8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libbc / libc / gen / sys5 / sighold.c
blobd0b304dd72d295c94b0ba5f477faa0024b7a80c6
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 #pragma ident "%Z%%M% %I% %E% SMI"
25 * Copyright (c) 1987 Sun Microsystems, Inc.
28 #include <errno.h>
29 #include <sys/signal.h>
31 int
32 sighold(sig)
33 int sig;
36 if (sig == SIGKILL) {
37 errno = EINVAL;
38 return (-1); /* sigblock quietly disallows SIGKILL */
40 (void) sigblock(sigmask(sig));
41 return (0); /* SVID specifies 0 return on success */
44 int
45 sigrelse(sig)
46 int sig;
49 if (sig == SIGKILL) {
50 errno = EINVAL;
51 return (-1); /* sigsetmask quietly disallows SIGKILL */
53 (void) sigsetmask(sigblock(0) & ~sigmask(sig));
54 return (0); /* SVID specifies 0 return on success */
57 int
58 sigignore(sig)
59 int sig;
61 struct sigvec vec;
63 if (sig == SIGKILL) {
64 errno = EINVAL;
65 return (-1); /* sigsetmask quietly disallows SIGKILL */
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 */
76 void (*
77 sigset(sig, func))()
78 int sig;
79 void (*func)();
81 struct sigvec newvec;
82 int newmask;
83 struct sigvec oldvec;
84 int oldmask;
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) {
96 * Signal will be held. Set the bit for that
97 * signal in the signal mask. Leave the action
98 * alone.
100 newmask |= sigmask(sig);
101 } else {
103 * Signal will not be held. Clear the bit
104 * for it in the signal mask. Set the action
105 * for it.
107 newmask &= ~sigmask(sig);
108 newvec.sv_handler = func;
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);