8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / tsol / getzonepath / getzonepath.c
blobf8e05df4819607296c11e99e05c77abbc7d30674
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
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Name: getzonepath.c
32 * Description: Get the zone pathname associated with a label.
34 * Usage: getzonepath sensitivity_label
37 #include <errno.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
43 #include <tsol/label.h>
45 static char *prog;
47 static void
48 label_error(const char *label, const int err)
50 if (errno == EINVAL) {
51 switch (err) {
52 case M_BAD_STRING:
53 (void) fprintf(stderr,
54 gettext("%s: bad string %s\n"), prog, label);
55 break;
56 case M_BAD_LABEL:
57 (void) fprintf(stderr,
58 gettext("%s: bad previous label\n"), prog);
59 break;
60 default:
61 (void) fprintf(stderr,
62 gettext("%s: parsing error found in "
63 "\"%s\" at position %d\n"), prog, label, err);
64 break;
66 } else {
67 perror(prog);
69 exit(1);
72 int
73 main(int argc, char **argv)
75 int err = 0;
76 m_label_t *label = NULL;
77 char *zone_root;
79 (void) setlocale(LC_ALL, "");
80 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
81 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it were'nt */
82 #endif
83 (void) textdomain(TEXT_DOMAIN);
85 if ((prog = strrchr(argv[0], '/')) == NULL)
86 prog = argv[0];
87 else
88 prog++;
90 if (argc != 2) {
91 (void) fprintf(stderr, gettext(
92 "Usage: %s label\n"), prog);
93 return (1);
96 if (str_to_label(argv[1], &label, MAC_LABEL, L_NO_CORRECTION,
97 &err) == -1) {
98 label_error(argv[1], err);
101 if ((zone_root = getzonerootbylabel(label)) == NULL) {
102 (void) fprintf(stderr,
103 gettext("%s: cannot get path for label: %s.\n"), prog,
104 strerror(errno));
105 return (3);
108 (void) printf("%s\n", zone_root);
110 return (0);
111 } /* end main() */