8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / zonename / zonename.c
blob2ab2f1f520e3ebf9f9bdc4d15f8d10ebde7cd95e
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <locale.h>
31 #include <libintl.h>
32 #include <zone.h>
33 #include <libzonecfg.h>
34 #include <dlfcn.h>
35 #include <sys/zone.h>
37 #if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
38 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
39 #endif
42 * -t prints "shared" vs. "exclusive"
44 int
45 main(int argc, char *argv[])
47 zoneid_t zoneid;
48 char zonename[ZONENAME_MAX];
49 FILE *fp;
50 int arg;
51 boolean_t stacktype = B_FALSE;
53 (void) setlocale(LC_ALL, "");
54 (void) textdomain(TEXT_DOMAIN);
56 opterr = 0;
57 while ((arg = getopt(argc, argv, "t")) != EOF) {
58 switch (arg) {
59 case 't':
60 stacktype = B_TRUE;
61 break;
65 zoneid = getzoneid();
67 if (stacktype) {
68 ushort_t flags;
70 if (zone_getattr(zoneid, ZONE_ATTR_FLAGS, &flags,
71 sizeof (flags)) < 0) {
72 perror("could not determine zone IP type");
73 exit(1);
75 if (flags & ZF_NET_EXCL)
76 (void) puts("exclusive");
77 else
78 (void) puts("shared");
79 return (0);
82 if (getzonenamebyid(zoneid, zonename, sizeof (zonename)) < 0) {
83 (void) fputs(gettext("could not determine zone name\n"),
84 stderr);
85 return (1);
89 * The use of dlopen here is a bit ugly, but it allows zonename to
90 * function properly before /usr is mounted. On such a system, scratch
91 * zones don't exist, so no translation is necessary.
93 if (dlopen("libzonecfg.so.1", RTLD_NOW | RTLD_GLOBAL) != NULL &&
94 zonecfg_is_scratch(zonename) &&
95 (fp = zonecfg_open_scratch("", B_FALSE)) != NULL) {
96 (void) zonecfg_reverse_scratch(fp, zonename, zonename,
97 sizeof (zonename), NULL, 0);
98 zonecfg_close_scratch(fp);
100 (void) puts(zonename);
101 return (0);