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]
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 * plabel - gets process label.
43 #include <sys/tsol/label_macro.h>
45 #include <tsol/label.h>
50 #define INIT_ALLOC_LEN 1024
51 #define MAX_ALLOC_NUM 11
53 static int look(char *);
54 static int perr(char *);
55 static void usage(void);
57 static char procname
[64];
59 static unsigned int opt_flag
= 0;
60 static char *cmd
= NULL
;
63 main(int argc
, char **argv
)
68 (void) setlocale(LC_ALL
, "");
69 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
70 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
72 (void) textdomain(TEXT_DOMAIN
);
74 if ((cmd
= strrchr(argv
[0], '/')) == NULL
)
79 /* Error if labeling is not active. */
80 if (!is_system_labeled()) {
81 (void) fprintf(stderr
,
82 gettext("%s: Trusted Extensions must be enabled\n"), cmd
);
86 while ((opt
= getopt(argc
, argv
, "sS")) != EOF
) {
89 if (opt_flag
& (s_flag
| S_flag
)) {
97 if (opt_flag
& (s_flag
| S_flag
)) {
112 char pid
[11]; /* 32 bit pids go to 4294967295 plus a NUL */
114 (void) sprintf(pid
, "%d", (int)getpid());
131 psinfo_t info
; /* process information from /proc */
133 int wordlen
= DEF_NAMES
;
135 if (opt_flag
== S_flag
)
136 wordlen
= LONG_NAMES
;
137 else if (opt_flag
== s_flag
)
138 wordlen
= SHORT_NAMES
;
140 if (strchr(arg
, '/') != NULL
)
141 (void) strncpy(procname
, arg
, sizeof (procname
));
143 (void) strcpy(procname
, "/proc/");
144 (void) strncat(procname
, arg
,
145 sizeof (procname
) - strlen(procname
));
147 (void) strlcat(procname
, "/psinfo", sizeof (procname
)
151 * Open the process to be examined.
154 if ((fd
= open(procname
, O_RDONLY
)) < 0) {
156 * Make clean message for non-existent process.
158 if (errno
== ENOENT
) {
168 * Get the info structure for the process and close quickly.
170 if (read(fd
, &info
, sizeof (info
)) < 0) {
174 if (saverr
== EAGAIN
)
176 if (saverr
!= ENOENT
)
182 if (info
.pr_lwp
.pr_state
== 0) /* can't happen? */
185 if ((plabel
= getzonelabelbyid(info
.pr_zoneid
)) == NULL
) {
190 * The process label for global zone is admin_high
192 if (info
.pr_zoneid
== GLOBAL_ZONEID
) {
196 if (label_to_str(plabel
, &str
, M_LABEL
, wordlen
) != 0) {
200 (void) printf("%s\n", str
);
201 m_label_free(plabel
);
210 * This routine is called whenever there is a usage type of error has
211 * occured. For example, when a invalid option has has been specified.
218 (void) fprintf(stderr
, "Usage: \n");
219 (void) fprintf(stderr
,
220 gettext(" %s [pid ...] \n"), cmd
);
221 (void) fprintf(stderr
,
222 gettext(" %s -s [pid ...] \n"), cmd
);
223 (void) fprintf(stderr
,
224 gettext(" %s -S [pid ...] \n"), cmd
);
231 (void) fprintf(stderr
, "%s: ", procname
);