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