1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 #pragma ident "%Z%%M% %I% %E% SMI" 23 24 /* 25 * Copyright (c) 1987 Sun Microsystems, Inc. 26 */ 27 28 #include <errno.h> 29 #include <sys/signal.h> 30 31 int 32 sighold(sig) 33 int sig; 34 { 35 36 if (sig == SIGKILL) { 37 errno = EINVAL; 38 return (-1); /* sigblock quietly disallows SIGKILL */ 39 } 40 (void) sigblock(sigmask(sig)); 41 return (0); /* SVID specifies 0 return on success */ 42 } 43 44 int 45 sigrelse(sig) 46 int sig; 47 { 48 49 if (sig == SIGKILL) { 50 errno = EINVAL; 51 return (-1); /* sigsetmask quietly disallows SIGKILL */ 52 } 53 (void) sigsetmask(sigblock(0) & ~sigmask(sig)); 54 return (0); /* SVID specifies 0 return on success */ 55 } 56 57 int 58 sigignore(sig) 59 int sig; 60 { 61 struct sigvec vec; 62 63 if (sig == SIGKILL) { 64 errno = EINVAL; 65 return (-1); /* sigsetmask quietly disallows SIGKILL */ 66 } 67 if (sigvec(sig, (struct sigvec *)0, &vec) < 0) 68 return (-1); 69 vec.sv_handler = SIG_IGN; 70 if (sigvec(sig, &vec, (struct sigvec *)0) < 0) 71 return (-1); 72 (void) sigsetmask(sigblock(0) & ~sigmask(sig)); 73 return (0); /* SVID specifies 0 return on success */ 74 } 75 76 void (* 77 sigset(sig, func))() 78 int sig; 79 void (*func)(); 80 { 81 struct sigvec newvec; 82 int newmask; 83 struct sigvec oldvec; 84 int oldmask; 85 86 if (sigvec(sig, (struct sigvec *)0, &oldvec) < 0) 87 return (SIG_ERR); 88 oldmask = sigblock(0); 89 newvec = oldvec; 90 newvec.sv_flags |= SV_INTERRUPT; 91 newvec.sv_flags &= ~SV_RESETHAND; 92 newvec.sv_mask = 0; 93 newmask = oldmask; 94 if (func == SIG_HOLD) { 95 /* 96 * Signal will be held. Set the bit for that 97 * signal in the signal mask. Leave the action 98 * alone. 99 */ 100 newmask |= sigmask(sig); 101 } else { 102 /* 103 * Signal will not be held. Clear the bit 104 * for it in the signal mask. Set the action 105 * for it. 106 */ 107 newmask &= ~sigmask(sig); 108 newvec.sv_handler = func; 109 } 110 if (sigvec(sig, &newvec, (struct sigvec *)0) < 0) 111 return (SIG_ERR); 112 if (sigsetmask(newmask) < 0) 113 return (SIG_ERR); 114 if (oldmask & sigmask(sig)) 115 return (SIG_HOLD); /* signal was held */ 116 else 117 return (oldvec.sv_handler); 118 } 119