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
56812Sraf * Common Development and Distribution License (the "License").
66812Sraf * 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 */
216812Sraf
220Sstevel@tonic-gate /*
23*11913SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
306812Sraf #include "lint.h"
310Sstevel@tonic-gate #include <string.h>
320Sstevel@tonic-gate #include <stdlib.h>
330Sstevel@tonic-gate #include <signal.h>
340Sstevel@tonic-gate #include <sys/types.h>
350Sstevel@tonic-gate #include <errno.h>
360Sstevel@tonic-gate
370Sstevel@tonic-gate typedef struct signame {
380Sstevel@tonic-gate const char *sigstr;
390Sstevel@tonic-gate const int signum;
400Sstevel@tonic-gate } signame_t;
410Sstevel@tonic-gate
420Sstevel@tonic-gate static signame_t signames[] = {
430Sstevel@tonic-gate { "EXIT", 0 },
440Sstevel@tonic-gate { "HUP", SIGHUP },
450Sstevel@tonic-gate { "INT", SIGINT },
460Sstevel@tonic-gate { "QUIT", SIGQUIT },
470Sstevel@tonic-gate { "ILL", SIGILL },
480Sstevel@tonic-gate { "TRAP", SIGTRAP },
490Sstevel@tonic-gate { "ABRT", SIGABRT },
500Sstevel@tonic-gate { "IOT", SIGIOT },
510Sstevel@tonic-gate { "EMT", SIGEMT },
520Sstevel@tonic-gate { "FPE", SIGFPE },
530Sstevel@tonic-gate { "KILL", SIGKILL },
540Sstevel@tonic-gate { "BUS", SIGBUS },
550Sstevel@tonic-gate { "SEGV", SIGSEGV },
560Sstevel@tonic-gate { "SYS", SIGSYS },
570Sstevel@tonic-gate { "PIPE", SIGPIPE },
580Sstevel@tonic-gate { "ALRM", SIGALRM },
590Sstevel@tonic-gate { "TERM", SIGTERM },
600Sstevel@tonic-gate { "USR1", SIGUSR1 },
610Sstevel@tonic-gate { "USR2", SIGUSR2 },
620Sstevel@tonic-gate { "CLD", SIGCLD },
630Sstevel@tonic-gate { "CHLD", SIGCHLD },
640Sstevel@tonic-gate { "PWR", SIGPWR },
650Sstevel@tonic-gate { "WINCH", SIGWINCH },
660Sstevel@tonic-gate { "URG", SIGURG },
670Sstevel@tonic-gate { "POLL", SIGPOLL },
680Sstevel@tonic-gate { "IO", SIGPOLL },
690Sstevel@tonic-gate { "STOP", SIGSTOP },
700Sstevel@tonic-gate { "TSTP", SIGTSTP },
710Sstevel@tonic-gate { "CONT", SIGCONT },
720Sstevel@tonic-gate { "TTIN", SIGTTIN },
730Sstevel@tonic-gate { "TTOU", SIGTTOU },
740Sstevel@tonic-gate { "VTALRM", SIGVTALRM },
750Sstevel@tonic-gate { "PROF", SIGPROF },
760Sstevel@tonic-gate { "XCPU", SIGXCPU },
770Sstevel@tonic-gate { "XFSZ", SIGXFSZ },
780Sstevel@tonic-gate { "WAITING", SIGWAITING },
790Sstevel@tonic-gate { "LWP", SIGLWP },
800Sstevel@tonic-gate { "FREEZE", SIGFREEZE },
810Sstevel@tonic-gate { "THAW", SIGTHAW },
820Sstevel@tonic-gate { "CANCEL", SIGCANCEL },
830Sstevel@tonic-gate { "LOST", SIGLOST },
840Sstevel@tonic-gate { "XRES", SIGXRES },
850Sstevel@tonic-gate { "JVM1", SIGJVM1 },
860Sstevel@tonic-gate { "JVM2", SIGJVM2 },
870Sstevel@tonic-gate { "RTMIN", _SIGRTMIN },
880Sstevel@tonic-gate { "RTMIN+1", _SIGRTMIN+1 },
890Sstevel@tonic-gate { "RTMIN+2", _SIGRTMIN+2 },
900Sstevel@tonic-gate { "RTMIN+3", _SIGRTMIN+3 },
91*11913SRoger.Faulkner@Sun.COM { "RTMIN+4", _SIGRTMIN+4 },
92*11913SRoger.Faulkner@Sun.COM { "RTMIN+5", _SIGRTMIN+5 },
93*11913SRoger.Faulkner@Sun.COM { "RTMIN+6", _SIGRTMIN+6 },
94*11913SRoger.Faulkner@Sun.COM { "RTMIN+7", _SIGRTMIN+7 },
95*11913SRoger.Faulkner@Sun.COM { "RTMIN+8", _SIGRTMIN+8 },
96*11913SRoger.Faulkner@Sun.COM { "RTMIN+9", _SIGRTMIN+9 },
97*11913SRoger.Faulkner@Sun.COM { "RTMIN+10", _SIGRTMIN+10 },
98*11913SRoger.Faulkner@Sun.COM { "RTMIN+11", _SIGRTMIN+11 },
99*11913SRoger.Faulkner@Sun.COM { "RTMIN+12", _SIGRTMIN+12 },
100*11913SRoger.Faulkner@Sun.COM { "RTMIN+13", _SIGRTMIN+13 },
101*11913SRoger.Faulkner@Sun.COM { "RTMIN+14", _SIGRTMIN+14 },
102*11913SRoger.Faulkner@Sun.COM { "RTMIN+15", _SIGRTMIN+15 },
103*11913SRoger.Faulkner@Sun.COM { "RTMAX-15", _SIGRTMAX-15 },
104*11913SRoger.Faulkner@Sun.COM { "RTMAX-14", _SIGRTMAX-14 },
105*11913SRoger.Faulkner@Sun.COM { "RTMAX-13", _SIGRTMAX-13 },
106*11913SRoger.Faulkner@Sun.COM { "RTMAX-12", _SIGRTMAX-12 },
107*11913SRoger.Faulkner@Sun.COM { "RTMAX-11", _SIGRTMAX-11 },
108*11913SRoger.Faulkner@Sun.COM { "RTMAX-10", _SIGRTMAX-10 },
109*11913SRoger.Faulkner@Sun.COM { "RTMAX-9", _SIGRTMAX-9 },
110*11913SRoger.Faulkner@Sun.COM { "RTMAX-8", _SIGRTMAX-8 },
111*11913SRoger.Faulkner@Sun.COM { "RTMAX-7", _SIGRTMAX-7 },
112*11913SRoger.Faulkner@Sun.COM { "RTMAX-6", _SIGRTMAX-6 },
113*11913SRoger.Faulkner@Sun.COM { "RTMAX-5", _SIGRTMAX-5 },
114*11913SRoger.Faulkner@Sun.COM { "RTMAX-4", _SIGRTMAX-4 },
1150Sstevel@tonic-gate { "RTMAX-3", _SIGRTMAX-3 },
1160Sstevel@tonic-gate { "RTMAX-2", _SIGRTMAX-2 },
1170Sstevel@tonic-gate { "RTMAX-1", _SIGRTMAX-1 },
1180Sstevel@tonic-gate { "RTMAX", _SIGRTMAX },
1190Sstevel@tonic-gate };
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate #define SIGCNT (sizeof (signames) / sizeof (struct signame))
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate static int str2long(const char *, long *);
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate static int
str2long(const char * p,long * val)1260Sstevel@tonic-gate str2long(const char *p, long *val)
1270Sstevel@tonic-gate {
1280Sstevel@tonic-gate char *q;
1290Sstevel@tonic-gate int error;
1300Sstevel@tonic-gate int saved_errno = errno;
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate errno = 0;
1330Sstevel@tonic-gate *val = strtol(p, &q, 10);
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate error = ((errno != 0 || q == p || *q != '\0') ? -1 : 0);
1360Sstevel@tonic-gate errno = saved_errno;
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate return (error);
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate int
str2sig(const char * s,int * sigp)1420Sstevel@tonic-gate str2sig(const char *s, int *sigp)
1430Sstevel@tonic-gate {
1440Sstevel@tonic-gate const struct signame *sp;
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate if (*s >= '0' && *s <= '9') {
1470Sstevel@tonic-gate long val;
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate if (str2long(s, &val) == -1)
1500Sstevel@tonic-gate return (-1);
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate for (sp = signames; sp < &signames[SIGCNT]; sp++) {
1530Sstevel@tonic-gate if (sp->signum == val) {
1540Sstevel@tonic-gate *sigp = sp->signum;
1550Sstevel@tonic-gate return (0);
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate return (-1);
1590Sstevel@tonic-gate } else {
1600Sstevel@tonic-gate for (sp = signames; sp < &signames[SIGCNT]; sp++) {
1610Sstevel@tonic-gate if (strcmp(sp->sigstr, s) == 0) {
1620Sstevel@tonic-gate *sigp = sp->signum;
1630Sstevel@tonic-gate return (0);
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate return (-1);
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate int
sig2str(int i,char * s)1710Sstevel@tonic-gate sig2str(int i, char *s)
1720Sstevel@tonic-gate {
1730Sstevel@tonic-gate const struct signame *sp;
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate for (sp = signames; sp < &signames[SIGCNT]; sp++) {
1760Sstevel@tonic-gate if (sp->signum == i) {
1770Sstevel@tonic-gate (void) strcpy(s, sp->sigstr);
1780Sstevel@tonic-gate return (0);
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate }
1810Sstevel@tonic-gate return (-1);
1820Sstevel@tonic-gate }
183