xref: /illumos-gate/usr/src/cmd/truss/listopts.c (revision 6a634c9d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5657b1f3dSraf  * Common Development and Distribution License (the "License").
6657b1f3dSraf  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21657b1f3dSraf 
227c478bd9Sstevel@tonic-gate /*
23*794f0adbSRoger A. Faulkner  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <stdlib.h>
317c478bd9Sstevel@tonic-gate #include <unistd.h>
327c478bd9Sstevel@tonic-gate #include <ctype.h>
337c478bd9Sstevel@tonic-gate #include <string.h>
347c478bd9Sstevel@tonic-gate #include <memory.h>
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <signal.h>
377c478bd9Sstevel@tonic-gate #include <libproc.h>
387c478bd9Sstevel@tonic-gate #include "ramdata.h"
397c478bd9Sstevel@tonic-gate #include "systable.h"
407c478bd9Sstevel@tonic-gate #include "proto.h"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /* XXX A bug in the <string.h> header file requires this */
437c478bd9Sstevel@tonic-gate extern char *strtok_r(char *s1, const char *s2, char **lasts);
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * option procesing ---
477c478bd9Sstevel@tonic-gate  * Routines for scanning syscall, signal, fault
487c478bd9Sstevel@tonic-gate  * and file descriptor lists.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Function prototypes for static routines in this module.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate void	upcase(char *);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate const char white[] = " \t\n";	/* white space characters */
577c478bd9Sstevel@tonic-gate const char sepr[] = " ,\t\n";	/* list separator characters */
587c478bd9Sstevel@tonic-gate const char csepr[] = " :,\t\n";	/* same, with ':' added */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * Scan list of syscall names.
627c478bd9Sstevel@tonic-gate  * Return 0 on success, != 0 on any failure.
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate int
syslist(char * str,sysset_t * setp,int * fp)657c478bd9Sstevel@tonic-gate syslist(char *str,			/* string of syscall names */
667c478bd9Sstevel@tonic-gate 	sysset_t *setp,			/* syscall set */
677c478bd9Sstevel@tonic-gate 	int *fp)			/* first-time flag */
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate 	char *name;
707c478bd9Sstevel@tonic-gate 	int exclude = FALSE;
717c478bd9Sstevel@tonic-gate 	int rc = 0;
727c478bd9Sstevel@tonic-gate 	char *lasts;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	name = strtok_r(str, sepr, &lasts);
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	if (name != NULL && *name == '!') {	/* exclude from set */
777c478bd9Sstevel@tonic-gate 		exclude = TRUE;
787c478bd9Sstevel@tonic-gate 		if (*++name == '\0')
797c478bd9Sstevel@tonic-gate 			name = strtok_r(NULL, sepr, &lasts);
807c478bd9Sstevel@tonic-gate 	} else if (!*fp) {	/* first time, clear the set */
817c478bd9Sstevel@tonic-gate 		premptyset(setp);
827c478bd9Sstevel@tonic-gate 		*fp = TRUE;
837c478bd9Sstevel@tonic-gate 	}
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	for (; name; name = strtok_r(NULL, sepr, &lasts)) {
867c478bd9Sstevel@tonic-gate 		int sys;
877c478bd9Sstevel@tonic-gate 		int sysx;
88657b1f3dSraf 		int sysxx;
897c478bd9Sstevel@tonic-gate 		int sys64;
907c478bd9Sstevel@tonic-gate 		char *next;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 		if (*name == '!') {	/* exclude remainder from set */
937c478bd9Sstevel@tonic-gate 			exclude = TRUE;
947c478bd9Sstevel@tonic-gate 			while (*++name == '!')
957c478bd9Sstevel@tonic-gate 				/* empty */;
967c478bd9Sstevel@tonic-gate 			if (*name == '\0')
977c478bd9Sstevel@tonic-gate 				continue;
987c478bd9Sstevel@tonic-gate 		}
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 		sys = strtol(name, &next, 0);
101657b1f3dSraf 		sysx = sysxx = sys64 = 0;
1027c478bd9Sstevel@tonic-gate 		if (sys < 0 || sys > PRMAXSYS || *next != '\0')
1037c478bd9Sstevel@tonic-gate 			sys = 0;
1047c478bd9Sstevel@tonic-gate 		if (sys == 0) {
1057c478bd9Sstevel@tonic-gate 			const struct systable *stp = systable;
1067c478bd9Sstevel@tonic-gate 			for (; sys == 0 && stp->nargs >= 0; stp++)
1077c478bd9Sstevel@tonic-gate 				if (stp->name && strcmp(stp->name, name) == 0)
1087c478bd9Sstevel@tonic-gate 					sys = stp-systable;
1097c478bd9Sstevel@tonic-gate 		}
1107c478bd9Sstevel@tonic-gate 		if (sys == 0) {
1117c478bd9Sstevel@tonic-gate 			const struct sysalias *sap = sysalias;
1127c478bd9Sstevel@tonic-gate 			for (; sys == 0 && sap->name; sap++)
1137c478bd9Sstevel@tonic-gate 				if (strcmp(sap->name, name) == 0)
1147c478bd9Sstevel@tonic-gate 					sys = sap->number;
1157c478bd9Sstevel@tonic-gate 		}
1167c478bd9Sstevel@tonic-gate 		if (sys > 0 && sys <= PRMAXSYS) {
1177c478bd9Sstevel@tonic-gate 			switch (sys) {
1188fd04b83SRoger A. Faulkner 			case SYS_fstatat:	/* set both if either */
1198fd04b83SRoger A. Faulkner 			case SYS_fstatat64:
1208fd04b83SRoger A. Faulkner 				sys = SYS_fstatat;
1218fd04b83SRoger A. Faulkner 				sys64 = SYS_fstatat64;
1228fd04b83SRoger A. Faulkner 				goto def;
1238fd04b83SRoger A. Faulkner 
1248fd04b83SRoger A. Faulkner 			case SYS_stat:		/* set all if either */
1257c478bd9Sstevel@tonic-gate 			case SYS_stat64:
1267c478bd9Sstevel@tonic-gate 				sys = SYS_stat;
1277c478bd9Sstevel@tonic-gate 				sys64 = SYS_stat64;
1288fd04b83SRoger A. Faulkner 				sysx = SYS_fstatat;
1298fd04b83SRoger A. Faulkner 				sysxx = SYS_fstatat64;
1307c478bd9Sstevel@tonic-gate 				goto def;
1317c478bd9Sstevel@tonic-gate 
1328fd04b83SRoger A. Faulkner 			case SYS_lstat:		/* set all if either */
1337c478bd9Sstevel@tonic-gate 			case SYS_lstat64:
1347c478bd9Sstevel@tonic-gate 				sys = SYS_lstat;
1357c478bd9Sstevel@tonic-gate 				sys64 = SYS_lstat64;
1368fd04b83SRoger A. Faulkner 				sysx = SYS_fstatat;
1378fd04b83SRoger A. Faulkner 				sysxx = SYS_fstatat64;
1387c478bd9Sstevel@tonic-gate 				goto def;
1397c478bd9Sstevel@tonic-gate 
1408fd04b83SRoger A. Faulkner 			case SYS_fstat:		/* set all if either */
1417c478bd9Sstevel@tonic-gate 			case SYS_fstat64:
1427c478bd9Sstevel@tonic-gate 				sys = SYS_fstat;
1437c478bd9Sstevel@tonic-gate 				sys64 = SYS_fstat64;
1448fd04b83SRoger A. Faulkner 				sysx = SYS_fstatat;
1458fd04b83SRoger A. Faulkner 				sysxx = SYS_fstatat64;
1467c478bd9Sstevel@tonic-gate 				goto def;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 			case SYS_getdents:	/* set both if either */
1497c478bd9Sstevel@tonic-gate 			case SYS_getdents64:
1507c478bd9Sstevel@tonic-gate 				sys = SYS_getdents;
1517c478bd9Sstevel@tonic-gate 				sys64 = SYS_getdents64;
1527c478bd9Sstevel@tonic-gate 				goto def;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 			case SYS_mmap:		/* set both if either */
1557c478bd9Sstevel@tonic-gate 			case SYS_mmap64:
1567c478bd9Sstevel@tonic-gate 				sys = SYS_mmap;
1577c478bd9Sstevel@tonic-gate 				sys64 = SYS_mmap64;
1587c478bd9Sstevel@tonic-gate 				goto def;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 			case SYS_statvfs:	/* set both if either */
1617c478bd9Sstevel@tonic-gate 			case SYS_statvfs64:
1627c478bd9Sstevel@tonic-gate 				sys = SYS_statvfs;
1637c478bd9Sstevel@tonic-gate 				sys64 = SYS_statvfs64;
1647c478bd9Sstevel@tonic-gate 				goto def;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 			case SYS_fstatvfs:	/* set both if either */
1677c478bd9Sstevel@tonic-gate 			case SYS_fstatvfs64:
1687c478bd9Sstevel@tonic-gate 				sys = SYS_fstatvfs;
1697c478bd9Sstevel@tonic-gate 				sys64 = SYS_fstatvfs64;
1707c478bd9Sstevel@tonic-gate 				goto def;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 			case SYS_setrlimit:	/* set both if either */
1737c478bd9Sstevel@tonic-gate 			case SYS_setrlimit64:
1747c478bd9Sstevel@tonic-gate 				sys = SYS_setrlimit;
1757c478bd9Sstevel@tonic-gate 				sys64 = SYS_setrlimit64;
1767c478bd9Sstevel@tonic-gate 				goto def;
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 			case SYS_getrlimit:	/* set both if either */
1797c478bd9Sstevel@tonic-gate 			case SYS_getrlimit64:
1807c478bd9Sstevel@tonic-gate 				sys = SYS_getrlimit;
1817c478bd9Sstevel@tonic-gate 				sys64 = SYS_getrlimit64;
1827c478bd9Sstevel@tonic-gate 				goto def;
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 			case SYS_pread:		/* set both if either */
1857c478bd9Sstevel@tonic-gate 			case SYS_pread64:
1867c478bd9Sstevel@tonic-gate 				sys = SYS_pread;
1877c478bd9Sstevel@tonic-gate 				sys64 = SYS_pread64;
1887c478bd9Sstevel@tonic-gate 				goto def;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 			case SYS_pwrite:	/* set both if either */
1917c478bd9Sstevel@tonic-gate 			case SYS_pwrite64:
1927c478bd9Sstevel@tonic-gate 				sys = SYS_pwrite;
1937c478bd9Sstevel@tonic-gate 				sys64 = SYS_pwrite64;
1947c478bd9Sstevel@tonic-gate 				goto def;
1957c478bd9Sstevel@tonic-gate 
1968fd04b83SRoger A. Faulkner 			case SYS_openat:	/* set all if any */
1978fd04b83SRoger A. Faulkner 			case SYS_openat64:
1988fd04b83SRoger A. Faulkner 			case SYS_open:
1997c478bd9Sstevel@tonic-gate 			case SYS_open64:
2008fd04b83SRoger A. Faulkner 				sys = SYS_openat;
2018fd04b83SRoger A. Faulkner 				sys64 = SYS_openat64;
2028fd04b83SRoger A. Faulkner 				sysx = SYS_open;
2038fd04b83SRoger A. Faulkner 				sysxx = SYS_open64;
2047c478bd9Sstevel@tonic-gate 				goto def;
2057c478bd9Sstevel@tonic-gate 
2068fd04b83SRoger A. Faulkner 			case SYS_forksys:	/* set both if either */
2077c478bd9Sstevel@tonic-gate 			case SYS_vfork:
2088fd04b83SRoger A. Faulkner 				sysx = SYS_forksys;
2098fd04b83SRoger A. Faulkner 				sys = SYS_vfork;
2107c478bd9Sstevel@tonic-gate 				goto def;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 			case SYS_sigprocmask:	/* set both if either */
2137c478bd9Sstevel@tonic-gate 			case SYS_lwp_sigmask:
2147c478bd9Sstevel@tonic-gate 				sysx = SYS_sigprocmask;
2157c478bd9Sstevel@tonic-gate 				sys = SYS_lwp_sigmask;
2167c478bd9Sstevel@tonic-gate 				goto def;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 			case SYS_lseek:		/* set both if either */
2197c478bd9Sstevel@tonic-gate 			case SYS_llseek:
2207c478bd9Sstevel@tonic-gate 				sysx = SYS_lseek;
2217c478bd9Sstevel@tonic-gate 				sys = SYS_llseek;
2227c478bd9Sstevel@tonic-gate 				goto def;
2237c478bd9Sstevel@tonic-gate 
2248fd04b83SRoger A. Faulkner 			case SYS_rename:	/* set both */
2258fd04b83SRoger A. Faulkner 				sysx = SYS_renameat;
2268fd04b83SRoger A. Faulkner 				goto def;
2278fd04b83SRoger A. Faulkner 
228*794f0adbSRoger A. Faulkner 			case SYS_link:		/* set both */
229*794f0adbSRoger A. Faulkner 				sysx = SYS_linkat;
2308fd04b83SRoger A. Faulkner 				goto def;
2318fd04b83SRoger A. Faulkner 
232*794f0adbSRoger A. Faulkner 			case SYS_unlink:	/* set both */
2338fd04b83SRoger A. Faulkner 			case SYS_rmdir:		/* set both */
2348fd04b83SRoger A. Faulkner 				sysx = SYS_unlinkat;
2358fd04b83SRoger A. Faulkner 				goto def;
2368fd04b83SRoger A. Faulkner 
237*794f0adbSRoger A. Faulkner 			case SYS_symlink:	/* set both */
238*794f0adbSRoger A. Faulkner 				sysx = SYS_symlinkat;
2398fd04b83SRoger A. Faulkner 				goto def;
2408fd04b83SRoger A. Faulkner 
241*794f0adbSRoger A. Faulkner 			case SYS_readlink:	/* set both */
242*794f0adbSRoger A. Faulkner 				sysx = SYS_readlinkat;
2438fd04b83SRoger A. Faulkner 				goto def;
2448fd04b83SRoger A. Faulkner 
245*794f0adbSRoger A. Faulkner 			case SYS_chmod:		/* set both */
246*794f0adbSRoger A. Faulkner 			case SYS_fchmod:	/* set both */
247*794f0adbSRoger A. Faulkner 				sysx = SYS_fchmodat;
248*794f0adbSRoger A. Faulkner 				goto def;
249*794f0adbSRoger A. Faulkner 
250*794f0adbSRoger A. Faulkner 			case SYS_chown:		/* set both */
251*794f0adbSRoger A. Faulkner 			case SYS_lchown:	/* set both */
2528fd04b83SRoger A. Faulkner 			case SYS_fchown:	/* set both */
2538fd04b83SRoger A. Faulkner 				sysx = SYS_fchownat;
2547c478bd9Sstevel@tonic-gate 				goto def;
2557c478bd9Sstevel@tonic-gate 
256*794f0adbSRoger A. Faulkner 			case SYS_mkdir:		/* set both */
257*794f0adbSRoger A. Faulkner 				sysx = SYS_mkdirat;
258*794f0adbSRoger A. Faulkner 				goto def;
259*794f0adbSRoger A. Faulkner 
260*794f0adbSRoger A. Faulkner 			case SYS_mknod:		/* set both */
261*794f0adbSRoger A. Faulkner 				sysx = SYS_mknodat;
262*794f0adbSRoger A. Faulkner 				goto def;
263*794f0adbSRoger A. Faulkner 
2648fd04b83SRoger A. Faulkner 			case SYS_access:	/* set both */
2658fd04b83SRoger A. Faulkner 				sysx = SYS_faccessat;
2667c478bd9Sstevel@tonic-gate 				goto def;
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 			default:
2697c478bd9Sstevel@tonic-gate 			def:
2707c478bd9Sstevel@tonic-gate 				if (exclude) {
2717c478bd9Sstevel@tonic-gate 					prdelset(setp, sys);
2727c478bd9Sstevel@tonic-gate 					if (sysx)
2737c478bd9Sstevel@tonic-gate 						prdelset(setp, sysx);
274657b1f3dSraf 					if (sysxx)
275657b1f3dSraf 						prdelset(setp, sysxx);
2767c478bd9Sstevel@tonic-gate 					if (sys64)
2777c478bd9Sstevel@tonic-gate 						prdelset(setp, sys64);
2787c478bd9Sstevel@tonic-gate 				} else {
2797c478bd9Sstevel@tonic-gate 					praddset(setp, sys);
2807c478bd9Sstevel@tonic-gate 					if (sysx)
2817c478bd9Sstevel@tonic-gate 						praddset(setp, sysx);
282657b1f3dSraf 					if (sysxx)
283657b1f3dSraf 						praddset(setp, sysxx);
2847c478bd9Sstevel@tonic-gate 					if (sys64)
2857c478bd9Sstevel@tonic-gate 						praddset(setp, sys64);
2867c478bd9Sstevel@tonic-gate 				}
2877c478bd9Sstevel@tonic-gate 				break;
2887c478bd9Sstevel@tonic-gate 			}
2897c478bd9Sstevel@tonic-gate 		} else if (strcmp(name, "all") == 0 ||
2907c478bd9Sstevel@tonic-gate 		    strcmp(name, "ALL") == 0) {
2917c478bd9Sstevel@tonic-gate 			if (exclude) {
2927c478bd9Sstevel@tonic-gate 				premptyset(setp);
2937c478bd9Sstevel@tonic-gate 			} else {
2947c478bd9Sstevel@tonic-gate 				prfillset(setp);
2957c478bd9Sstevel@tonic-gate 			}
2967c478bd9Sstevel@tonic-gate 		} else {
2977c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
298a574db85Sraf 			    "%s: unrecognized syscall: %s\n",
299a574db85Sraf 			    command, name);
3007c478bd9Sstevel@tonic-gate 			rc = -1;
3017c478bd9Sstevel@tonic-gate 		}
3027c478bd9Sstevel@tonic-gate 	}
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	return (rc);
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate  * List of signals to trace.
3097c478bd9Sstevel@tonic-gate  * Return 0 on success, != 0 on any failure.
3107c478bd9Sstevel@tonic-gate  */
3117c478bd9Sstevel@tonic-gate int
siglist(private_t * pri,char * str,sigset_t * setp,int * fp)3127c478bd9Sstevel@tonic-gate siglist(private_t *pri,
3137c478bd9Sstevel@tonic-gate 	char *str,			/* string of signal names */
3147c478bd9Sstevel@tonic-gate 	sigset_t *setp,			/* signal set */
3157c478bd9Sstevel@tonic-gate 	int *fp)			/* first-time flag */
3167c478bd9Sstevel@tonic-gate {
3177c478bd9Sstevel@tonic-gate 	char *name;
3187c478bd9Sstevel@tonic-gate 	int exclude = FALSE;
3197c478bd9Sstevel@tonic-gate 	int rc = 0;
3207c478bd9Sstevel@tonic-gate 	char *lasts;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	upcase(str);
3237c478bd9Sstevel@tonic-gate 	name = strtok_r(str, sepr, &lasts);
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	if (name != NULL && *name == '!') {	/* exclude from set */
3267c478bd9Sstevel@tonic-gate 		exclude = TRUE;
3277c478bd9Sstevel@tonic-gate 		if (*++name == '\0')
3287c478bd9Sstevel@tonic-gate 			name = strtok_r(NULL, sepr, &lasts);
3297c478bd9Sstevel@tonic-gate 	} else if (!*fp) {	/* first time, clear the set */
3307c478bd9Sstevel@tonic-gate 		premptyset(setp);
3317c478bd9Sstevel@tonic-gate 		*fp = TRUE;
3327c478bd9Sstevel@tonic-gate 	}
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	for (; name; name = strtok_r(NULL, sepr, &lasts)) {
3357c478bd9Sstevel@tonic-gate 		int sig;
3367c478bd9Sstevel@tonic-gate 		char *next;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 		if (*name == '!') {	/* exclude remainder from set */
3397c478bd9Sstevel@tonic-gate 			exclude = TRUE;
3407c478bd9Sstevel@tonic-gate 			while (*++name == '!')
3417c478bd9Sstevel@tonic-gate 				/* empty */;
3427c478bd9Sstevel@tonic-gate 			if (*name == '\0')
3437c478bd9Sstevel@tonic-gate 				continue;
3447c478bd9Sstevel@tonic-gate 		}
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 		sig = strtol(name, &next, 0);
3477c478bd9Sstevel@tonic-gate 		if (sig <= 0 || sig > PRMAXSIG || *next != '\0') {
3487c478bd9Sstevel@tonic-gate 			for (sig = 1; sig <= PRMAXSIG; sig++) {
3497c478bd9Sstevel@tonic-gate 				const char *sname = rawsigname(pri, sig);
3507c478bd9Sstevel@tonic-gate 				if (sname == NULL)
3517c478bd9Sstevel@tonic-gate 					continue;
3527c478bd9Sstevel@tonic-gate 				if (strcmp(sname, name) == 0 ||
3537c478bd9Sstevel@tonic-gate 				    strcmp(sname+3, name) == 0)
3547c478bd9Sstevel@tonic-gate 					break;
3557c478bd9Sstevel@tonic-gate 			}
3567c478bd9Sstevel@tonic-gate 			if (sig > PRMAXSIG)
3577c478bd9Sstevel@tonic-gate 				sig = 0;
3587c478bd9Sstevel@tonic-gate 		}
3597c478bd9Sstevel@tonic-gate 		if (sig > 0 && sig <= PRMAXSIG) {
3607c478bd9Sstevel@tonic-gate 			if (exclude) {
3617c478bd9Sstevel@tonic-gate 				prdelset(setp, sig);
3627c478bd9Sstevel@tonic-gate 			} else {
3637c478bd9Sstevel@tonic-gate 				praddset(setp, sig);
3647c478bd9Sstevel@tonic-gate 			}
3657c478bd9Sstevel@tonic-gate 		} else if (strcmp(name, "ALL") == 0) {
3667c478bd9Sstevel@tonic-gate 			if (exclude) {
3677c478bd9Sstevel@tonic-gate 				premptyset(setp);
3687c478bd9Sstevel@tonic-gate 			} else {
3697c478bd9Sstevel@tonic-gate 				prfillset(setp);
3707c478bd9Sstevel@tonic-gate 			}
3717c478bd9Sstevel@tonic-gate 		} else {
3727c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
373a574db85Sraf 			    "%s: unrecognized signal name/number: %s\n",
374a574db85Sraf 			    command, name);
3757c478bd9Sstevel@tonic-gate 			rc = -1;
3767c478bd9Sstevel@tonic-gate 		}
3777c478bd9Sstevel@tonic-gate 	}
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate 	return (rc);
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate /*
3837c478bd9Sstevel@tonic-gate  * List of faults to trace.
3847c478bd9Sstevel@tonic-gate  * return 0 on success, != 0 on any failure.
3857c478bd9Sstevel@tonic-gate  */
3867c478bd9Sstevel@tonic-gate int
fltlist(char * str,fltset_t * setp,int * fp)3877c478bd9Sstevel@tonic-gate fltlist(char *str,			/* string of fault names */
3887c478bd9Sstevel@tonic-gate 	fltset_t *setp,			/* fault set */
3897c478bd9Sstevel@tonic-gate 	int *fp)			/* first-time flag */
3907c478bd9Sstevel@tonic-gate {
3917c478bd9Sstevel@tonic-gate 	char *name;
3927c478bd9Sstevel@tonic-gate 	int exclude = FALSE;
3937c478bd9Sstevel@tonic-gate 	int rc = 0;
3947c478bd9Sstevel@tonic-gate 	char *lasts;
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	upcase(str);
3977c478bd9Sstevel@tonic-gate 	name = strtok_r(str, sepr, &lasts);
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	if (name != NULL && *name == '!') {	/* exclude from set */
4007c478bd9Sstevel@tonic-gate 		exclude = TRUE;
4017c478bd9Sstevel@tonic-gate 		if (*++name == '\0')
4027c478bd9Sstevel@tonic-gate 			name = strtok_r(NULL, sepr, &lasts);
4037c478bd9Sstevel@tonic-gate 	} else if (!*fp) {	/* first time, clear the set */
4047c478bd9Sstevel@tonic-gate 		premptyset(setp);
4057c478bd9Sstevel@tonic-gate 		*fp = TRUE;
4067c478bd9Sstevel@tonic-gate 	}
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	for (; name; name = strtok_r(NULL, sepr, &lasts)) {
4097c478bd9Sstevel@tonic-gate 		int flt;
4107c478bd9Sstevel@tonic-gate 		char *next;
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 		if (*name == '!') {	/* exclude remainder from set */
4137c478bd9Sstevel@tonic-gate 			exclude = TRUE;
4147c478bd9Sstevel@tonic-gate 			while (*++name == '!')
4157c478bd9Sstevel@tonic-gate 				/* empty */;
4167c478bd9Sstevel@tonic-gate 			if (*name == '\0')
4177c478bd9Sstevel@tonic-gate 				continue;
4187c478bd9Sstevel@tonic-gate 		}
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 		flt = strtol(name, &next, 0);
4217c478bd9Sstevel@tonic-gate 		if (flt <= 0 || flt > PRMAXFAULT || *next != '\0') {
4227c478bd9Sstevel@tonic-gate 			for (flt = 1; flt <= PRMAXFAULT; flt++) {
4237c478bd9Sstevel@tonic-gate 				char fname[32];
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate 				if (proc_fltname(flt, fname,
4267c478bd9Sstevel@tonic-gate 				    sizeof (fname)) == NULL)
4277c478bd9Sstevel@tonic-gate 					continue;
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 				if (strcmp(fname, name) == 0 ||
4307c478bd9Sstevel@tonic-gate 				    strcmp(fname+3, name) == 0)
4317c478bd9Sstevel@tonic-gate 					break;
4327c478bd9Sstevel@tonic-gate 			}
4337c478bd9Sstevel@tonic-gate 			if (flt > PRMAXFAULT)
4347c478bd9Sstevel@tonic-gate 				flt = 0;
4357c478bd9Sstevel@tonic-gate 		}
4367c478bd9Sstevel@tonic-gate 		if (flt > 0 && flt <= PRMAXFAULT) {
4377c478bd9Sstevel@tonic-gate 			if (exclude) {
4387c478bd9Sstevel@tonic-gate 				prdelset(setp, flt);
4397c478bd9Sstevel@tonic-gate 			} else {
4407c478bd9Sstevel@tonic-gate 				praddset(setp, flt);
4417c478bd9Sstevel@tonic-gate 			}
4427c478bd9Sstevel@tonic-gate 		} else if (strcmp(name, "ALL") == 0) {
4437c478bd9Sstevel@tonic-gate 			if (exclude) {
4447c478bd9Sstevel@tonic-gate 				premptyset(setp);
4457c478bd9Sstevel@tonic-gate 			} else {
4467c478bd9Sstevel@tonic-gate 				prfillset(setp);
4477c478bd9Sstevel@tonic-gate 			}
4487c478bd9Sstevel@tonic-gate 		} else {
4497c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
450a574db85Sraf 			    "%s: unrecognized fault name/number: %s\n",
451a574db85Sraf 			    command, name);
4527c478bd9Sstevel@tonic-gate 			rc = -1;
4537c478bd9Sstevel@tonic-gate 		}
4547c478bd9Sstevel@tonic-gate 	}
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	return (rc);
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate /*
4607c478bd9Sstevel@tonic-gate  * Gather file descriptors to dump.
4617c478bd9Sstevel@tonic-gate  * Return 0 on success, != 0 on any failure.
4627c478bd9Sstevel@tonic-gate  */
4637c478bd9Sstevel@tonic-gate int
fdlist(char * str,fileset_t * setp)4647c478bd9Sstevel@tonic-gate fdlist(char *str,		/* string of filedescriptors */
4657c478bd9Sstevel@tonic-gate 	fileset_t *setp)	/* set of boolean flags */
4667c478bd9Sstevel@tonic-gate {
4677c478bd9Sstevel@tonic-gate 	char *name;
4687c478bd9Sstevel@tonic-gate 	int exclude = FALSE;
4697c478bd9Sstevel@tonic-gate 	int rc = 0;
4707c478bd9Sstevel@tonic-gate 	char *lasts;
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	upcase(str);
4737c478bd9Sstevel@tonic-gate 	name = strtok_r(str, sepr, &lasts);
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate 	if (name != NULL && *name == '!') {	/* exclude from set */
4767c478bd9Sstevel@tonic-gate 		exclude = TRUE;
4777c478bd9Sstevel@tonic-gate 		if (*++name == '\0')
4787c478bd9Sstevel@tonic-gate 			name = strtok_r(NULL, sepr, &lasts);
4797c478bd9Sstevel@tonic-gate 	}
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 	for (; name; name = strtok_r(NULL, sepr, &lasts)) {
4827c478bd9Sstevel@tonic-gate 		int fd;
4837c478bd9Sstevel@tonic-gate 		char *next;
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 		if (*name == '!') {	/* exclude remainder from set */
4867c478bd9Sstevel@tonic-gate 			exclude = TRUE;
4877c478bd9Sstevel@tonic-gate 			while (*++name == '!')
4887c478bd9Sstevel@tonic-gate 				/* empty */;
4897c478bd9Sstevel@tonic-gate 			if (*name == '\0')
4907c478bd9Sstevel@tonic-gate 				continue;
4917c478bd9Sstevel@tonic-gate 		}
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 		fd = strtol(name, &next, 0);
4947c478bd9Sstevel@tonic-gate 		if (fd >= 0 && fd < NOFILES_MAX && *next == '\0') {
4957c478bd9Sstevel@tonic-gate 			fd++;
4967c478bd9Sstevel@tonic-gate 			if (exclude) {
4977c478bd9Sstevel@tonic-gate 				prdelset(setp, fd);
4987c478bd9Sstevel@tonic-gate 			} else {
4997c478bd9Sstevel@tonic-gate 				praddset(setp, fd);
5007c478bd9Sstevel@tonic-gate 			}
5017c478bd9Sstevel@tonic-gate 		} else if (strcmp(name, "ALL") == 0) {
5027c478bd9Sstevel@tonic-gate 			if (exclude) {
5037c478bd9Sstevel@tonic-gate 				premptyset(setp);
5047c478bd9Sstevel@tonic-gate 			} else {
5057c478bd9Sstevel@tonic-gate 				prfillset(setp);
5067c478bd9Sstevel@tonic-gate 			}
5077c478bd9Sstevel@tonic-gate 		} else {
5087c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr,
509a574db85Sraf 			    "%s: filedescriptor not in range[0..%d]: %s\n",
510a574db85Sraf 			    command, NOFILES_MAX-1, name);
5117c478bd9Sstevel@tonic-gate 			rc = -1;
5127c478bd9Sstevel@tonic-gate 		}
5137c478bd9Sstevel@tonic-gate 	}
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	return (rc);
5167c478bd9Sstevel@tonic-gate }
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate void
upcase(char * str)5197c478bd9Sstevel@tonic-gate upcase(char *str)
5207c478bd9Sstevel@tonic-gate {
5217c478bd9Sstevel@tonic-gate 	int c;
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	while ((c = *str) != '\0')
5247c478bd9Sstevel@tonic-gate 		*str++ = toupper(c);
5257c478bd9Sstevel@tonic-gate }
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate /*
5287c478bd9Sstevel@tonic-gate  * 'arg' points to a string like:
5297c478bd9Sstevel@tonic-gate  *	libc,libnsl,... : printf,read,write,...
5307c478bd9Sstevel@tonic-gate  * or
5317c478bd9Sstevel@tonic-gate  *	libc,libnsl,... :: printf,read,write,...
5327c478bd9Sstevel@tonic-gate  * with possible filename pattern-matching metacharacters.
5337c478bd9Sstevel@tonic-gate  *
5347c478bd9Sstevel@tonic-gate  * Assumption:  No library or function name can contain ',' or ':'.
5357c478bd9Sstevel@tonic-gate  */
5367c478bd9Sstevel@tonic-gate int
liblist(char * arg,int hang)5377c478bd9Sstevel@tonic-gate liblist(char *arg, int hang)
5387c478bd9Sstevel@tonic-gate {
5397c478bd9Sstevel@tonic-gate 	const char *star = "*";
5407c478bd9Sstevel@tonic-gate 	struct dynpat *Dyp;
5417c478bd9Sstevel@tonic-gate 	char *pat;
5427c478bd9Sstevel@tonic-gate 	char *fpat;
5437c478bd9Sstevel@tonic-gate 	char *lasts;
5447c478bd9Sstevel@tonic-gate 	uint_t maxpat;
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	/* append a new dynpat structure to the end of the Dynpat list */
5477c478bd9Sstevel@tonic-gate 	Dyp = my_malloc(sizeof (struct dynpat), NULL);
5487c478bd9Sstevel@tonic-gate 	Dyp->next = NULL;
5497c478bd9Sstevel@tonic-gate 	if (Lastpat == NULL)
5507c478bd9Sstevel@tonic-gate 		Dynpat = Lastpat = Dyp;
5517c478bd9Sstevel@tonic-gate 	else {
5527c478bd9Sstevel@tonic-gate 		Lastpat->next = Dyp;
5537c478bd9Sstevel@tonic-gate 		Lastpat = Dyp;
5547c478bd9Sstevel@tonic-gate 	}
5557c478bd9Sstevel@tonic-gate 	Dyp->flag = hang? BPT_HANG : 0;
5567c478bd9Sstevel@tonic-gate 	Dyp->exclude_lib = 0;
5577c478bd9Sstevel@tonic-gate 	Dyp->exclude = 0;
5587c478bd9Sstevel@tonic-gate 	Dyp->internal = 0;
5597c478bd9Sstevel@tonic-gate 	Dyp->Dp = NULL;
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	/*
5627c478bd9Sstevel@tonic-gate 	 * Find the beginning of the filename patterns
5637c478bd9Sstevel@tonic-gate 	 * and null-terminate the library name patterns.
5647c478bd9Sstevel@tonic-gate 	 */
5657c478bd9Sstevel@tonic-gate 	if ((fpat = strchr(arg, ':')) != NULL)
5667c478bd9Sstevel@tonic-gate 		*fpat++ = '\0';
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	/*
5697c478bd9Sstevel@tonic-gate 	 * Library name patterns.
5707c478bd9Sstevel@tonic-gate 	 */
5717c478bd9Sstevel@tonic-gate 	pat = strtok_r(arg, sepr, &lasts);
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate 	/* '!' introduces an exclusion list */
5747c478bd9Sstevel@tonic-gate 	if (pat != NULL && *pat == '!') {
5757c478bd9Sstevel@tonic-gate 		Dyp->exclude_lib = 1;
5767c478bd9Sstevel@tonic-gate 		pat += strspn(pat, "!");
5777c478bd9Sstevel@tonic-gate 		if (*pat == '\0')
5787c478bd9Sstevel@tonic-gate 			pat = strtok_r(NULL, sepr, &lasts);
5797c478bd9Sstevel@tonic-gate 		/* force exclusion of all functions as well */
5807c478bd9Sstevel@tonic-gate 		Dyp->exclude = 1;
5817c478bd9Sstevel@tonic-gate 		Dyp->internal = 1;
5827c478bd9Sstevel@tonic-gate 		fpat = NULL;
5837c478bd9Sstevel@tonic-gate 	}
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate 	if (pat == NULL) {
5867c478bd9Sstevel@tonic-gate 		/* empty list means all libraries */
5877c478bd9Sstevel@tonic-gate 		Dyp->libpat = my_malloc(sizeof (char *), NULL);
5887c478bd9Sstevel@tonic-gate 		Dyp->libpat[0] = star;
5897c478bd9Sstevel@tonic-gate 		Dyp->nlibpat = 1;
5907c478bd9Sstevel@tonic-gate 	} else {
5917c478bd9Sstevel@tonic-gate 		/*
5927c478bd9Sstevel@tonic-gate 		 * We are now at the library list.
5937c478bd9Sstevel@tonic-gate 		 * Generate the list and count the library name patterns.
5947c478bd9Sstevel@tonic-gate 		 */
5957c478bd9Sstevel@tonic-gate 		maxpat = 1;
5967c478bd9Sstevel@tonic-gate 		Dyp->libpat = my_malloc(maxpat * sizeof (char *), NULL);
5977c478bd9Sstevel@tonic-gate 		Dyp->nlibpat = 0;
5987c478bd9Sstevel@tonic-gate 		Dyp->libpat[Dyp->nlibpat++] = pat;
5997c478bd9Sstevel@tonic-gate 		while ((pat = strtok_r(NULL, sepr, &lasts)) != NULL) {
6007c478bd9Sstevel@tonic-gate 			if (Dyp->nlibpat == maxpat) {
6017c478bd9Sstevel@tonic-gate 				maxpat *= 2;
6027c478bd9Sstevel@tonic-gate 				Dyp->libpat = my_realloc(Dyp->libpat,
603a574db85Sraf 				    maxpat * sizeof (char *), NULL);
6047c478bd9Sstevel@tonic-gate 			}
6057c478bd9Sstevel@tonic-gate 			Dyp->libpat[Dyp->nlibpat++] = pat;
6067c478bd9Sstevel@tonic-gate 		}
6077c478bd9Sstevel@tonic-gate 	}
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	/*
6107c478bd9Sstevel@tonic-gate 	 * Function name patterns.
6117c478bd9Sstevel@tonic-gate 	 */
6127c478bd9Sstevel@tonic-gate 	if (fpat == NULL)
6137c478bd9Sstevel@tonic-gate 		pat = NULL;
6147c478bd9Sstevel@tonic-gate 	else {
6157c478bd9Sstevel@tonic-gate 		/*
6167c478bd9Sstevel@tonic-gate 		 * We have already seen a ':'.  Look for another.
6177c478bd9Sstevel@tonic-gate 		 * Double ':' means trace internal calls.
6187c478bd9Sstevel@tonic-gate 		 */
6197c478bd9Sstevel@tonic-gate 		fpat += strspn(fpat, white);
6207c478bd9Sstevel@tonic-gate 		if (*fpat == ':') {
6217c478bd9Sstevel@tonic-gate 			Dyp->internal = 1;
6227c478bd9Sstevel@tonic-gate 			*fpat++ = '\0';
6237c478bd9Sstevel@tonic-gate 		}
6247c478bd9Sstevel@tonic-gate 		pat = strtok_r(fpat, csepr, &lasts);
6257c478bd9Sstevel@tonic-gate 	}
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate 	/* '!' introduces an exclusion list */
6287c478bd9Sstevel@tonic-gate 	if (pat != NULL && *pat == '!') {
6297c478bd9Sstevel@tonic-gate 		Dyp->exclude = 1;
6307c478bd9Sstevel@tonic-gate 		Dyp->internal = 1;
6317c478bd9Sstevel@tonic-gate 		pat += strspn(pat, "!");
6327c478bd9Sstevel@tonic-gate 		if (*pat == '\0')
6337c478bd9Sstevel@tonic-gate 			pat = strtok_r(NULL, sepr, &lasts);
6347c478bd9Sstevel@tonic-gate 	}
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate 	if (pat == NULL) {
6377c478bd9Sstevel@tonic-gate 		/* empty function list means exclude all functions */
6387c478bd9Sstevel@tonic-gate 		Dyp->sympat = my_malloc(sizeof (char *), NULL);
6397c478bd9Sstevel@tonic-gate 		Dyp->sympat[0] = star;
6407c478bd9Sstevel@tonic-gate 		Dyp->nsympat = 1;
6417c478bd9Sstevel@tonic-gate 	} else {
6427c478bd9Sstevel@tonic-gate 		/*
6437c478bd9Sstevel@tonic-gate 		 * We are now at the function list.
6447c478bd9Sstevel@tonic-gate 		 * Generate the list and count the symbol name patterns.
6457c478bd9Sstevel@tonic-gate 		 */
6467c478bd9Sstevel@tonic-gate 		maxpat = 1;
6477c478bd9Sstevel@tonic-gate 		Dyp->sympat = my_malloc(maxpat * sizeof (char *), NULL);
6487c478bd9Sstevel@tonic-gate 		Dyp->nsympat = 0;
6497c478bd9Sstevel@tonic-gate 		Dyp->sympat[Dyp->nsympat++] = pat;
6507c478bd9Sstevel@tonic-gate 		while ((pat = strtok_r(NULL, sepr, &lasts)) != NULL) {
6517c478bd9Sstevel@tonic-gate 			if (Dyp->nsympat == maxpat) {
6527c478bd9Sstevel@tonic-gate 				maxpat *= 2;
6537c478bd9Sstevel@tonic-gate 				Dyp->sympat = my_realloc(Dyp->sympat,
654a574db85Sraf 				    maxpat * sizeof (char *), NULL);
6557c478bd9Sstevel@tonic-gate 			}
6567c478bd9Sstevel@tonic-gate 			Dyp->sympat[Dyp->nsympat++] = pat;
6577c478bd9Sstevel@tonic-gate 		}
6587c478bd9Sstevel@tonic-gate 	}
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	return (0);
6617c478bd9Sstevel@tonic-gate }
662