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 2005 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #define	__EXTENSIONS__
31*7c478bd9Sstevel@tonic-gate #include <string.h>
32*7c478bd9Sstevel@tonic-gate #undef  __EXTENSIONS__
33*7c478bd9Sstevel@tonic-gate #include <signal.h>
34*7c478bd9Sstevel@tonic-gate #include <alloca.h>
35*7c478bd9Sstevel@tonic-gate #include <errno.h>
36*7c478bd9Sstevel@tonic-gate #include "libproc.h"
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate static const char *
39*7c478bd9Sstevel@tonic-gate rawfltname(int flt)
40*7c478bd9Sstevel@tonic-gate {
41*7c478bd9Sstevel@tonic-gate 	const char *name;
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate 	switch (flt) {
44*7c478bd9Sstevel@tonic-gate 	case FLTILL:	name = "FLTILL";	break;
45*7c478bd9Sstevel@tonic-gate 	case FLTPRIV:	name = "FLTPRIV";	break;
46*7c478bd9Sstevel@tonic-gate 	case FLTBPT:	name = "FLTBPT";	break;
47*7c478bd9Sstevel@tonic-gate 	case FLTTRACE:	name = "FLTTRACE";	break;
48*7c478bd9Sstevel@tonic-gate 	case FLTACCESS:	name = "FLTACCESS";	break;
49*7c478bd9Sstevel@tonic-gate 	case FLTBOUNDS:	name = "FLTBOUNDS";	break;
50*7c478bd9Sstevel@tonic-gate 	case FLTIOVF:	name = "FLTIOVF";	break;
51*7c478bd9Sstevel@tonic-gate 	case FLTIZDIV:	name = "FLTIZDIV";	break;
52*7c478bd9Sstevel@tonic-gate 	case FLTFPE:	name = "FLTFPE";	break;
53*7c478bd9Sstevel@tonic-gate 	case FLTSTACK:	name = "FLTSTACK";	break;
54*7c478bd9Sstevel@tonic-gate 	case FLTPAGE:	name = "FLTPAGE";	break;
55*7c478bd9Sstevel@tonic-gate 	case FLTWATCH:	name = "FLTWATCH";	break;
56*7c478bd9Sstevel@tonic-gate 	case FLTCPCOVF:	name = "FLTCPCOVF";	break;
57*7c478bd9Sstevel@tonic-gate 	default:	name = NULL;		break;
58*7c478bd9Sstevel@tonic-gate 	}
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	return (name);
61*7c478bd9Sstevel@tonic-gate }
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate /*
64*7c478bd9Sstevel@tonic-gate  * Return the name of a fault.
65*7c478bd9Sstevel@tonic-gate  * Manufacture a name for unknown fault.
66*7c478bd9Sstevel@tonic-gate  */
67*7c478bd9Sstevel@tonic-gate char *
68*7c478bd9Sstevel@tonic-gate proc_fltname(int flt, char *buf, size_t bufsz)
69*7c478bd9Sstevel@tonic-gate {
70*7c478bd9Sstevel@tonic-gate 	const char *name = rawfltname(flt);
71*7c478bd9Sstevel@tonic-gate 	size_t len;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
74*7c478bd9Sstevel@tonic-gate 		return (NULL);
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	if (name != NULL) {
77*7c478bd9Sstevel@tonic-gate 		len = strlen(name);
78*7c478bd9Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
79*7c478bd9Sstevel@tonic-gate 	} else {
80*7c478bd9Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "FLT#%d", flt);
81*7c478bd9Sstevel@tonic-gate 	}
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
84*7c478bd9Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 	return (buf);
87*7c478bd9Sstevel@tonic-gate }
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /*
90*7c478bd9Sstevel@tonic-gate  * Return the name of a signal.
91*7c478bd9Sstevel@tonic-gate  * Manufacture a name for unknown signal.
92*7c478bd9Sstevel@tonic-gate  */
93*7c478bd9Sstevel@tonic-gate char *
94*7c478bd9Sstevel@tonic-gate proc_signame(int sig, char *buf, size_t bufsz)
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate 	char name[SIG2STR_MAX+4];
97*7c478bd9Sstevel@tonic-gate 	size_t len;
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
100*7c478bd9Sstevel@tonic-gate 		return (NULL);
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	/* sig2str() omits the leading "SIG" */
103*7c478bd9Sstevel@tonic-gate 	(void) strcpy(name, "SIG");
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	if (sig2str(sig, name+3) == 0) {
106*7c478bd9Sstevel@tonic-gate 		len = strlen(name);
107*7c478bd9Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
108*7c478bd9Sstevel@tonic-gate 	} else {
109*7c478bd9Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "SIG#%d", sig);
110*7c478bd9Sstevel@tonic-gate 	}
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
113*7c478bd9Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate 	return (buf);
116*7c478bd9Sstevel@tonic-gate }
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate static const char *const systable[] = {
119*7c478bd9Sstevel@tonic-gate 	NULL,			/*  0 */
120*7c478bd9Sstevel@tonic-gate 	"_exit",		/*  1 */
121*7c478bd9Sstevel@tonic-gate 	"forkall",		/*  2 */
122*7c478bd9Sstevel@tonic-gate 	"read",			/*  3 */
123*7c478bd9Sstevel@tonic-gate 	"write",		/*  4 */
124*7c478bd9Sstevel@tonic-gate 	"open",			/*  5 */
125*7c478bd9Sstevel@tonic-gate 	"close",		/*  6 */
126*7c478bd9Sstevel@tonic-gate 	"wait",			/*  7 */
127*7c478bd9Sstevel@tonic-gate 	"creat",		/*  8 */
128*7c478bd9Sstevel@tonic-gate 	"link",			/*  9 */
129*7c478bd9Sstevel@tonic-gate 	"unlink",		/* 10 */
130*7c478bd9Sstevel@tonic-gate 	"exec",			/* 11 */
131*7c478bd9Sstevel@tonic-gate 	"chdir",		/* 12 */
132*7c478bd9Sstevel@tonic-gate 	"time",			/* 13 */
133*7c478bd9Sstevel@tonic-gate 	"mknod",		/* 14 */
134*7c478bd9Sstevel@tonic-gate 	"chmod",		/* 15 */
135*7c478bd9Sstevel@tonic-gate 	"chown",		/* 16 */
136*7c478bd9Sstevel@tonic-gate 	"brk",			/* 17 */
137*7c478bd9Sstevel@tonic-gate 	"stat",			/* 18 */
138*7c478bd9Sstevel@tonic-gate 	"lseek",		/* 19 */
139*7c478bd9Sstevel@tonic-gate 	"getpid",		/* 20 */
140*7c478bd9Sstevel@tonic-gate 	"mount",		/* 21 */
141*7c478bd9Sstevel@tonic-gate 	"umount",		/* 22 */
142*7c478bd9Sstevel@tonic-gate 	"setuid",		/* 23 */
143*7c478bd9Sstevel@tonic-gate 	"getuid",		/* 24 */
144*7c478bd9Sstevel@tonic-gate 	"stime",		/* 25 */
145*7c478bd9Sstevel@tonic-gate 	"ptrace",		/* 26 */
146*7c478bd9Sstevel@tonic-gate 	"alarm",		/* 27 */
147*7c478bd9Sstevel@tonic-gate 	"fstat",		/* 28 */
148*7c478bd9Sstevel@tonic-gate 	"pause",		/* 29 */
149*7c478bd9Sstevel@tonic-gate 	"utime",		/* 30 */
150*7c478bd9Sstevel@tonic-gate 	"stty",			/* 31 */
151*7c478bd9Sstevel@tonic-gate 	"gtty",			/* 32 */
152*7c478bd9Sstevel@tonic-gate 	"access",		/* 33 */
153*7c478bd9Sstevel@tonic-gate 	"nice",			/* 34 */
154*7c478bd9Sstevel@tonic-gate 	"statfs",		/* 35 */
155*7c478bd9Sstevel@tonic-gate 	"sync",			/* 36 */
156*7c478bd9Sstevel@tonic-gate 	"kill",			/* 37 */
157*7c478bd9Sstevel@tonic-gate 	"fstatfs",		/* 38 */
158*7c478bd9Sstevel@tonic-gate 	"pgrpsys",		/* 39 */
159*7c478bd9Sstevel@tonic-gate 	NULL,			/* 40 was xenix */
160*7c478bd9Sstevel@tonic-gate 	"dup",			/* 41 */
161*7c478bd9Sstevel@tonic-gate 	"pipe",			/* 42 */
162*7c478bd9Sstevel@tonic-gate 	"times",		/* 43 */
163*7c478bd9Sstevel@tonic-gate 	"profil",		/* 44 */
164*7c478bd9Sstevel@tonic-gate 	"plock",		/* 45 */
165*7c478bd9Sstevel@tonic-gate 	"setgid",		/* 46 */
166*7c478bd9Sstevel@tonic-gate 	"getgid",		/* 47 */
167*7c478bd9Sstevel@tonic-gate 	"signal",		/* 48 */
168*7c478bd9Sstevel@tonic-gate 	"msgsys",		/* 49 */
169*7c478bd9Sstevel@tonic-gate 	"sysi86",		/* 50 */
170*7c478bd9Sstevel@tonic-gate 	"acct",			/* 51 */
171*7c478bd9Sstevel@tonic-gate 	"shmsys",		/* 52 */
172*7c478bd9Sstevel@tonic-gate 	"semsys",		/* 53 */
173*7c478bd9Sstevel@tonic-gate 	"ioctl",		/* 54 */
174*7c478bd9Sstevel@tonic-gate 	"uadmin",		/* 55 */
175*7c478bd9Sstevel@tonic-gate 	NULL,			/* 56 */
176*7c478bd9Sstevel@tonic-gate 	"utssys",		/* 57 */
177*7c478bd9Sstevel@tonic-gate 	"fdsync",		/* 58 */
178*7c478bd9Sstevel@tonic-gate 	"execve",		/* 59 */
179*7c478bd9Sstevel@tonic-gate 	"umask",		/* 60 */
180*7c478bd9Sstevel@tonic-gate 	"chroot",		/* 61 */
181*7c478bd9Sstevel@tonic-gate 	"fcntl",		/* 62 */
182*7c478bd9Sstevel@tonic-gate 	"ulimit",		/* 63 */
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate 	/* The following 6 entries were reserved for the UNIX PC */
185*7c478bd9Sstevel@tonic-gate 	NULL,			/* 64 */
186*7c478bd9Sstevel@tonic-gate 	NULL,			/* 65 */
187*7c478bd9Sstevel@tonic-gate 	NULL,			/* 66 */
188*7c478bd9Sstevel@tonic-gate 	NULL,			/* 67 */
189*7c478bd9Sstevel@tonic-gate 	NULL,			/* 68 */
190*7c478bd9Sstevel@tonic-gate 	NULL,			/* 69 */
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate 	"tasksys",		/* 70 */
193*7c478bd9Sstevel@tonic-gate 	"acctctl",		/* 71 */
194*7c478bd9Sstevel@tonic-gate 	"exacctsys",		/* 72 */
195*7c478bd9Sstevel@tonic-gate 	"getpagesizes",		/* 73 */
196*7c478bd9Sstevel@tonic-gate 	"rctlsys",		/* 74 */
197*7c478bd9Sstevel@tonic-gate 	"issetugid",		/* 75 */
198*7c478bd9Sstevel@tonic-gate 	"fsat",			/* 76 */
199*7c478bd9Sstevel@tonic-gate 	"lwp_park",		/* 77 */
200*7c478bd9Sstevel@tonic-gate 	"sendfilev",		/* 78 */
201*7c478bd9Sstevel@tonic-gate 	"rmdir",		/* 79 */
202*7c478bd9Sstevel@tonic-gate 	"mkdir",		/* 80 */
203*7c478bd9Sstevel@tonic-gate 	"getdents",		/* 81 */
204*7c478bd9Sstevel@tonic-gate 	"privsys",		/* 82 */
205*7c478bd9Sstevel@tonic-gate 	"ucredsys",		/* 83 */
206*7c478bd9Sstevel@tonic-gate 	"sysfs",		/* 84 */
207*7c478bd9Sstevel@tonic-gate 	"getmsg",		/* 85 */
208*7c478bd9Sstevel@tonic-gate 	"putmsg",		/* 86 */
209*7c478bd9Sstevel@tonic-gate 	"poll",			/* 87 */
210*7c478bd9Sstevel@tonic-gate 	"lstat",		/* 88 */
211*7c478bd9Sstevel@tonic-gate 	"symlink",		/* 89 */
212*7c478bd9Sstevel@tonic-gate 	"readlink",		/* 90 */
213*7c478bd9Sstevel@tonic-gate 	"setgroups",		/* 91 */
214*7c478bd9Sstevel@tonic-gate 	"getgroups",		/* 92 */
215*7c478bd9Sstevel@tonic-gate 	"fchmod",		/* 93 */
216*7c478bd9Sstevel@tonic-gate 	"fchown",		/* 94 */
217*7c478bd9Sstevel@tonic-gate 	"sigprocmask",		/* 95 */
218*7c478bd9Sstevel@tonic-gate 	"sigsuspend",		/* 96 */
219*7c478bd9Sstevel@tonic-gate 	"sigaltstack",		/* 97 */
220*7c478bd9Sstevel@tonic-gate 	"sigaction",		/* 98 */
221*7c478bd9Sstevel@tonic-gate 	"sigpending",		/* 99 */
222*7c478bd9Sstevel@tonic-gate 	"context",		/* 100 */
223*7c478bd9Sstevel@tonic-gate 	"evsys",		/* 101 */
224*7c478bd9Sstevel@tonic-gate 	"evtrapret",		/* 102 */
225*7c478bd9Sstevel@tonic-gate 	"statvfs",		/* 103 */
226*7c478bd9Sstevel@tonic-gate 	"fstatvfs",		/* 104 */
227*7c478bd9Sstevel@tonic-gate 	"getloadavg",		/* 105 */
228*7c478bd9Sstevel@tonic-gate 	"nfssys",		/* 106 */
229*7c478bd9Sstevel@tonic-gate 	"waitid",		/* 107 */
230*7c478bd9Sstevel@tonic-gate 	"sigsendsys",		/* 108 */
231*7c478bd9Sstevel@tonic-gate 	"hrtsys",		/* 109 */
232*7c478bd9Sstevel@tonic-gate 	"acancel",		/* 110 */
233*7c478bd9Sstevel@tonic-gate 	"async",		/* 111 */
234*7c478bd9Sstevel@tonic-gate 	"priocntlsys",		/* 112 */
235*7c478bd9Sstevel@tonic-gate 	"pathconf",		/* 113 */
236*7c478bd9Sstevel@tonic-gate 	"mincore",		/* 114 */
237*7c478bd9Sstevel@tonic-gate 	"mmap",			/* 115 */
238*7c478bd9Sstevel@tonic-gate 	"mprotect",		/* 116 */
239*7c478bd9Sstevel@tonic-gate 	"munmap",		/* 117 */
240*7c478bd9Sstevel@tonic-gate 	"fpathconf",		/* 118 */
241*7c478bd9Sstevel@tonic-gate 	"vfork",		/* 119 */
242*7c478bd9Sstevel@tonic-gate 	"fchdir",		/* 120 */
243*7c478bd9Sstevel@tonic-gate 	"readv",		/* 121 */
244*7c478bd9Sstevel@tonic-gate 	"writev",		/* 122 */
245*7c478bd9Sstevel@tonic-gate 	"xstat",		/* 123 */
246*7c478bd9Sstevel@tonic-gate 	"lxstat",		/* 124 */
247*7c478bd9Sstevel@tonic-gate 	"fxstat",		/* 125 */
248*7c478bd9Sstevel@tonic-gate 	"xmknod",		/* 126 */
249*7c478bd9Sstevel@tonic-gate 	"NULL",			/* 127 */
250*7c478bd9Sstevel@tonic-gate 	"setrlimit",		/* 128 */
251*7c478bd9Sstevel@tonic-gate 	"getrlimit",		/* 129 */
252*7c478bd9Sstevel@tonic-gate 	"lchown",		/* 130 */
253*7c478bd9Sstevel@tonic-gate 	"memcntl",		/* 131 */
254*7c478bd9Sstevel@tonic-gate 	"getpmsg",		/* 132 */
255*7c478bd9Sstevel@tonic-gate 	"putpmsg",		/* 133 */
256*7c478bd9Sstevel@tonic-gate 	"rename",		/* 134 */
257*7c478bd9Sstevel@tonic-gate 	"uname",		/* 135 */
258*7c478bd9Sstevel@tonic-gate 	"setegid",		/* 136 */
259*7c478bd9Sstevel@tonic-gate 	"sysconfig",		/* 137 */
260*7c478bd9Sstevel@tonic-gate 	"adjtime",		/* 138 */
261*7c478bd9Sstevel@tonic-gate 	"systeminfo",		/* 139 */
262*7c478bd9Sstevel@tonic-gate 	NULL,			/* 140 */
263*7c478bd9Sstevel@tonic-gate 	"seteuid",		/* 141 */
264*7c478bd9Sstevel@tonic-gate 	NULL,			/* 142 */
265*7c478bd9Sstevel@tonic-gate 	"fork1",		/* 143 */
266*7c478bd9Sstevel@tonic-gate 	"sigtimedwait",		/* 144 */
267*7c478bd9Sstevel@tonic-gate 	"lwp_info",		/* 145 */
268*7c478bd9Sstevel@tonic-gate 	"yield",		/* 146 */
269*7c478bd9Sstevel@tonic-gate 	"lwp_sema_wait",	/* 147 */
270*7c478bd9Sstevel@tonic-gate 	"lwp_sema_post",	/* 148 */
271*7c478bd9Sstevel@tonic-gate 	"lwp_sema_trywait",	/* 149 */
272*7c478bd9Sstevel@tonic-gate 	"lwp_detatch",		/* 150 */
273*7c478bd9Sstevel@tonic-gate 	"corectl",		/* 151 */
274*7c478bd9Sstevel@tonic-gate 	"modctl",		/* 152 */
275*7c478bd9Sstevel@tonic-gate 	"fchroot",		/* 153 */
276*7c478bd9Sstevel@tonic-gate 	"utimes",		/* 154 */
277*7c478bd9Sstevel@tonic-gate 	"vhangup",		/* 155 */
278*7c478bd9Sstevel@tonic-gate 	"gettimeofday",		/* 156 */
279*7c478bd9Sstevel@tonic-gate 	"getitimer",		/* 157 */
280*7c478bd9Sstevel@tonic-gate 	"setitimer",		/* 158 */
281*7c478bd9Sstevel@tonic-gate 	"lwp_create",		/* 159 */
282*7c478bd9Sstevel@tonic-gate 	"lwp_exit",		/* 160 */
283*7c478bd9Sstevel@tonic-gate 	"lwp_suspend",		/* 161 */
284*7c478bd9Sstevel@tonic-gate 	"lwp_continue",		/* 162 */
285*7c478bd9Sstevel@tonic-gate 	"lwp_kill",		/* 163 */
286*7c478bd9Sstevel@tonic-gate 	"lwp_self",		/* 164 */
287*7c478bd9Sstevel@tonic-gate 	"lwp_sigmask",		/* 165 */
288*7c478bd9Sstevel@tonic-gate 	"lwp_private",		/* 166 */
289*7c478bd9Sstevel@tonic-gate 	"lwp_wait",		/* 167 */
290*7c478bd9Sstevel@tonic-gate 	"lwp_mutex_unlock",	/* 168 */
291*7c478bd9Sstevel@tonic-gate 	"lwp_mutex_lock",	/* 169 */
292*7c478bd9Sstevel@tonic-gate 	"lwp_cond_wait",	/* 170 */
293*7c478bd9Sstevel@tonic-gate 	"lwp_cond_signal",	/* 171 */
294*7c478bd9Sstevel@tonic-gate 	"lwp_cond_broadcast",	/* 172 */
295*7c478bd9Sstevel@tonic-gate 	"pread",		/* 173 */
296*7c478bd9Sstevel@tonic-gate 	"pwrite",		/* 174 */
297*7c478bd9Sstevel@tonic-gate 	"llseek",		/* 175 */
298*7c478bd9Sstevel@tonic-gate 	"inst_sync",		/* 176 */
299*7c478bd9Sstevel@tonic-gate 	NULL,			/* 177 */
300*7c478bd9Sstevel@tonic-gate 	"kaio",			/* 178 */
301*7c478bd9Sstevel@tonic-gate 	"cpc",			/* 179 */
302*7c478bd9Sstevel@tonic-gate 	"lgrpsys",		/* 180 */
303*7c478bd9Sstevel@tonic-gate 	"rusagesys",		/* 181 */
304*7c478bd9Sstevel@tonic-gate 	"portfs",		/* 182 */
305*7c478bd9Sstevel@tonic-gate 	"pollsys",		/* 183 */
306*7c478bd9Sstevel@tonic-gate 	NULL,			/* 184 */
307*7c478bd9Sstevel@tonic-gate 	"acl",			/* 185 */
308*7c478bd9Sstevel@tonic-gate 	"auditsys",		/* 186 */
309*7c478bd9Sstevel@tonic-gate 	"processor_bind",	/* 187 */
310*7c478bd9Sstevel@tonic-gate 	"processor_info",	/* 188 */
311*7c478bd9Sstevel@tonic-gate 	"p_online",		/* 189 */
312*7c478bd9Sstevel@tonic-gate 	"sigqueue",		/* 190 */
313*7c478bd9Sstevel@tonic-gate 	"clock_gettime",	/* 191 */
314*7c478bd9Sstevel@tonic-gate 	"clock_settime",	/* 192 */
315*7c478bd9Sstevel@tonic-gate 	"clock_getres",		/* 193 */
316*7c478bd9Sstevel@tonic-gate 	"timer_create",		/* 194 */
317*7c478bd9Sstevel@tonic-gate 	"timer_delete",		/* 195 */
318*7c478bd9Sstevel@tonic-gate 	"timer_settime",	/* 196 */
319*7c478bd9Sstevel@tonic-gate 	"timer_gettime",	/* 197 */
320*7c478bd9Sstevel@tonic-gate 	"timer_getoverrun",	/* 198 */
321*7c478bd9Sstevel@tonic-gate 	"nanosleep",		/* 199 */
322*7c478bd9Sstevel@tonic-gate 	"facl",			/* 200 */
323*7c478bd9Sstevel@tonic-gate 	"door",			/* 201 */
324*7c478bd9Sstevel@tonic-gate 	"setreuid",		/* 202 */
325*7c478bd9Sstevel@tonic-gate 	"setregid",		/* 203 */
326*7c478bd9Sstevel@tonic-gate 	"install_utrap",	/* 204 */
327*7c478bd9Sstevel@tonic-gate 	"signotify",		/* 205 */
328*7c478bd9Sstevel@tonic-gate 	"schedctl",		/* 206 */
329*7c478bd9Sstevel@tonic-gate 	"pset",			/* 207 */
330*7c478bd9Sstevel@tonic-gate 	"sparc_utrap_install",	/* 208 */
331*7c478bd9Sstevel@tonic-gate 	"resolvepath",		/* 209 */
332*7c478bd9Sstevel@tonic-gate 	"lwp_mutex_timedlock",	/* 210 */
333*7c478bd9Sstevel@tonic-gate 	"lwp_sema_timedwait",	/* 211 */
334*7c478bd9Sstevel@tonic-gate 	"lwp_rwlock_sys",	/* 212 */
335*7c478bd9Sstevel@tonic-gate 	"getdents64",		/* 213 */
336*7c478bd9Sstevel@tonic-gate 	"mmap64",		/* 214 */
337*7c478bd9Sstevel@tonic-gate 	"stat64",		/* 215 */
338*7c478bd9Sstevel@tonic-gate 	"lstat64",		/* 216 */
339*7c478bd9Sstevel@tonic-gate 	"fstat64",		/* 217 */
340*7c478bd9Sstevel@tonic-gate 	"statvfs64",		/* 218 */
341*7c478bd9Sstevel@tonic-gate 	"fstatvfs64",		/* 219 */
342*7c478bd9Sstevel@tonic-gate 	"setrlimit64",		/* 220 */
343*7c478bd9Sstevel@tonic-gate 	"getrlimit64",		/* 221 */
344*7c478bd9Sstevel@tonic-gate 	"pread64",		/* 222 */
345*7c478bd9Sstevel@tonic-gate 	"pwrite64",		/* 223 */
346*7c478bd9Sstevel@tonic-gate 	"creat64",		/* 224 */
347*7c478bd9Sstevel@tonic-gate 	"open64",		/* 225 */
348*7c478bd9Sstevel@tonic-gate 	"rpcmod",		/* 226 */
349*7c478bd9Sstevel@tonic-gate 	"zone",			/* 227 */
350*7c478bd9Sstevel@tonic-gate 	"autofssys",		/* 228 */
351*7c478bd9Sstevel@tonic-gate 	"getcwd",		/* 229 */
352*7c478bd9Sstevel@tonic-gate 	"so_socket",		/* 230 */
353*7c478bd9Sstevel@tonic-gate 	"so_socketpair",	/* 231 */
354*7c478bd9Sstevel@tonic-gate 	"bind",			/* 232 */
355*7c478bd9Sstevel@tonic-gate 	"listen",		/* 233 */
356*7c478bd9Sstevel@tonic-gate 	"accept",		/* 234 */
357*7c478bd9Sstevel@tonic-gate 	"connect",		/* 235 */
358*7c478bd9Sstevel@tonic-gate 	"shutdown",		/* 236 */
359*7c478bd9Sstevel@tonic-gate 	"recv",			/* 237 */
360*7c478bd9Sstevel@tonic-gate 	"recvfrom",		/* 238 */
361*7c478bd9Sstevel@tonic-gate 	"recvmsg",		/* 239 */
362*7c478bd9Sstevel@tonic-gate 	"send",			/* 240 */
363*7c478bd9Sstevel@tonic-gate 	"sendmsg",		/* 241 */
364*7c478bd9Sstevel@tonic-gate 	"sendto",		/* 242 */
365*7c478bd9Sstevel@tonic-gate 	"getpeername",		/* 243 */
366*7c478bd9Sstevel@tonic-gate 	"getsockname",		/* 244 */
367*7c478bd9Sstevel@tonic-gate 	"getsockopt",		/* 245 */
368*7c478bd9Sstevel@tonic-gate 	"setsockopt",		/* 246 */
369*7c478bd9Sstevel@tonic-gate 	"sockconfig",		/* 247 */
370*7c478bd9Sstevel@tonic-gate 	"ntp_gettime",		/* 248 */
371*7c478bd9Sstevel@tonic-gate 	"ntp_adjtime",		/* 249 */
372*7c478bd9Sstevel@tonic-gate 	"lwp_mutex_unlock",	/* 250 */
373*7c478bd9Sstevel@tonic-gate 	"lwp_mutex_trylock",	/* 251 */
374*7c478bd9Sstevel@tonic-gate 	"lwp_mutex_init",	/* 252 */
375*7c478bd9Sstevel@tonic-gate 	"cladm",		/* 253 */
376*7c478bd9Sstevel@tonic-gate 	NULL,			/* 254 */
377*7c478bd9Sstevel@tonic-gate 	"umount2"		/* 255 */
378*7c478bd9Sstevel@tonic-gate };
379*7c478bd9Sstevel@tonic-gate 
380*7c478bd9Sstevel@tonic-gate /* SYSEND == max syscall number + 1 */
381*7c478bd9Sstevel@tonic-gate #define	SYSEND	(sizeof (systable) / sizeof (systable[0]))
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate /*
384*7c478bd9Sstevel@tonic-gate  * Return the name of a system call.
385*7c478bd9Sstevel@tonic-gate  * Manufacture a name for unknown system call.
386*7c478bd9Sstevel@tonic-gate  */
387*7c478bd9Sstevel@tonic-gate char *
388*7c478bd9Sstevel@tonic-gate proc_sysname(int sys, char *buf, size_t bufsz)
389*7c478bd9Sstevel@tonic-gate {
390*7c478bd9Sstevel@tonic-gate 	const char *name;
391*7c478bd9Sstevel@tonic-gate 	size_t len;
392*7c478bd9Sstevel@tonic-gate 
393*7c478bd9Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
394*7c478bd9Sstevel@tonic-gate 		return (NULL);
395*7c478bd9Sstevel@tonic-gate 
396*7c478bd9Sstevel@tonic-gate 	if (sys >= 0 && sys < SYSEND)
397*7c478bd9Sstevel@tonic-gate 		name = systable[sys];
398*7c478bd9Sstevel@tonic-gate 	else
399*7c478bd9Sstevel@tonic-gate 		name = NULL;
400*7c478bd9Sstevel@tonic-gate 
401*7c478bd9Sstevel@tonic-gate 	if (name != NULL) {
402*7c478bd9Sstevel@tonic-gate 		len = strlen(name);
403*7c478bd9Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
404*7c478bd9Sstevel@tonic-gate 	} else {
405*7c478bd9Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "SYS#%d", sys);
406*7c478bd9Sstevel@tonic-gate 	}
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
409*7c478bd9Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
410*7c478bd9Sstevel@tonic-gate 
411*7c478bd9Sstevel@tonic-gate 	return (buf);
412*7c478bd9Sstevel@tonic-gate }
413*7c478bd9Sstevel@tonic-gate 
414*7c478bd9Sstevel@tonic-gate /*
415*7c478bd9Sstevel@tonic-gate  * Convert a string representation of a fault to the corresponding number.
416*7c478bd9Sstevel@tonic-gate  */
417*7c478bd9Sstevel@tonic-gate int
418*7c478bd9Sstevel@tonic-gate proc_str2flt(const char *str, int *fltnum)
419*7c478bd9Sstevel@tonic-gate {
420*7c478bd9Sstevel@tonic-gate 	char *next;
421*7c478bd9Sstevel@tonic-gate 	int i;
422*7c478bd9Sstevel@tonic-gate 
423*7c478bd9Sstevel@tonic-gate 	i = strtol(str, &next, 0);
424*7c478bd9Sstevel@tonic-gate 	if (i > 0 && i <= PRMAXFAULT && *next == '\0') {
425*7c478bd9Sstevel@tonic-gate 		*fltnum = i;
426*7c478bd9Sstevel@tonic-gate 		return (0);
427*7c478bd9Sstevel@tonic-gate 	}
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate 	for (i = 1; i <= PRMAXFAULT; i++) {
430*7c478bd9Sstevel@tonic-gate 		const char *s = rawfltname(i);
431*7c478bd9Sstevel@tonic-gate 
432*7c478bd9Sstevel@tonic-gate 		if (s && (strcasecmp(s, str) == 0 ||
433*7c478bd9Sstevel@tonic-gate 		    strcasecmp(s + 3, str) == 0)) {
434*7c478bd9Sstevel@tonic-gate 			*fltnum = i;
435*7c478bd9Sstevel@tonic-gate 			return (0);
436*7c478bd9Sstevel@tonic-gate 		}
437*7c478bd9Sstevel@tonic-gate 	}
438*7c478bd9Sstevel@tonic-gate 
439*7c478bd9Sstevel@tonic-gate 	return (-1);
440*7c478bd9Sstevel@tonic-gate }
441*7c478bd9Sstevel@tonic-gate 
442*7c478bd9Sstevel@tonic-gate /*
443*7c478bd9Sstevel@tonic-gate  * Convert a string representation of a signal to the signal number.  This
444*7c478bd9Sstevel@tonic-gate  * functionality is already available in libc, but the interface doesn't
445*7c478bd9Sstevel@tonic-gate  * optionally accept a "SIG" prefix.  We strip that first, and then call libc.
446*7c478bd9Sstevel@tonic-gate  */
447*7c478bd9Sstevel@tonic-gate int
448*7c478bd9Sstevel@tonic-gate proc_str2sig(const char *str, int *signum)
449*7c478bd9Sstevel@tonic-gate {
450*7c478bd9Sstevel@tonic-gate 	if (strncasecmp(str, "SIG", 3) == 0)
451*7c478bd9Sstevel@tonic-gate 		str += 3; /* skip prefix */
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate 	return (str2sig(str, signum));
454*7c478bd9Sstevel@tonic-gate }
455*7c478bd9Sstevel@tonic-gate 
456*7c478bd9Sstevel@tonic-gate /*
457*7c478bd9Sstevel@tonic-gate  * Convert a string representation of a system call to the corresponding number.
458*7c478bd9Sstevel@tonic-gate  * We do this by performing a simple linear search of the table above.
459*7c478bd9Sstevel@tonic-gate  */
460*7c478bd9Sstevel@tonic-gate int
461*7c478bd9Sstevel@tonic-gate proc_str2sys(const char *str, int *sysnum)
462*7c478bd9Sstevel@tonic-gate {
463*7c478bd9Sstevel@tonic-gate 	char *next;
464*7c478bd9Sstevel@tonic-gate 	int i;
465*7c478bd9Sstevel@tonic-gate 
466*7c478bd9Sstevel@tonic-gate 	i = strtol(str, &next, 0);
467*7c478bd9Sstevel@tonic-gate 	if (i > 0 && i <= PRMAXSYS && *next == '\0') {
468*7c478bd9Sstevel@tonic-gate 		*sysnum = i;
469*7c478bd9Sstevel@tonic-gate 		return (0);
470*7c478bd9Sstevel@tonic-gate 	}
471*7c478bd9Sstevel@tonic-gate 
472*7c478bd9Sstevel@tonic-gate 	for (i = 1; i < SYSEND; i++) {
473*7c478bd9Sstevel@tonic-gate 		if (systable[i] != NULL && strcmp(systable[i], str) == 0) {
474*7c478bd9Sstevel@tonic-gate 			*sysnum = i;
475*7c478bd9Sstevel@tonic-gate 			return (0);
476*7c478bd9Sstevel@tonic-gate 		}
477*7c478bd9Sstevel@tonic-gate 	}
478*7c478bd9Sstevel@tonic-gate 
479*7c478bd9Sstevel@tonic-gate 	return (-1);
480*7c478bd9Sstevel@tonic-gate }
481*7c478bd9Sstevel@tonic-gate 
482*7c478bd9Sstevel@tonic-gate /*
483*7c478bd9Sstevel@tonic-gate  * Convert a fltset_t to a string representation consisting of canonical
484*7c478bd9Sstevel@tonic-gate  * machine fault names separated by the given delimeter string.  If
485*7c478bd9Sstevel@tonic-gate  * m is non-zero (TRUE), set members are printed.  If m is zero (FALSE), set
486*7c478bd9Sstevel@tonic-gate  * non-members are printed.  If the specified buf is too small to hold the
487*7c478bd9Sstevel@tonic-gate  * complete formatted set, NULL is returned; otherwise buf is returned.
488*7c478bd9Sstevel@tonic-gate  */
489*7c478bd9Sstevel@tonic-gate char *
490*7c478bd9Sstevel@tonic-gate proc_fltset2str(const fltset_t *set, const char *delim, int m,
491*7c478bd9Sstevel@tonic-gate 	char *buf, size_t len)
492*7c478bd9Sstevel@tonic-gate {
493*7c478bd9Sstevel@tonic-gate 	char name[FLT2STR_MAX], *p = buf;
494*7c478bd9Sstevel@tonic-gate 	size_t n;
495*7c478bd9Sstevel@tonic-gate 	int i;
496*7c478bd9Sstevel@tonic-gate 
497*7c478bd9Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
498*7c478bd9Sstevel@tonic-gate 		errno = EINVAL;
499*7c478bd9Sstevel@tonic-gate 		return (NULL);
500*7c478bd9Sstevel@tonic-gate 	}
501*7c478bd9Sstevel@tonic-gate 
502*7c478bd9Sstevel@tonic-gate 	buf[0] = '\0';  /* Set first byte to \0 */
503*7c478bd9Sstevel@tonic-gate 
504*7c478bd9Sstevel@tonic-gate 	for (i = 1; i <= PRMAXFAULT; i++) {
505*7c478bd9Sstevel@tonic-gate 		if ((prismember(set, i) != 0) ^ (m == 0)) {
506*7c478bd9Sstevel@tonic-gate 			(void) proc_fltname(i, name, sizeof (name));
507*7c478bd9Sstevel@tonic-gate 
508*7c478bd9Sstevel@tonic-gate 			if (buf[0] != '\0')
509*7c478bd9Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
510*7c478bd9Sstevel@tonic-gate 			else
511*7c478bd9Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
512*7c478bd9Sstevel@tonic-gate 
513*7c478bd9Sstevel@tonic-gate 			if (n != strlen(p)) {
514*7c478bd9Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
515*7c478bd9Sstevel@tonic-gate 				return (NULL);
516*7c478bd9Sstevel@tonic-gate 			}
517*7c478bd9Sstevel@tonic-gate 			len -= n;
518*7c478bd9Sstevel@tonic-gate 			p += n;
519*7c478bd9Sstevel@tonic-gate 		}
520*7c478bd9Sstevel@tonic-gate 	}
521*7c478bd9Sstevel@tonic-gate 	return (buf);
522*7c478bd9Sstevel@tonic-gate }
523*7c478bd9Sstevel@tonic-gate 
524*7c478bd9Sstevel@tonic-gate /*
525*7c478bd9Sstevel@tonic-gate  * Convert a sigset_t to a string representation consisting of canonical signal
526*7c478bd9Sstevel@tonic-gate  * names (without the SIG prefix). Parameters and return values analogous to
527*7c478bd9Sstevel@tonic-gate  * proc_fltset2str().
528*7c478bd9Sstevel@tonic-gate  */
529*7c478bd9Sstevel@tonic-gate char *
530*7c478bd9Sstevel@tonic-gate proc_sigset2str(const sigset_t *set, const char *delim, int m,
531*7c478bd9Sstevel@tonic-gate 	char *buf, size_t len)
532*7c478bd9Sstevel@tonic-gate {
533*7c478bd9Sstevel@tonic-gate 	char name[SIG2STR_MAX], *p = buf;
534*7c478bd9Sstevel@tonic-gate 	size_t n;
535*7c478bd9Sstevel@tonic-gate 	int i;
536*7c478bd9Sstevel@tonic-gate 
537*7c478bd9Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
538*7c478bd9Sstevel@tonic-gate 		errno = EINVAL;
539*7c478bd9Sstevel@tonic-gate 		return (NULL);
540*7c478bd9Sstevel@tonic-gate 	}
541*7c478bd9Sstevel@tonic-gate 
542*7c478bd9Sstevel@tonic-gate 	m = (m != 0);	/* Make sure m is 0 or 1 */
543*7c478bd9Sstevel@tonic-gate 	buf[0] = '\0';	/* Set first byte to \0 */
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate 	/*
546*7c478bd9Sstevel@tonic-gate 	 * Unlike proc_fltset2str() and proc_sysset2str(), we don't loop
547*7c478bd9Sstevel@tonic-gate 	 * until i <= NSIG here, because sigismember() rejects i == NSIG.
548*7c478bd9Sstevel@tonic-gate 	 */
549*7c478bd9Sstevel@tonic-gate 	for (i = 1; i < NSIG; i++) {
550*7c478bd9Sstevel@tonic-gate 		if (sigismember(set, i) == m) {
551*7c478bd9Sstevel@tonic-gate 			(void) sig2str(i, name);
552*7c478bd9Sstevel@tonic-gate 
553*7c478bd9Sstevel@tonic-gate 			if (buf[0] != '\0')
554*7c478bd9Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
555*7c478bd9Sstevel@tonic-gate 			else
556*7c478bd9Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
557*7c478bd9Sstevel@tonic-gate 
558*7c478bd9Sstevel@tonic-gate 			if (n != strlen(p)) {
559*7c478bd9Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
560*7c478bd9Sstevel@tonic-gate 				return (NULL);
561*7c478bd9Sstevel@tonic-gate 			}
562*7c478bd9Sstevel@tonic-gate 
563*7c478bd9Sstevel@tonic-gate 			len -= n;
564*7c478bd9Sstevel@tonic-gate 			p += n;
565*7c478bd9Sstevel@tonic-gate 		}
566*7c478bd9Sstevel@tonic-gate 	}
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate 	return (buf);
569*7c478bd9Sstevel@tonic-gate }
570*7c478bd9Sstevel@tonic-gate 
571*7c478bd9Sstevel@tonic-gate /*
572*7c478bd9Sstevel@tonic-gate  * Convert a sysset_t to a string representation consisting of canonical system
573*7c478bd9Sstevel@tonic-gate  * call names. Parameters and return values analogous to proc_fltset2str().
574*7c478bd9Sstevel@tonic-gate  */
575*7c478bd9Sstevel@tonic-gate char *
576*7c478bd9Sstevel@tonic-gate proc_sysset2str(const sysset_t *set, const char *delim, int m,
577*7c478bd9Sstevel@tonic-gate 	char *buf, size_t len)
578*7c478bd9Sstevel@tonic-gate {
579*7c478bd9Sstevel@tonic-gate 	char name[SYS2STR_MAX], *p = buf;
580*7c478bd9Sstevel@tonic-gate 	size_t n;
581*7c478bd9Sstevel@tonic-gate 	int i;
582*7c478bd9Sstevel@tonic-gate 
583*7c478bd9Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
584*7c478bd9Sstevel@tonic-gate 		errno = EINVAL;
585*7c478bd9Sstevel@tonic-gate 		return (NULL);
586*7c478bd9Sstevel@tonic-gate 	}
587*7c478bd9Sstevel@tonic-gate 
588*7c478bd9Sstevel@tonic-gate 	buf[0] = '\0';  /* Set first byte to \0 */
589*7c478bd9Sstevel@tonic-gate 
590*7c478bd9Sstevel@tonic-gate 	for (i = 1; i <= PRMAXSYS; i++) {
591*7c478bd9Sstevel@tonic-gate 		if ((prismember(set, i) != 0) ^ (m == 0)) {
592*7c478bd9Sstevel@tonic-gate 			(void) proc_sysname(i, name, sizeof (name));
593*7c478bd9Sstevel@tonic-gate 
594*7c478bd9Sstevel@tonic-gate 			if (buf[0] != '\0')
595*7c478bd9Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
596*7c478bd9Sstevel@tonic-gate 			else
597*7c478bd9Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
598*7c478bd9Sstevel@tonic-gate 
599*7c478bd9Sstevel@tonic-gate 			if (n != strlen(p)) {
600*7c478bd9Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
601*7c478bd9Sstevel@tonic-gate 				return (NULL);
602*7c478bd9Sstevel@tonic-gate 			}
603*7c478bd9Sstevel@tonic-gate 			len -= n;
604*7c478bd9Sstevel@tonic-gate 			p += n;
605*7c478bd9Sstevel@tonic-gate 		}
606*7c478bd9Sstevel@tonic-gate 	}
607*7c478bd9Sstevel@tonic-gate 	return (buf);
608*7c478bd9Sstevel@tonic-gate }
609*7c478bd9Sstevel@tonic-gate 
610*7c478bd9Sstevel@tonic-gate /*
611*7c478bd9Sstevel@tonic-gate  * Convert a string representation of a fault set (names separated by
612*7c478bd9Sstevel@tonic-gate  * one or more of the given delimeters) to a fltset_t.
613*7c478bd9Sstevel@tonic-gate  * If m is non-zero (TRUE), members of the string representation are set.
614*7c478bd9Sstevel@tonic-gate  * If m is zero (FALSE), non-members of the string representation are set.
615*7c478bd9Sstevel@tonic-gate  * This function returns NULL for success. Otherwise it returns a pointer
616*7c478bd9Sstevel@tonic-gate  * to the token of the string that couldn't be identified as a string
617*7c478bd9Sstevel@tonic-gate  * representation of a fault.
618*7c478bd9Sstevel@tonic-gate  */
619*7c478bd9Sstevel@tonic-gate char *
620*7c478bd9Sstevel@tonic-gate proc_str2fltset(const char *s, const char *delim, int m, fltset_t *set)
621*7c478bd9Sstevel@tonic-gate {
622*7c478bd9Sstevel@tonic-gate 	char *p, *q, *t = alloca(strlen(s) + 1);
623*7c478bd9Sstevel@tonic-gate 	int flt;
624*7c478bd9Sstevel@tonic-gate 
625*7c478bd9Sstevel@tonic-gate 	if (m) {
626*7c478bd9Sstevel@tonic-gate 		premptyset(set);
627*7c478bd9Sstevel@tonic-gate 	} else {
628*7c478bd9Sstevel@tonic-gate 		prfillset(set);
629*7c478bd9Sstevel@tonic-gate 	}
630*7c478bd9Sstevel@tonic-gate 
631*7c478bd9Sstevel@tonic-gate 	(void) strcpy(t, s);
632*7c478bd9Sstevel@tonic-gate 
633*7c478bd9Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
634*7c478bd9Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
635*7c478bd9Sstevel@tonic-gate 		if (proc_str2flt(p, &flt) == -1) {
636*7c478bd9Sstevel@tonic-gate 			errno = EINVAL;
637*7c478bd9Sstevel@tonic-gate 			return ((char *)s + (p - t));
638*7c478bd9Sstevel@tonic-gate 		}
639*7c478bd9Sstevel@tonic-gate 		if (m)
640*7c478bd9Sstevel@tonic-gate 			praddset(set, flt);
641*7c478bd9Sstevel@tonic-gate 		else
642*7c478bd9Sstevel@tonic-gate 			prdelset(set, flt);
643*7c478bd9Sstevel@tonic-gate 	}
644*7c478bd9Sstevel@tonic-gate 	return (NULL);
645*7c478bd9Sstevel@tonic-gate }
646*7c478bd9Sstevel@tonic-gate 
647*7c478bd9Sstevel@tonic-gate /*
648*7c478bd9Sstevel@tonic-gate  * Convert a string representation of a signal set (names with or without the
649*7c478bd9Sstevel@tonic-gate  * SIG prefix separated by one or more of the given delimeters) to a sigset_t.
650*7c478bd9Sstevel@tonic-gate  * Parameters and return values analogous to proc_str2fltset().
651*7c478bd9Sstevel@tonic-gate  */
652*7c478bd9Sstevel@tonic-gate char *
653*7c478bd9Sstevel@tonic-gate proc_str2sigset(const char *s, const char *delim, int m, sigset_t *set)
654*7c478bd9Sstevel@tonic-gate {
655*7c478bd9Sstevel@tonic-gate 	char *p, *q, *t = alloca(strlen(s) + 1);
656*7c478bd9Sstevel@tonic-gate 	int sig;
657*7c478bd9Sstevel@tonic-gate 
658*7c478bd9Sstevel@tonic-gate 	if (m) {
659*7c478bd9Sstevel@tonic-gate 		premptyset(set);
660*7c478bd9Sstevel@tonic-gate 	} else {
661*7c478bd9Sstevel@tonic-gate 		prfillset(set);
662*7c478bd9Sstevel@tonic-gate 	}
663*7c478bd9Sstevel@tonic-gate 
664*7c478bd9Sstevel@tonic-gate 	(void) strcpy(t, s);
665*7c478bd9Sstevel@tonic-gate 
666*7c478bd9Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
667*7c478bd9Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
668*7c478bd9Sstevel@tonic-gate 		if (proc_str2sig(p, &sig) == -1) {
669*7c478bd9Sstevel@tonic-gate 			errno = EINVAL;
670*7c478bd9Sstevel@tonic-gate 			return ((char *)s + (p - t));
671*7c478bd9Sstevel@tonic-gate 		}
672*7c478bd9Sstevel@tonic-gate 		if (m)
673*7c478bd9Sstevel@tonic-gate 			praddset(set, sig);
674*7c478bd9Sstevel@tonic-gate 		else
675*7c478bd9Sstevel@tonic-gate 			prdelset(set, sig);
676*7c478bd9Sstevel@tonic-gate 	}
677*7c478bd9Sstevel@tonic-gate 	return (NULL);
678*7c478bd9Sstevel@tonic-gate }
679*7c478bd9Sstevel@tonic-gate 
680*7c478bd9Sstevel@tonic-gate /*
681*7c478bd9Sstevel@tonic-gate  * Convert a string representation of a system call set (names separated by
682*7c478bd9Sstevel@tonic-gate  * one or more of the given delimeters) to a sysset_t. Parameters and return
683*7c478bd9Sstevel@tonic-gate  * values analogous to proc_str2fltset().
684*7c478bd9Sstevel@tonic-gate  */
685*7c478bd9Sstevel@tonic-gate char *
686*7c478bd9Sstevel@tonic-gate proc_str2sysset(const char *s, const char *delim, int m, sysset_t *set)
687*7c478bd9Sstevel@tonic-gate {
688*7c478bd9Sstevel@tonic-gate 	char *p, *q, *t = alloca(strlen(s) + 1);
689*7c478bd9Sstevel@tonic-gate 	int sys;
690*7c478bd9Sstevel@tonic-gate 
691*7c478bd9Sstevel@tonic-gate 	if (m) {
692*7c478bd9Sstevel@tonic-gate 		premptyset(set);
693*7c478bd9Sstevel@tonic-gate 	} else {
694*7c478bd9Sstevel@tonic-gate 		prfillset(set);
695*7c478bd9Sstevel@tonic-gate 	}
696*7c478bd9Sstevel@tonic-gate 
697*7c478bd9Sstevel@tonic-gate 	(void) strcpy(t, s);
698*7c478bd9Sstevel@tonic-gate 
699*7c478bd9Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
700*7c478bd9Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
701*7c478bd9Sstevel@tonic-gate 		if (proc_str2sys(p, &sys) == -1) {
702*7c478bd9Sstevel@tonic-gate 			errno = EINVAL;
703*7c478bd9Sstevel@tonic-gate 			return ((char *)s + (p - t));
704*7c478bd9Sstevel@tonic-gate 		}
705*7c478bd9Sstevel@tonic-gate 		if (m)
706*7c478bd9Sstevel@tonic-gate 			praddset(set, sys);
707*7c478bd9Sstevel@tonic-gate 		else
708*7c478bd9Sstevel@tonic-gate 			prdelset(set, sys);
709*7c478bd9Sstevel@tonic-gate 	}
710*7c478bd9Sstevel@tonic-gate 	return (NULL);
711*7c478bd9Sstevel@tonic-gate }
712