4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <sys/param.h>
27 #include <libintl.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <strings.h>
32 #include <syslog.h>
33 #include <unistd.h>
34 #include <errno.h>
35
36 #include "utils.h"
37
38 static char ERRNO_FMT[] = ": %s";
39
40 static char *pname = NULL;
41 static rcm_level_t message_priority = RCM_WARN;
42 static rcm_dst_t message_dst = RCD_STD;
43
239 hrt2ts(hrtime_t hrt, timestruc_t *tsp)
240 {
241 tsp->tv_sec = hrt / NANOSEC;
242 tsp->tv_nsec = hrt % NANOSEC;
243 }
244
245 int
246 xatoi(char *p)
247 {
248 int i;
249 char *q;
250
251 errno = 0;
252 i = (int)strtol(p, &q, 10);
253 if (errno != 0 || q == p || i < 0 || *q != '\0') {
254 warn(gettext("illegal argument -- %s\n"), p);
255 return (-1);
256 } else {
257 return (i);
258 }
259 }
260
261 /*
262 * get_running_zones() calls zone_list(2) to find out how many zones are
263 * running. It then calls zone_list(2) again to fetch the list of running
264 * zones (stored in *zents).
265 */
266 int
267 get_running_zones(uint_t *nzents, zone_entry_t **zents)
268 {
269 zoneid_t *zids;
270 uint_t nzents_saved;
271 int i;
272 zone_entry_t *zentp;
273 zone_state_t zstate;
274
275 *zents = NULL;
276 if (zone_list(NULL, nzents) != 0) {
277 warn(gettext("could not get zoneid list\n"));
278 return (E_ERROR);
279 }
280
281 again:
282 if (*nzents == 0)
283 return (E_SUCCESS);
284
285 if ((zids = (zoneid_t *)calloc(*nzents, sizeof (zoneid_t))) == NULL) {
286 warn(gettext("out of memory: zones will not be capped\n"));
287 return (E_ERROR);
288 }
289
290 nzents_saved = *nzents;
291
292 if (zone_list(zids, nzents) != 0) {
293 warn(gettext("could not get zone list\n"));
294 free(zids);
295 return (E_ERROR);
296 }
297 if (*nzents != nzents_saved) {
298 /* list changed, try again */
299 free(zids);
300 goto again;
301 }
302
303 *zents = calloc(*nzents, sizeof (zone_entry_t));
304 if (*zents == NULL) {
305 warn(gettext("out of memory: zones will not be capped\n"));
306 free(zids);
307 return (E_ERROR);
308 }
309
310 zentp = *zents;
311 for (i = 0; i < *nzents; i++) {
312 char name[ZONENAME_MAX];
313
314 if (getzonenamebyid(zids[i], name, sizeof (name)) < 0) {
315 warn(gettext("could not get name for "
316 "zoneid %d\n"), zids[i]);
317 continue;
318 }
319
320 (void) strlcpy(zentp->zname, name, sizeof (zentp->zname));
321 zentp->zid = zids[i];
322 if (zone_get_state(name, &zstate) != Z_OK ||
323 zstate != ZONE_STATE_RUNNING)
324 continue;
325
326
327 zentp++;
328 }
329 *nzents = zentp - *zents;
330
331 free(zids);
332 return (E_SUCCESS);
333 }
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2011, Joyent, Inc. All rights reserved.
25 */
26
27 #include <sys/param.h>
28 #include <libintl.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <strings.h>
33 #include <syslog.h>
34 #include <unistd.h>
35 #include <errno.h>
36
37 #include "utils.h"
38
39 static char ERRNO_FMT[] = ": %s";
40
41 static char *pname = NULL;
42 static rcm_level_t message_priority = RCM_WARN;
43 static rcm_dst_t message_dst = RCD_STD;
44
240 hrt2ts(hrtime_t hrt, timestruc_t *tsp)
241 {
242 tsp->tv_sec = hrt / NANOSEC;
243 tsp->tv_nsec = hrt % NANOSEC;
244 }
245
246 int
247 xatoi(char *p)
248 {
249 int i;
250 char *q;
251
252 errno = 0;
253 i = (int)strtol(p, &q, 10);
254 if (errno != 0 || q == p || i < 0 || *q != '\0') {
255 warn(gettext("illegal argument -- %s\n"), p);
256 return (-1);
257 } else {
258 return (i);
259 }
260 }
|