1 /*
2 * ircsig.c: has a `my_signal()' that uses sigaction().
3 *
4 * Copyright (c) 1993-2000 Matthew R. Green.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 /*
32 * written by matthew green, 1993.
33 *
34 * i stole bits of this from w. richard stevens' `advanced programming
35 * in the unix environment' -mrg
36 */
37
38 #include "irc.h"
39 IRCII_RCSID("@(#)$Id: ircsig.c,v 1.10 2000/04/03 08:28:47 mrg Exp $");
40
41 #ifdef USE_SIGACTION
42 sigfunc *
my_signal(sig_no,sig_handler,misc_flags)43 my_signal(sig_no, sig_handler, misc_flags)
44 int sig_no;
45 sigfunc *sig_handler;
46 int misc_flags;
47 {
48 /*
49 * misc_flags is unused currently. it's planned to be used
50 * to use some of the doovier bits of sigaction(), if at
51 * some point we need them, -mrg
52 */
53
54 struct sigaction sa, osa;
55
56 /*
57 * have to (void *) this because of strict type checking
58 * on some systems -glen
59 */
60 sa.sa_handler = (void (*)_((int))) sig_handler;
61
62 sigemptyset(&sa.sa_mask);
63 sigaddset(&sa.sa_mask, sig_no);
64
65 /* this is ugly, but the `correct' way. i hate c. -mrg */
66 sa.sa_flags = 0;
67 #if defined(SA_RESTART) || defined(SA_INTERRUPT)
68 if (SIGALRM == sig_no)
69 {
70 # if defined(SA_INTERRUPT)
71 sa.sa_flags |= SA_INTERRUPT;
72 # endif /* SA_INTERRUPT */
73 }
74 else
75 {
76 # if defined(SA_RESTART)
77 sa.sa_flags |= SA_RESTART;
78 # endif /* SA_RESTART */
79 }
80 #endif /* SA_RESTART || SA_INTERRUPT */
81
82 if (0 > sigaction(sig_no, &sa, &osa))
83 return ((sigfunc *)SIG_ERR);
84
85 return ((sigfunc *)osa.sa_handler);
86 }
87 #endif /* USE_SIGACTION */
88