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 57257d1b4Sraf * Common Development and Distribution License (the "License"). 67257d1b4Sraf * 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 */ 217257d1b4Sraf 227c478bd9Sstevel@tonic-gate /* 23bdf0047cSRoger A. Faulkner * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*19d32b9aSRobert Mustacchi * Copyright (c) 2014, Joyent, Inc. All rights reserved. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 297c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 307c478bd9Sstevel@tonic-gate 317257d1b4Sraf #include "lint.h" 327c478bd9Sstevel@tonic-gate #include <string.h> 337c478bd9Sstevel@tonic-gate #include <stdlib.h> 347c478bd9Sstevel@tonic-gate #include <signal.h> 357c478bd9Sstevel@tonic-gate #include <sys/types.h> 367c478bd9Sstevel@tonic-gate #include <errno.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate typedef struct signame { 397c478bd9Sstevel@tonic-gate const char *sigstr; 407c478bd9Sstevel@tonic-gate const int signum; 417c478bd9Sstevel@tonic-gate } signame_t; 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate static signame_t signames[] = { 447c478bd9Sstevel@tonic-gate { "EXIT", 0 }, 457c478bd9Sstevel@tonic-gate { "HUP", SIGHUP }, 467c478bd9Sstevel@tonic-gate { "INT", SIGINT }, 477c478bd9Sstevel@tonic-gate { "QUIT", SIGQUIT }, 487c478bd9Sstevel@tonic-gate { "ILL", SIGILL }, 497c478bd9Sstevel@tonic-gate { "TRAP", SIGTRAP }, 507c478bd9Sstevel@tonic-gate { "ABRT", SIGABRT }, 517c478bd9Sstevel@tonic-gate { "IOT", SIGIOT }, 527c478bd9Sstevel@tonic-gate { "EMT", SIGEMT }, 537c478bd9Sstevel@tonic-gate { "FPE", SIGFPE }, 547c478bd9Sstevel@tonic-gate { "KILL", SIGKILL }, 557c478bd9Sstevel@tonic-gate { "BUS", SIGBUS }, 567c478bd9Sstevel@tonic-gate { "SEGV", SIGSEGV }, 577c478bd9Sstevel@tonic-gate { "SYS", SIGSYS }, 587c478bd9Sstevel@tonic-gate { "PIPE", SIGPIPE }, 597c478bd9Sstevel@tonic-gate { "ALRM", SIGALRM }, 607c478bd9Sstevel@tonic-gate { "TERM", SIGTERM }, 617c478bd9Sstevel@tonic-gate { "USR1", SIGUSR1 }, 627c478bd9Sstevel@tonic-gate { "USR2", SIGUSR2 }, 637c478bd9Sstevel@tonic-gate { "CLD", SIGCLD }, 647c478bd9Sstevel@tonic-gate { "CHLD", SIGCHLD }, 657c478bd9Sstevel@tonic-gate { "PWR", SIGPWR }, 667c478bd9Sstevel@tonic-gate { "WINCH", SIGWINCH }, 677c478bd9Sstevel@tonic-gate { "URG", SIGURG }, 687c478bd9Sstevel@tonic-gate { "POLL", SIGPOLL }, 697c478bd9Sstevel@tonic-gate { "IO", SIGPOLL }, 707c478bd9Sstevel@tonic-gate { "STOP", SIGSTOP }, 717c478bd9Sstevel@tonic-gate { "TSTP", SIGTSTP }, 727c478bd9Sstevel@tonic-gate { "CONT", SIGCONT }, 737c478bd9Sstevel@tonic-gate { "TTIN", SIGTTIN }, 747c478bd9Sstevel@tonic-gate { "TTOU", SIGTTOU }, 757c478bd9Sstevel@tonic-gate { "VTALRM", SIGVTALRM }, 767c478bd9Sstevel@tonic-gate { "PROF", SIGPROF }, 777c478bd9Sstevel@tonic-gate { "XCPU", SIGXCPU }, 787c478bd9Sstevel@tonic-gate { "XFSZ", SIGXFSZ }, 797c478bd9Sstevel@tonic-gate { "WAITING", SIGWAITING }, 807c478bd9Sstevel@tonic-gate { "LWP", SIGLWP }, 817c478bd9Sstevel@tonic-gate { "FREEZE", SIGFREEZE }, 827c478bd9Sstevel@tonic-gate { "THAW", SIGTHAW }, 837c478bd9Sstevel@tonic-gate { "CANCEL", SIGCANCEL }, 847c478bd9Sstevel@tonic-gate { "LOST", SIGLOST }, 857c478bd9Sstevel@tonic-gate { "XRES", SIGXRES }, 867c478bd9Sstevel@tonic-gate { "JVM1", SIGJVM1 }, 877c478bd9Sstevel@tonic-gate { "JVM2", SIGJVM2 }, 88*19d32b9aSRobert Mustacchi { "INFO", SIGINFO }, 897c478bd9Sstevel@tonic-gate { "RTMIN", _SIGRTMIN }, 907c478bd9Sstevel@tonic-gate { "RTMIN+1", _SIGRTMIN+1 }, 917c478bd9Sstevel@tonic-gate { "RTMIN+2", _SIGRTMIN+2 }, 927c478bd9Sstevel@tonic-gate { "RTMIN+3", _SIGRTMIN+3 }, 93bdf0047cSRoger A. Faulkner { "RTMIN+4", _SIGRTMIN+4 }, 94bdf0047cSRoger A. Faulkner { "RTMIN+5", _SIGRTMIN+5 }, 95bdf0047cSRoger A. Faulkner { "RTMIN+6", _SIGRTMIN+6 }, 96bdf0047cSRoger A. Faulkner { "RTMIN+7", _SIGRTMIN+7 }, 97bdf0047cSRoger A. Faulkner { "RTMIN+8", _SIGRTMIN+8 }, 98bdf0047cSRoger A. Faulkner { "RTMIN+9", _SIGRTMIN+9 }, 99bdf0047cSRoger A. Faulkner { "RTMIN+10", _SIGRTMIN+10 }, 100bdf0047cSRoger A. Faulkner { "RTMIN+11", _SIGRTMIN+11 }, 101bdf0047cSRoger A. Faulkner { "RTMIN+12", _SIGRTMIN+12 }, 102bdf0047cSRoger A. Faulkner { "RTMIN+13", _SIGRTMIN+13 }, 103bdf0047cSRoger A. Faulkner { "RTMIN+14", _SIGRTMIN+14 }, 104bdf0047cSRoger A. Faulkner { "RTMIN+15", _SIGRTMIN+15 }, 105bdf0047cSRoger A. Faulkner { "RTMAX-15", _SIGRTMAX-15 }, 106bdf0047cSRoger A. Faulkner { "RTMAX-14", _SIGRTMAX-14 }, 107bdf0047cSRoger A. Faulkner { "RTMAX-13", _SIGRTMAX-13 }, 108bdf0047cSRoger A. Faulkner { "RTMAX-12", _SIGRTMAX-12 }, 109bdf0047cSRoger A. Faulkner { "RTMAX-11", _SIGRTMAX-11 }, 110bdf0047cSRoger A. Faulkner { "RTMAX-10", _SIGRTMAX-10 }, 111bdf0047cSRoger A. Faulkner { "RTMAX-9", _SIGRTMAX-9 }, 112bdf0047cSRoger A. Faulkner { "RTMAX-8", _SIGRTMAX-8 }, 113bdf0047cSRoger A. Faulkner { "RTMAX-7", _SIGRTMAX-7 }, 114bdf0047cSRoger A. Faulkner { "RTMAX-6", _SIGRTMAX-6 }, 115bdf0047cSRoger A. Faulkner { "RTMAX-5", _SIGRTMAX-5 }, 116bdf0047cSRoger A. Faulkner { "RTMAX-4", _SIGRTMAX-4 }, 1177c478bd9Sstevel@tonic-gate { "RTMAX-3", _SIGRTMAX-3 }, 1187c478bd9Sstevel@tonic-gate { "RTMAX-2", _SIGRTMAX-2 }, 1197c478bd9Sstevel@tonic-gate { "RTMAX-1", _SIGRTMAX-1 }, 1207c478bd9Sstevel@tonic-gate { "RTMAX", _SIGRTMAX }, 1217c478bd9Sstevel@tonic-gate }; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate #define SIGCNT (sizeof (signames) / sizeof (struct signame)) 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate static int str2long(const char *, long *); 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate static int 1287c478bd9Sstevel@tonic-gate str2long(const char *p, long *val) 1297c478bd9Sstevel@tonic-gate { 1307c478bd9Sstevel@tonic-gate char *q; 1317c478bd9Sstevel@tonic-gate int error; 1327c478bd9Sstevel@tonic-gate int saved_errno = errno; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate errno = 0; 1357c478bd9Sstevel@tonic-gate *val = strtol(p, &q, 10); 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate error = ((errno != 0 || q == p || *q != '\0') ? -1 : 0); 1387c478bd9Sstevel@tonic-gate errno = saved_errno; 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate return (error); 1417c478bd9Sstevel@tonic-gate } 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate int 1447c478bd9Sstevel@tonic-gate str2sig(const char *s, int *sigp) 1457c478bd9Sstevel@tonic-gate { 1467c478bd9Sstevel@tonic-gate const struct signame *sp; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate if (*s >= '0' && *s <= '9') { 1497c478bd9Sstevel@tonic-gate long val; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate if (str2long(s, &val) == -1) 1527c478bd9Sstevel@tonic-gate return (-1); 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate for (sp = signames; sp < &signames[SIGCNT]; sp++) { 1557c478bd9Sstevel@tonic-gate if (sp->signum == val) { 1567c478bd9Sstevel@tonic-gate *sigp = sp->signum; 1577c478bd9Sstevel@tonic-gate return (0); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate return (-1); 1617c478bd9Sstevel@tonic-gate } else { 1627c478bd9Sstevel@tonic-gate for (sp = signames; sp < &signames[SIGCNT]; sp++) { 1637c478bd9Sstevel@tonic-gate if (strcmp(sp->sigstr, s) == 0) { 1647c478bd9Sstevel@tonic-gate *sigp = sp->signum; 1657c478bd9Sstevel@tonic-gate return (0); 1667c478bd9Sstevel@tonic-gate } 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate return (-1); 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate int 1737c478bd9Sstevel@tonic-gate sig2str(int i, char *s) 1747c478bd9Sstevel@tonic-gate { 1757c478bd9Sstevel@tonic-gate const struct signame *sp; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate for (sp = signames; sp < &signames[SIGCNT]; sp++) { 1787c478bd9Sstevel@tonic-gate if (sp->signum == i) { 1797c478bd9Sstevel@tonic-gate (void) strcpy(s, sp->sigstr); 1807c478bd9Sstevel@tonic-gate return (0); 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate return (-1); 1847c478bd9Sstevel@tonic-gate } 185