xref: /titanic_44/usr/src/cmd/truss/procset.c (revision 0dc2366f7b9f9f36e10909b1e95edbf2a261c2ac)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <string.h>
37 #include <sys/types.h>
38 #include <sys/wait.h>
39 #include <libproc.h>
40 #include "ramdata.h"
41 #include "proto.h"
42 
43 /*
44  * Function prototypes for static routines in this module.
45  */
46 const char *idop_enum(private_t *, idop_t);
47 
48 void
49 show_procset(private_t *pri, long offset)
50 {
51 	procset_t procset;
52 	procset_t *psp = &procset;
53 
54 	if (Pread(Proc, psp, sizeof (*psp), offset) == sizeof (*psp)) {
55 		(void) printf("%s\top=%s",
56 			pri->pname, idop_enum(pri, psp->p_op));
57 		(void) printf("  ltyp=%s lid=%ld",
58 			idtype_enum(pri, psp->p_lidtype), (long)psp->p_lid);
59 		(void) printf("  rtyp=%s rid=%ld\n",
60 			idtype_enum(pri, psp->p_ridtype), (long)psp->p_rid);
61 	}
62 }
63 
64 const char *
65 idop_enum(private_t *pri, idop_t arg)
66 {
67 	const char *str;
68 
69 	switch (arg) {
70 	case POP_DIFF:	str = "POP_DIFF";	break;
71 	case POP_AND:	str = "POP_AND";	break;
72 	case POP_OR:	str = "POP_OR";		break;
73 	case POP_XOR:	str = "POP_XOR";	break;
74 	default:
75 		(void) sprintf(pri->code_buf, "%d", arg);
76 		str = (const char *)pri->code_buf;
77 		break;
78 	}
79 
80 	return (str);
81 }
82 
83 const char *
84 idtype_enum(private_t *pri, long arg)
85 {
86 	const char *str;
87 
88 	switch (arg) {
89 	case P_PID:	str = "P_PID";		break;
90 	case P_PPID:	str = "P_PPID";		break;
91 	case P_PGID:	str = "P_PGID";		break;
92 	case P_SID:	str = "P_SID";		break;
93 	case P_CID:	str = "P_CID";		break;
94 	case P_UID:	str = "P_UID";		break;
95 	case P_GID:	str = "P_GID";		break;
96 	case P_ALL:	str = "P_ALL";		break;
97 	case P_LWPID:	str = "P_LWPID";	break;
98 	case P_TASKID:	str = "P_TASKID";	break;
99 	case P_PROJID:	str = "P_PROJID";	break;
100 	case P_ZONEID:	str = "P_ZONEID";	break;
101 	case P_CTID:	str = "P_CTID";		break;
102 	default:
103 		(void) sprintf(pri->code_buf, "%ld", arg);
104 		str = (const char *)pri->code_buf;
105 		break;
106 	}
107 
108 	return (str);
109 }
110 
111 const char *
112 woptions(private_t *pri, int arg)
113 {
114 	char *str = pri->code_buf;
115 
116 	if (arg == 0)
117 		return ("0");
118 	if (arg &
119 	    ~(WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|WNOHANG|WNOWAIT))
120 		return (NULL);
121 
122 	*str = '\0';
123 	if (arg & WEXITED)
124 		(void) strcat(str, "|WEXITED");
125 	if (arg & WTRAPPED)
126 		(void) strcat(str, "|WTRAPPED");
127 	if (arg & WSTOPPED)
128 		(void) strcat(str, "|WSTOPPED");
129 	if (arg & WCONTINUED)
130 		(void) strcat(str, "|WCONTINUED");
131 	if (arg & WNOHANG)
132 		(void) strcat(str, "|WNOHANG");
133 	if (arg & WNOWAIT)
134 		(void) strcat(str, "|WNOWAIT");
135 
136 	return ((const char *)(str+1));
137 }
138