xref: /onnv-gate/usr/src/lib/libproc/common/proc_names.c (revision 13093:48f2dbca79a2)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52712Snn35248  * Common Development and Distribution License (the "License").
62712Snn35248  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
2111798SRoger.Faulkner@Sun.COM 
220Sstevel@tonic-gate /*
2312789SRoger.Faulkner@Oracle.COM  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include <stdio.h>
270Sstevel@tonic-gate #define	__EXTENSIONS__
280Sstevel@tonic-gate #include <string.h>
290Sstevel@tonic-gate #undef  __EXTENSIONS__
300Sstevel@tonic-gate #include <signal.h>
310Sstevel@tonic-gate #include <errno.h>
320Sstevel@tonic-gate #include "libproc.h"
330Sstevel@tonic-gate 
340Sstevel@tonic-gate static const char *
rawfltname(int flt)350Sstevel@tonic-gate rawfltname(int flt)
360Sstevel@tonic-gate {
370Sstevel@tonic-gate 	const char *name;
380Sstevel@tonic-gate 
390Sstevel@tonic-gate 	switch (flt) {
400Sstevel@tonic-gate 	case FLTILL:	name = "FLTILL";	break;
410Sstevel@tonic-gate 	case FLTPRIV:	name = "FLTPRIV";	break;
420Sstevel@tonic-gate 	case FLTBPT:	name = "FLTBPT";	break;
430Sstevel@tonic-gate 	case FLTTRACE:	name = "FLTTRACE";	break;
440Sstevel@tonic-gate 	case FLTACCESS:	name = "FLTACCESS";	break;
450Sstevel@tonic-gate 	case FLTBOUNDS:	name = "FLTBOUNDS";	break;
460Sstevel@tonic-gate 	case FLTIOVF:	name = "FLTIOVF";	break;
470Sstevel@tonic-gate 	case FLTIZDIV:	name = "FLTIZDIV";	break;
480Sstevel@tonic-gate 	case FLTFPE:	name = "FLTFPE";	break;
490Sstevel@tonic-gate 	case FLTSTACK:	name = "FLTSTACK";	break;
500Sstevel@tonic-gate 	case FLTPAGE:	name = "FLTPAGE";	break;
510Sstevel@tonic-gate 	case FLTWATCH:	name = "FLTWATCH";	break;
520Sstevel@tonic-gate 	case FLTCPCOVF:	name = "FLTCPCOVF";	break;
530Sstevel@tonic-gate 	default:	name = NULL;		break;
540Sstevel@tonic-gate 	}
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	return (name);
570Sstevel@tonic-gate }
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate  * Return the name of a fault.
610Sstevel@tonic-gate  * Manufacture a name for unknown fault.
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate char *
proc_fltname(int flt,char * buf,size_t bufsz)640Sstevel@tonic-gate proc_fltname(int flt, char *buf, size_t bufsz)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate 	const char *name = rawfltname(flt);
670Sstevel@tonic-gate 	size_t len;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
700Sstevel@tonic-gate 		return (NULL);
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	if (name != NULL) {
730Sstevel@tonic-gate 		len = strlen(name);
740Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
750Sstevel@tonic-gate 	} else {
760Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "FLT#%d", flt);
770Sstevel@tonic-gate 	}
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
800Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	return (buf);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * Return the name of a signal.
870Sstevel@tonic-gate  * Manufacture a name for unknown signal.
880Sstevel@tonic-gate  */
890Sstevel@tonic-gate char *
proc_signame(int sig,char * buf,size_t bufsz)900Sstevel@tonic-gate proc_signame(int sig, char *buf, size_t bufsz)
910Sstevel@tonic-gate {
920Sstevel@tonic-gate 	char name[SIG2STR_MAX+4];
930Sstevel@tonic-gate 	size_t len;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
960Sstevel@tonic-gate 		return (NULL);
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 	/* sig2str() omits the leading "SIG" */
990Sstevel@tonic-gate 	(void) strcpy(name, "SIG");
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	if (sig2str(sig, name+3) == 0) {
1020Sstevel@tonic-gate 		len = strlen(name);
1030Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
1040Sstevel@tonic-gate 	} else {
1050Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "SIG#%d", sig);
1060Sstevel@tonic-gate 	}
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
1090Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	return (buf);
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate static const char *const systable[] = {
1150Sstevel@tonic-gate 	NULL,			/*  0 */
1160Sstevel@tonic-gate 	"_exit",		/*  1 */
11711798SRoger.Faulkner@Sun.COM 	NULL,			/*  2 */
1180Sstevel@tonic-gate 	"read",			/*  3 */
1190Sstevel@tonic-gate 	"write",		/*  4 */
1200Sstevel@tonic-gate 	"open",			/*  5 */
1210Sstevel@tonic-gate 	"close",		/*  6 */
12212789SRoger.Faulkner@Oracle.COM 	"linkat",		/*  7 */
12311798SRoger.Faulkner@Sun.COM 	NULL,			/*  8 */
1240Sstevel@tonic-gate 	"link",			/*  9 */
1250Sstevel@tonic-gate 	"unlink",		/* 10 */
12612789SRoger.Faulkner@Oracle.COM 	"symlinkat",		/* 11 */
1270Sstevel@tonic-gate 	"chdir",		/* 12 */
1280Sstevel@tonic-gate 	"time",			/* 13 */
1290Sstevel@tonic-gate 	"mknod",		/* 14 */
1300Sstevel@tonic-gate 	"chmod",		/* 15 */
1310Sstevel@tonic-gate 	"chown",		/* 16 */
1320Sstevel@tonic-gate 	"brk",			/* 17 */
1330Sstevel@tonic-gate 	"stat",			/* 18 */
1340Sstevel@tonic-gate 	"lseek",		/* 19 */
1350Sstevel@tonic-gate 	"getpid",		/* 20 */
1360Sstevel@tonic-gate 	"mount",		/* 21 */
13712789SRoger.Faulkner@Oracle.COM 	"readlinkat",		/* 22 */
1380Sstevel@tonic-gate 	"setuid",		/* 23 */
1390Sstevel@tonic-gate 	"getuid",		/* 24 */
1400Sstevel@tonic-gate 	"stime",		/* 25 */
1410Sstevel@tonic-gate 	"ptrace",		/* 26 */
1420Sstevel@tonic-gate 	"alarm",		/* 27 */
1430Sstevel@tonic-gate 	"fstat",		/* 28 */
1440Sstevel@tonic-gate 	"pause",		/* 29 */
14511798SRoger.Faulkner@Sun.COM 	NULL,			/* 30 */
1460Sstevel@tonic-gate 	"stty",			/* 31 */
1470Sstevel@tonic-gate 	"gtty",			/* 32 */
1480Sstevel@tonic-gate 	"access",		/* 33 */
1490Sstevel@tonic-gate 	"nice",			/* 34 */
1500Sstevel@tonic-gate 	"statfs",		/* 35 */
1510Sstevel@tonic-gate 	"sync",			/* 36 */
1520Sstevel@tonic-gate 	"kill",			/* 37 */
1530Sstevel@tonic-gate 	"fstatfs",		/* 38 */
1540Sstevel@tonic-gate 	"pgrpsys",		/* 39 */
1552712Snn35248 	"uucopystr",		/* 40 */
15611798SRoger.Faulkner@Sun.COM 	NULL,			/* 41 */
1570Sstevel@tonic-gate 	"pipe",			/* 42 */
1580Sstevel@tonic-gate 	"times",		/* 43 */
1590Sstevel@tonic-gate 	"profil",		/* 44 */
16011798SRoger.Faulkner@Sun.COM 	"faccessat",		/* 45 */
1610Sstevel@tonic-gate 	"setgid",		/* 46 */
1620Sstevel@tonic-gate 	"getgid",		/* 47 */
16312789SRoger.Faulkner@Oracle.COM 	"mknodat",		/* 48 */
1640Sstevel@tonic-gate 	"msgsys",		/* 49 */
1650Sstevel@tonic-gate 	"sysi86",		/* 50 */
1660Sstevel@tonic-gate 	"acct",			/* 51 */
1670Sstevel@tonic-gate 	"shmsys",		/* 52 */
1680Sstevel@tonic-gate 	"semsys",		/* 53 */
1690Sstevel@tonic-gate 	"ioctl",		/* 54 */
1700Sstevel@tonic-gate 	"uadmin",		/* 55 */
17111798SRoger.Faulkner@Sun.COM 	"fchownat",		/* 56 */
1720Sstevel@tonic-gate 	"utssys",		/* 57 */
1730Sstevel@tonic-gate 	"fdsync",		/* 58 */
1740Sstevel@tonic-gate 	"execve",		/* 59 */
1750Sstevel@tonic-gate 	"umask",		/* 60 */
1760Sstevel@tonic-gate 	"chroot",		/* 61 */
1770Sstevel@tonic-gate 	"fcntl",		/* 62 */
1780Sstevel@tonic-gate 	"ulimit",		/* 63 */
17911798SRoger.Faulkner@Sun.COM 	"renameat",		/* 64 */
18011798SRoger.Faulkner@Sun.COM 	"unlinkat",		/* 65 */
18111798SRoger.Faulkner@Sun.COM 	"fstatat",		/* 66 */
18211798SRoger.Faulkner@Sun.COM 	"fstatat64",		/* 67 */
18311798SRoger.Faulkner@Sun.COM 	"openat",		/* 68 */
18411798SRoger.Faulkner@Sun.COM 	"openat64",		/* 69 */
1850Sstevel@tonic-gate 	"tasksys",		/* 70 */
1860Sstevel@tonic-gate 	"acctctl",		/* 71 */
1870Sstevel@tonic-gate 	"exacctsys",		/* 72 */
1880Sstevel@tonic-gate 	"getpagesizes",		/* 73 */
1890Sstevel@tonic-gate 	"rctlsys",		/* 74 */
1900Sstevel@tonic-gate 	"issetugid",		/* 75 */
1910Sstevel@tonic-gate 	"fsat",			/* 76 */
1920Sstevel@tonic-gate 	"lwp_park",		/* 77 */
1930Sstevel@tonic-gate 	"sendfilev",		/* 78 */
1940Sstevel@tonic-gate 	"rmdir",		/* 79 */
1950Sstevel@tonic-gate 	"mkdir",		/* 80 */
1960Sstevel@tonic-gate 	"getdents",		/* 81 */
1970Sstevel@tonic-gate 	"privsys",		/* 82 */
1980Sstevel@tonic-gate 	"ucredsys",		/* 83 */
1990Sstevel@tonic-gate 	"sysfs",		/* 84 */
2000Sstevel@tonic-gate 	"getmsg",		/* 85 */
2010Sstevel@tonic-gate 	"putmsg",		/* 86 */
20211798SRoger.Faulkner@Sun.COM 	NULL,			/* 87 */
2030Sstevel@tonic-gate 	"lstat",		/* 88 */
2040Sstevel@tonic-gate 	"symlink",		/* 89 */
2050Sstevel@tonic-gate 	"readlink",		/* 90 */
2060Sstevel@tonic-gate 	"setgroups",		/* 91 */
2070Sstevel@tonic-gate 	"getgroups",		/* 92 */
2080Sstevel@tonic-gate 	"fchmod",		/* 93 */
2090Sstevel@tonic-gate 	"fchown",		/* 94 */
2100Sstevel@tonic-gate 	"sigprocmask",		/* 95 */
2110Sstevel@tonic-gate 	"sigsuspend",		/* 96 */
2120Sstevel@tonic-gate 	"sigaltstack",		/* 97 */
2130Sstevel@tonic-gate 	"sigaction",		/* 98 */
2140Sstevel@tonic-gate 	"sigpending",		/* 99 */
2150Sstevel@tonic-gate 	"context",		/* 100 */
21612789SRoger.Faulkner@Oracle.COM 	"fchmodat",		/* 101 */
21712789SRoger.Faulkner@Oracle.COM 	"mkdirat",		/* 102 */
2180Sstevel@tonic-gate 	"statvfs",		/* 103 */
2190Sstevel@tonic-gate 	"fstatvfs",		/* 104 */
2200Sstevel@tonic-gate 	"getloadavg",		/* 105 */
2210Sstevel@tonic-gate 	"nfssys",		/* 106 */
2220Sstevel@tonic-gate 	"waitid",		/* 107 */
2230Sstevel@tonic-gate 	"sigsendsys",		/* 108 */
2240Sstevel@tonic-gate 	"hrtsys",		/* 109 */
2250Sstevel@tonic-gate 	"acancel",		/* 110 */
2260Sstevel@tonic-gate 	"async",		/* 111 */
2270Sstevel@tonic-gate 	"priocntlsys",		/* 112 */
2280Sstevel@tonic-gate 	"pathconf",		/* 113 */
2290Sstevel@tonic-gate 	"mincore",		/* 114 */
2300Sstevel@tonic-gate 	"mmap",			/* 115 */
2310Sstevel@tonic-gate 	"mprotect",		/* 116 */
2320Sstevel@tonic-gate 	"munmap",		/* 117 */
2330Sstevel@tonic-gate 	"fpathconf",		/* 118 */
2340Sstevel@tonic-gate 	"vfork",		/* 119 */
2350Sstevel@tonic-gate 	"fchdir",		/* 120 */
2360Sstevel@tonic-gate 	"readv",		/* 121 */
2370Sstevel@tonic-gate 	"writev",		/* 122 */
23811798SRoger.Faulkner@Sun.COM 	NULL,			/* 123 */
23911798SRoger.Faulkner@Sun.COM 	NULL,			/* 124 */
24011798SRoger.Faulkner@Sun.COM 	NULL,			/* 125 */
24111798SRoger.Faulkner@Sun.COM 	NULL,			/* 126 */
2428212SMichael.Corcoran@Sun.COM 	"mmapobj",		/* 127 */
2430Sstevel@tonic-gate 	"setrlimit",		/* 128 */
2440Sstevel@tonic-gate 	"getrlimit",		/* 129 */
2450Sstevel@tonic-gate 	"lchown",		/* 130 */
2460Sstevel@tonic-gate 	"memcntl",		/* 131 */
2470Sstevel@tonic-gate 	"getpmsg",		/* 132 */
2480Sstevel@tonic-gate 	"putpmsg",		/* 133 */
2490Sstevel@tonic-gate 	"rename",		/* 134 */
2500Sstevel@tonic-gate 	"uname",		/* 135 */
2510Sstevel@tonic-gate 	"setegid",		/* 136 */
2520Sstevel@tonic-gate 	"sysconfig",		/* 137 */
2530Sstevel@tonic-gate 	"adjtime",		/* 138 */
2540Sstevel@tonic-gate 	"systeminfo",		/* 139 */
2553957Sth199096 	"sharefs",		/* 140 */
2560Sstevel@tonic-gate 	"seteuid",		/* 141 */
2574801Seschrock 	"forksys",		/* 142 */
25811798SRoger.Faulkner@Sun.COM 	NULL,			/* 143 */
2590Sstevel@tonic-gate 	"sigtimedwait",		/* 144 */
2600Sstevel@tonic-gate 	"lwp_info",		/* 145 */
2610Sstevel@tonic-gate 	"yield",		/* 146 */
26211798SRoger.Faulkner@Sun.COM 	NULL,			/* 147 */
2630Sstevel@tonic-gate 	"lwp_sema_post",	/* 148 */
2640Sstevel@tonic-gate 	"lwp_sema_trywait",	/* 149 */
2650Sstevel@tonic-gate 	"lwp_detatch",		/* 150 */
2660Sstevel@tonic-gate 	"corectl",		/* 151 */
2670Sstevel@tonic-gate 	"modctl",		/* 152 */
2680Sstevel@tonic-gate 	"fchroot",		/* 153 */
26911798SRoger.Faulkner@Sun.COM 	NULL,			/* 154 */
2700Sstevel@tonic-gate 	"vhangup",		/* 155 */
2710Sstevel@tonic-gate 	"gettimeofday",		/* 156 */
2720Sstevel@tonic-gate 	"getitimer",		/* 157 */
2730Sstevel@tonic-gate 	"setitimer",		/* 158 */
2740Sstevel@tonic-gate 	"lwp_create",		/* 159 */
2750Sstevel@tonic-gate 	"lwp_exit",		/* 160 */
2760Sstevel@tonic-gate 	"lwp_suspend",		/* 161 */
2770Sstevel@tonic-gate 	"lwp_continue",		/* 162 */
2780Sstevel@tonic-gate 	"lwp_kill",		/* 163 */
2790Sstevel@tonic-gate 	"lwp_self",		/* 164 */
2800Sstevel@tonic-gate 	"lwp_sigmask",		/* 165 */
2810Sstevel@tonic-gate 	"lwp_private",		/* 166 */
2820Sstevel@tonic-gate 	"lwp_wait",		/* 167 */
2834574Sraf 	"lwp_mutex_wakeup",	/* 168 */
28411798SRoger.Faulkner@Sun.COM 	NULL,			/* 169 */
2850Sstevel@tonic-gate 	"lwp_cond_wait",	/* 170 */
2860Sstevel@tonic-gate 	"lwp_cond_signal",	/* 171 */
2870Sstevel@tonic-gate 	"lwp_cond_broadcast",	/* 172 */
2880Sstevel@tonic-gate 	"pread",		/* 173 */
2890Sstevel@tonic-gate 	"pwrite",		/* 174 */
2900Sstevel@tonic-gate 	"llseek",		/* 175 */
2910Sstevel@tonic-gate 	"inst_sync",		/* 176 */
2922712Snn35248 	"brand",		/* 177 */
2930Sstevel@tonic-gate 	"kaio",			/* 178 */
2940Sstevel@tonic-gate 	"cpc",			/* 179 */
2950Sstevel@tonic-gate 	"lgrpsys",		/* 180 */
2960Sstevel@tonic-gate 	"rusagesys",		/* 181 */
2970Sstevel@tonic-gate 	"portfs",		/* 182 */
2980Sstevel@tonic-gate 	"pollsys",		/* 183 */
29911798SRoger.Faulkner@Sun.COM 	"labelsys",		/* 184 */
3000Sstevel@tonic-gate 	"acl",			/* 185 */
3010Sstevel@tonic-gate 	"auditsys",		/* 186 */
3020Sstevel@tonic-gate 	"processor_bind",	/* 187 */
3030Sstevel@tonic-gate 	"processor_info",	/* 188 */
3040Sstevel@tonic-gate 	"p_online",		/* 189 */
3050Sstevel@tonic-gate 	"sigqueue",		/* 190 */
3060Sstevel@tonic-gate 	"clock_gettime",	/* 191 */
3070Sstevel@tonic-gate 	"clock_settime",	/* 192 */
3080Sstevel@tonic-gate 	"clock_getres",		/* 193 */
3090Sstevel@tonic-gate 	"timer_create",		/* 194 */
3100Sstevel@tonic-gate 	"timer_delete",		/* 195 */
3110Sstevel@tonic-gate 	"timer_settime",	/* 196 */
3120Sstevel@tonic-gate 	"timer_gettime",	/* 197 */
3130Sstevel@tonic-gate 	"timer_getoverrun",	/* 198 */
3140Sstevel@tonic-gate 	"nanosleep",		/* 199 */
3150Sstevel@tonic-gate 	"facl",			/* 200 */
3160Sstevel@tonic-gate 	"door",			/* 201 */
3170Sstevel@tonic-gate 	"setreuid",		/* 202 */
3180Sstevel@tonic-gate 	"setregid",		/* 203 */
3190Sstevel@tonic-gate 	"install_utrap",	/* 204 */
3200Sstevel@tonic-gate 	"signotify",		/* 205 */
3210Sstevel@tonic-gate 	"schedctl",		/* 206 */
3220Sstevel@tonic-gate 	"pset",			/* 207 */
3230Sstevel@tonic-gate 	"sparc_utrap_install",	/* 208 */
3240Sstevel@tonic-gate 	"resolvepath",		/* 209 */
3250Sstevel@tonic-gate 	"lwp_mutex_timedlock",	/* 210 */
3260Sstevel@tonic-gate 	"lwp_sema_timedwait",	/* 211 */
3270Sstevel@tonic-gate 	"lwp_rwlock_sys",	/* 212 */
3280Sstevel@tonic-gate 	"getdents64",		/* 213 */
3290Sstevel@tonic-gate 	"mmap64",		/* 214 */
3300Sstevel@tonic-gate 	"stat64",		/* 215 */
3310Sstevel@tonic-gate 	"lstat64",		/* 216 */
3320Sstevel@tonic-gate 	"fstat64",		/* 217 */
3330Sstevel@tonic-gate 	"statvfs64",		/* 218 */
3340Sstevel@tonic-gate 	"fstatvfs64",		/* 219 */
3350Sstevel@tonic-gate 	"setrlimit64",		/* 220 */
3360Sstevel@tonic-gate 	"getrlimit64",		/* 221 */
3370Sstevel@tonic-gate 	"pread64",		/* 222 */
3380Sstevel@tonic-gate 	"pwrite64",		/* 223 */
33911798SRoger.Faulkner@Sun.COM 	NULL,			/* 224 */
3400Sstevel@tonic-gate 	"open64",		/* 225 */
3410Sstevel@tonic-gate 	"rpcmod",		/* 226 */
3420Sstevel@tonic-gate 	"zone",			/* 227 */
3430Sstevel@tonic-gate 	"autofssys",		/* 228 */
3440Sstevel@tonic-gate 	"getcwd",		/* 229 */
3450Sstevel@tonic-gate 	"so_socket",		/* 230 */
3460Sstevel@tonic-gate 	"so_socketpair",	/* 231 */
3470Sstevel@tonic-gate 	"bind",			/* 232 */
3480Sstevel@tonic-gate 	"listen",		/* 233 */
3490Sstevel@tonic-gate 	"accept",		/* 234 */
3500Sstevel@tonic-gate 	"connect",		/* 235 */
3510Sstevel@tonic-gate 	"shutdown",		/* 236 */
3520Sstevel@tonic-gate 	"recv",			/* 237 */
3530Sstevel@tonic-gate 	"recvfrom",		/* 238 */
3540Sstevel@tonic-gate 	"recvmsg",		/* 239 */
3550Sstevel@tonic-gate 	"send",			/* 240 */
3560Sstevel@tonic-gate 	"sendmsg",		/* 241 */
3570Sstevel@tonic-gate 	"sendto",		/* 242 */
3580Sstevel@tonic-gate 	"getpeername",		/* 243 */
3590Sstevel@tonic-gate 	"getsockname",		/* 244 */
3600Sstevel@tonic-gate 	"getsockopt",		/* 245 */
3610Sstevel@tonic-gate 	"setsockopt",		/* 246 */
3620Sstevel@tonic-gate 	"sockconfig",		/* 247 */
3630Sstevel@tonic-gate 	"ntp_gettime",		/* 248 */
3640Sstevel@tonic-gate 	"ntp_adjtime",		/* 249 */
3650Sstevel@tonic-gate 	"lwp_mutex_unlock",	/* 250 */
3660Sstevel@tonic-gate 	"lwp_mutex_trylock",	/* 251 */
3674574Sraf 	"lwp_mutex_register",	/* 252 */
3680Sstevel@tonic-gate 	"cladm",		/* 253 */
3692712Snn35248 	"uucopy",		/* 254 */
3700Sstevel@tonic-gate 	"umount2"		/* 255 */
3710Sstevel@tonic-gate };
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate /* SYSEND == max syscall number + 1 */
3740Sstevel@tonic-gate #define	SYSEND	(sizeof (systable) / sizeof (systable[0]))
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate /*
3770Sstevel@tonic-gate  * Return the name of a system call.
3780Sstevel@tonic-gate  * Manufacture a name for unknown system call.
3790Sstevel@tonic-gate  */
3800Sstevel@tonic-gate char *
proc_sysname(int sys,char * buf,size_t bufsz)3810Sstevel@tonic-gate proc_sysname(int sys, char *buf, size_t bufsz)
3820Sstevel@tonic-gate {
3830Sstevel@tonic-gate 	const char *name;
3840Sstevel@tonic-gate 	size_t len;
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	if (bufsz == 0)		/* force a program failure */
3870Sstevel@tonic-gate 		return (NULL);
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 	if (sys >= 0 && sys < SYSEND)
3900Sstevel@tonic-gate 		name = systable[sys];
3910Sstevel@tonic-gate 	else
3920Sstevel@tonic-gate 		name = NULL;
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate 	if (name != NULL) {
3950Sstevel@tonic-gate 		len = strlen(name);
3960Sstevel@tonic-gate 		(void) strncpy(buf, name, bufsz);
3970Sstevel@tonic-gate 	} else {
3980Sstevel@tonic-gate 		len = snprintf(buf, bufsz, "SYS#%d", sys);
3990Sstevel@tonic-gate 	}
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate 	if (len >= bufsz)	/* ensure null-termination */
4020Sstevel@tonic-gate 		buf[bufsz-1] = '\0';
4030Sstevel@tonic-gate 
4040Sstevel@tonic-gate 	return (buf);
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate /*
4080Sstevel@tonic-gate  * Convert a string representation of a fault to the corresponding number.
4090Sstevel@tonic-gate  */
4100Sstevel@tonic-gate int
proc_str2flt(const char * str,int * fltnum)4110Sstevel@tonic-gate proc_str2flt(const char *str, int *fltnum)
4120Sstevel@tonic-gate {
4130Sstevel@tonic-gate 	char *next;
4140Sstevel@tonic-gate 	int i;
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 	i = strtol(str, &next, 0);
4170Sstevel@tonic-gate 	if (i > 0 && i <= PRMAXFAULT && *next == '\0') {
4180Sstevel@tonic-gate 		*fltnum = i;
4190Sstevel@tonic-gate 		return (0);
4200Sstevel@tonic-gate 	}
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate 	for (i = 1; i <= PRMAXFAULT; i++) {
4230Sstevel@tonic-gate 		const char *s = rawfltname(i);
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate 		if (s && (strcasecmp(s, str) == 0 ||
4260Sstevel@tonic-gate 		    strcasecmp(s + 3, str) == 0)) {
4270Sstevel@tonic-gate 			*fltnum = i;
4280Sstevel@tonic-gate 			return (0);
4290Sstevel@tonic-gate 		}
4300Sstevel@tonic-gate 	}
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate 	return (-1);
4330Sstevel@tonic-gate }
4340Sstevel@tonic-gate 
4350Sstevel@tonic-gate /*
4360Sstevel@tonic-gate  * Convert a string representation of a signal to the signal number.  This
4370Sstevel@tonic-gate  * functionality is already available in libc, but the interface doesn't
4380Sstevel@tonic-gate  * optionally accept a "SIG" prefix.  We strip that first, and then call libc.
4390Sstevel@tonic-gate  */
4400Sstevel@tonic-gate int
proc_str2sig(const char * str,int * signum)4410Sstevel@tonic-gate proc_str2sig(const char *str, int *signum)
4420Sstevel@tonic-gate {
4430Sstevel@tonic-gate 	if (strncasecmp(str, "SIG", 3) == 0)
4440Sstevel@tonic-gate 		str += 3; /* skip prefix */
4450Sstevel@tonic-gate 
4460Sstevel@tonic-gate 	return (str2sig(str, signum));
4470Sstevel@tonic-gate }
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate /*
4500Sstevel@tonic-gate  * Convert a string representation of a system call to the corresponding number.
4510Sstevel@tonic-gate  * We do this by performing a simple linear search of the table above.
4520Sstevel@tonic-gate  */
4530Sstevel@tonic-gate int
proc_str2sys(const char * str,int * sysnum)4540Sstevel@tonic-gate proc_str2sys(const char *str, int *sysnum)
4550Sstevel@tonic-gate {
4560Sstevel@tonic-gate 	char *next;
4570Sstevel@tonic-gate 	int i;
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate 	i = strtol(str, &next, 0);
4600Sstevel@tonic-gate 	if (i > 0 && i <= PRMAXSYS && *next == '\0') {
4610Sstevel@tonic-gate 		*sysnum = i;
4620Sstevel@tonic-gate 		return (0);
4630Sstevel@tonic-gate 	}
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 	for (i = 1; i < SYSEND; i++) {
4660Sstevel@tonic-gate 		if (systable[i] != NULL && strcmp(systable[i], str) == 0) {
4670Sstevel@tonic-gate 			*sysnum = i;
4680Sstevel@tonic-gate 			return (0);
4690Sstevel@tonic-gate 		}
4700Sstevel@tonic-gate 	}
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 	return (-1);
4730Sstevel@tonic-gate }
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate /*
4760Sstevel@tonic-gate  * Convert a fltset_t to a string representation consisting of canonical
4770Sstevel@tonic-gate  * machine fault names separated by the given delimeter string.  If
4780Sstevel@tonic-gate  * m is non-zero (TRUE), set members are printed.  If m is zero (FALSE), set
4790Sstevel@tonic-gate  * non-members are printed.  If the specified buf is too small to hold the
4800Sstevel@tonic-gate  * complete formatted set, NULL is returned; otherwise buf is returned.
4810Sstevel@tonic-gate  */
4820Sstevel@tonic-gate char *
proc_fltset2str(const fltset_t * set,const char * delim,int m,char * buf,size_t len)4830Sstevel@tonic-gate proc_fltset2str(const fltset_t *set, const char *delim, int m,
4840Sstevel@tonic-gate 	char *buf, size_t len)
4850Sstevel@tonic-gate {
4860Sstevel@tonic-gate 	char name[FLT2STR_MAX], *p = buf;
4870Sstevel@tonic-gate 	size_t n;
4880Sstevel@tonic-gate 	int i;
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
4910Sstevel@tonic-gate 		errno = EINVAL;
4920Sstevel@tonic-gate 		return (NULL);
4930Sstevel@tonic-gate 	}
4940Sstevel@tonic-gate 
4950Sstevel@tonic-gate 	buf[0] = '\0';  /* Set first byte to \0 */
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate 	for (i = 1; i <= PRMAXFAULT; i++) {
4980Sstevel@tonic-gate 		if ((prismember(set, i) != 0) ^ (m == 0)) {
4990Sstevel@tonic-gate 			(void) proc_fltname(i, name, sizeof (name));
5000Sstevel@tonic-gate 
5010Sstevel@tonic-gate 			if (buf[0] != '\0')
5020Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
5030Sstevel@tonic-gate 			else
5040Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate 			if (n != strlen(p)) {
5070Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
5080Sstevel@tonic-gate 				return (NULL);
5090Sstevel@tonic-gate 			}
5100Sstevel@tonic-gate 			len -= n;
5110Sstevel@tonic-gate 			p += n;
5120Sstevel@tonic-gate 		}
5130Sstevel@tonic-gate 	}
5140Sstevel@tonic-gate 	return (buf);
5150Sstevel@tonic-gate }
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate /*
5180Sstevel@tonic-gate  * Convert a sigset_t to a string representation consisting of canonical signal
5190Sstevel@tonic-gate  * names (without the SIG prefix). Parameters and return values analogous to
5200Sstevel@tonic-gate  * proc_fltset2str().
5210Sstevel@tonic-gate  */
5220Sstevel@tonic-gate char *
proc_sigset2str(const sigset_t * set,const char * delim,int m,char * buf,size_t len)5230Sstevel@tonic-gate proc_sigset2str(const sigset_t *set, const char *delim, int m,
5240Sstevel@tonic-gate 	char *buf, size_t len)
5250Sstevel@tonic-gate {
5260Sstevel@tonic-gate 	char name[SIG2STR_MAX], *p = buf;
5270Sstevel@tonic-gate 	size_t n;
5280Sstevel@tonic-gate 	int i;
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
5310Sstevel@tonic-gate 		errno = EINVAL;
5320Sstevel@tonic-gate 		return (NULL);
5330Sstevel@tonic-gate 	}
5340Sstevel@tonic-gate 
5350Sstevel@tonic-gate 	m = (m != 0);	/* Make sure m is 0 or 1 */
5360Sstevel@tonic-gate 	buf[0] = '\0';	/* Set first byte to \0 */
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate 	/*
5390Sstevel@tonic-gate 	 * Unlike proc_fltset2str() and proc_sysset2str(), we don't loop
5400Sstevel@tonic-gate 	 * until i <= NSIG here, because sigismember() rejects i == NSIG.
5410Sstevel@tonic-gate 	 */
5420Sstevel@tonic-gate 	for (i = 1; i < NSIG; i++) {
5430Sstevel@tonic-gate 		if (sigismember(set, i) == m) {
5440Sstevel@tonic-gate 			(void) sig2str(i, name);
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate 			if (buf[0] != '\0')
5470Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
5480Sstevel@tonic-gate 			else
5490Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
5500Sstevel@tonic-gate 
5510Sstevel@tonic-gate 			if (n != strlen(p)) {
5520Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
5530Sstevel@tonic-gate 				return (NULL);
5540Sstevel@tonic-gate 			}
5550Sstevel@tonic-gate 
5560Sstevel@tonic-gate 			len -= n;
5570Sstevel@tonic-gate 			p += n;
5580Sstevel@tonic-gate 		}
5590Sstevel@tonic-gate 	}
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate 	return (buf);
5620Sstevel@tonic-gate }
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate /*
5650Sstevel@tonic-gate  * Convert a sysset_t to a string representation consisting of canonical system
5660Sstevel@tonic-gate  * call names. Parameters and return values analogous to proc_fltset2str().
5670Sstevel@tonic-gate  */
5680Sstevel@tonic-gate char *
proc_sysset2str(const sysset_t * set,const char * delim,int m,char * buf,size_t len)5690Sstevel@tonic-gate proc_sysset2str(const sysset_t *set, const char *delim, int m,
5700Sstevel@tonic-gate 	char *buf, size_t len)
5710Sstevel@tonic-gate {
5720Sstevel@tonic-gate 	char name[SYS2STR_MAX], *p = buf;
5730Sstevel@tonic-gate 	size_t n;
5740Sstevel@tonic-gate 	int i;
5750Sstevel@tonic-gate 
5760Sstevel@tonic-gate 	if (buf == NULL || len < 1) {
5770Sstevel@tonic-gate 		errno = EINVAL;
5780Sstevel@tonic-gate 		return (NULL);
5790Sstevel@tonic-gate 	}
5800Sstevel@tonic-gate 
5810Sstevel@tonic-gate 	buf[0] = '\0';  /* Set first byte to \0 */
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate 	for (i = 1; i <= PRMAXSYS; i++) {
5840Sstevel@tonic-gate 		if ((prismember(set, i) != 0) ^ (m == 0)) {
5850Sstevel@tonic-gate 			(void) proc_sysname(i, name, sizeof (name));
5860Sstevel@tonic-gate 
5870Sstevel@tonic-gate 			if (buf[0] != '\0')
5880Sstevel@tonic-gate 				n = snprintf(p, len, "%s%s", delim, name);
5890Sstevel@tonic-gate 			else
5900Sstevel@tonic-gate 				n = snprintf(p, len, "%s", name);
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate 			if (n != strlen(p)) {
5930Sstevel@tonic-gate 				errno = ENAMETOOLONG; /* Output was truncated */
5940Sstevel@tonic-gate 				return (NULL);
5950Sstevel@tonic-gate 			}
5960Sstevel@tonic-gate 			len -= n;
5970Sstevel@tonic-gate 			p += n;
5980Sstevel@tonic-gate 		}
5990Sstevel@tonic-gate 	}
6000Sstevel@tonic-gate 	return (buf);
6010Sstevel@tonic-gate }
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate /*
6040Sstevel@tonic-gate  * Convert a string representation of a fault set (names separated by
6050Sstevel@tonic-gate  * one or more of the given delimeters) to a fltset_t.
6060Sstevel@tonic-gate  * If m is non-zero (TRUE), members of the string representation are set.
6070Sstevel@tonic-gate  * If m is zero (FALSE), non-members of the string representation are set.
6080Sstevel@tonic-gate  * This function returns NULL for success. Otherwise it returns a pointer
6090Sstevel@tonic-gate  * to the token of the string that couldn't be identified as a string
6100Sstevel@tonic-gate  * representation of a fault.
6110Sstevel@tonic-gate  */
6120Sstevel@tonic-gate char *
proc_str2fltset(const char * s,const char * delim,int m,fltset_t * set)6130Sstevel@tonic-gate proc_str2fltset(const char *s, const char *delim, int m, fltset_t *set)
6140Sstevel@tonic-gate {
615*13093SRoger.Faulkner@Oracle.COM 	char *p, *q, *t;
6160Sstevel@tonic-gate 	int flt;
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate 	if (m) {
6190Sstevel@tonic-gate 		premptyset(set);
6200Sstevel@tonic-gate 	} else {
6210Sstevel@tonic-gate 		prfillset(set);
6220Sstevel@tonic-gate 	}
6230Sstevel@tonic-gate 
624*13093SRoger.Faulkner@Oracle.COM 	t = strdupa(s);
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
6270Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
6280Sstevel@tonic-gate 		if (proc_str2flt(p, &flt) == -1) {
6290Sstevel@tonic-gate 			errno = EINVAL;
6300Sstevel@tonic-gate 			return ((char *)s + (p - t));
6310Sstevel@tonic-gate 		}
6320Sstevel@tonic-gate 		if (m)
6330Sstevel@tonic-gate 			praddset(set, flt);
6340Sstevel@tonic-gate 		else
6350Sstevel@tonic-gate 			prdelset(set, flt);
6360Sstevel@tonic-gate 	}
6370Sstevel@tonic-gate 	return (NULL);
6380Sstevel@tonic-gate }
6390Sstevel@tonic-gate 
6400Sstevel@tonic-gate /*
6410Sstevel@tonic-gate  * Convert a string representation of a signal set (names with or without the
6420Sstevel@tonic-gate  * SIG prefix separated by one or more of the given delimeters) to a sigset_t.
6430Sstevel@tonic-gate  * Parameters and return values analogous to proc_str2fltset().
6440Sstevel@tonic-gate  */
6450Sstevel@tonic-gate char *
proc_str2sigset(const char * s,const char * delim,int m,sigset_t * set)6460Sstevel@tonic-gate proc_str2sigset(const char *s, const char *delim, int m, sigset_t *set)
6470Sstevel@tonic-gate {
648*13093SRoger.Faulkner@Oracle.COM 	char *p, *q, *t;
6490Sstevel@tonic-gate 	int sig;
6500Sstevel@tonic-gate 
6510Sstevel@tonic-gate 	if (m) {
6520Sstevel@tonic-gate 		premptyset(set);
6530Sstevel@tonic-gate 	} else {
6540Sstevel@tonic-gate 		prfillset(set);
6550Sstevel@tonic-gate 	}
6560Sstevel@tonic-gate 
657*13093SRoger.Faulkner@Oracle.COM 	t = strdupa(s);
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
6600Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
6610Sstevel@tonic-gate 		if (proc_str2sig(p, &sig) == -1) {
6620Sstevel@tonic-gate 			errno = EINVAL;
6630Sstevel@tonic-gate 			return ((char *)s + (p - t));
6640Sstevel@tonic-gate 		}
6650Sstevel@tonic-gate 		if (m)
6660Sstevel@tonic-gate 			praddset(set, sig);
6670Sstevel@tonic-gate 		else
6680Sstevel@tonic-gate 			prdelset(set, sig);
6690Sstevel@tonic-gate 	}
6700Sstevel@tonic-gate 	return (NULL);
6710Sstevel@tonic-gate }
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate /*
6740Sstevel@tonic-gate  * Convert a string representation of a system call set (names separated by
6750Sstevel@tonic-gate  * one or more of the given delimeters) to a sysset_t. Parameters and return
6760Sstevel@tonic-gate  * values analogous to proc_str2fltset().
6770Sstevel@tonic-gate  */
6780Sstevel@tonic-gate char *
proc_str2sysset(const char * s,const char * delim,int m,sysset_t * set)6790Sstevel@tonic-gate proc_str2sysset(const char *s, const char *delim, int m, sysset_t *set)
6800Sstevel@tonic-gate {
681*13093SRoger.Faulkner@Oracle.COM 	char *p, *q, *t;
6820Sstevel@tonic-gate 	int sys;
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate 	if (m) {
6850Sstevel@tonic-gate 		premptyset(set);
6860Sstevel@tonic-gate 	} else {
6870Sstevel@tonic-gate 		prfillset(set);
6880Sstevel@tonic-gate 	}
6890Sstevel@tonic-gate 
690*13093SRoger.Faulkner@Oracle.COM 	t = strdupa(s);
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate 	for (p = strtok_r(t, delim, &q); p != NULL;
6930Sstevel@tonic-gate 	    p = strtok_r(NULL, delim, &q)) {
6940Sstevel@tonic-gate 		if (proc_str2sys(p, &sys) == -1) {
6950Sstevel@tonic-gate 			errno = EINVAL;
6960Sstevel@tonic-gate 			return ((char *)s + (p - t));
6970Sstevel@tonic-gate 		}
6980Sstevel@tonic-gate 		if (m)
6990Sstevel@tonic-gate 			praddset(set, sys);
7000Sstevel@tonic-gate 		else
7010Sstevel@tonic-gate 			prdelset(set, sys);
7020Sstevel@tonic-gate 	}
7030Sstevel@tonic-gate 	return (NULL);
7040Sstevel@tonic-gate }
705