xref: /illumos-gate/usr/src/cmd/truss/procset.c (revision 2a8bcb4e)
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 #include <stdio.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <sys/wait.h>
36 #include <libproc.h>
37 #include "ramdata.h"
38 #include "proto.h"
39 
40 /*
41  * Function prototypes for static routines in this module.
42  */
43 const char *idop_enum(private_t *, idop_t);
44 
45 void
show_procset(private_t * pri,long offset)46 show_procset(private_t *pri, long offset)
47 {
48 	procset_t procset;
49 	procset_t *psp = &procset;
50 
51 	if (Pread(Proc, psp, sizeof (*psp), offset) == sizeof (*psp)) {
52 		(void) printf("%s\top=%s",
53 			pri->pname, idop_enum(pri, psp->p_op));
54 		(void) printf("  ltyp=%s lid=%ld",
55 			idtype_enum(pri, psp->p_lidtype), (long)psp->p_lid);
56 		(void) printf("  rtyp=%s rid=%ld\n",
57 			idtype_enum(pri, psp->p_ridtype), (long)psp->p_rid);
58 	}
59 }
60 
61 const char *
idop_enum(private_t * pri,idop_t arg)62 idop_enum(private_t *pri, idop_t arg)
63 {
64 	const char *str;
65 
66 	switch (arg) {
67 	case POP_DIFF:	str = "POP_DIFF";	break;
68 	case POP_AND:	str = "POP_AND";	break;
69 	case POP_OR:	str = "POP_OR";		break;
70 	case POP_XOR:	str = "POP_XOR";	break;
71 	default:
72 		(void) sprintf(pri->code_buf, "%d", arg);
73 		str = (const char *)pri->code_buf;
74 		break;
75 	}
76 
77 	return (str);
78 }
79 
80 const char *
idtype_enum(private_t * pri,long arg)81 idtype_enum(private_t *pri, long arg)
82 {
83 	const char *str;
84 
85 	switch (arg) {
86 	case P_PID:	str = "P_PID";		break;
87 	case P_PPID:	str = "P_PPID";		break;
88 	case P_PGID:	str = "P_PGID";		break;
89 	case P_SID:	str = "P_SID";		break;
90 	case P_CID:	str = "P_CID";		break;
91 	case P_UID:	str = "P_UID";		break;
92 	case P_GID:	str = "P_GID";		break;
93 	case P_ALL:	str = "P_ALL";		break;
94 	case P_LWPID:	str = "P_LWPID";	break;
95 	case P_TASKID:	str = "P_TASKID";	break;
96 	case P_PROJID:	str = "P_PROJID";	break;
97 	case P_ZONEID:	str = "P_ZONEID";	break;
98 	case P_CTID:	str = "P_CTID";		break;
99 	default:
100 		(void) sprintf(pri->code_buf, "%ld", arg);
101 		str = (const char *)pri->code_buf;
102 		break;
103 	}
104 
105 	return (str);
106 }
107 
108 const char *
woptions(private_t * pri,int arg)109 woptions(private_t *pri, int arg)
110 {
111 	char *str = pri->code_buf;
112 
113 	if (arg == 0)
114 		return ("0");
115 	if (arg &
116 	    ~(WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|WNOHANG|WNOWAIT))
117 		return (NULL);
118 
119 	*str = '\0';
120 	if (arg & WEXITED)
121 		(void) strcat(str, "|WEXITED");
122 	if (arg & WTRAPPED)
123 		(void) strcat(str, "|WTRAPPED");
124 	if (arg & WSTOPPED)
125 		(void) strcat(str, "|WSTOPPED");
126 	if (arg & WCONTINUED)
127 		(void) strcat(str, "|WCONTINUED");
128 	if (arg & WNOHANG)
129 		(void) strcat(str, "|WNOHANG");
130 	if (arg & WNOWAIT)
131 		(void) strcat(str, "|WNOWAIT");
132 
133 	return ((const char *)(str+1));
134 }
135