]> The Tcpdump Group git mirrors - tcpdump/blob - setsignal.c
Switch to config.h instead of passing defines in DEFS.
[tcpdump] / setsignal.c
1 /*
2 * Copyright (c) 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/setsignal.c,v 1.5 1999-11-21 09:37:04 fenner Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <sys/types.h>
32
33 #ifdef HAVE_MEMORY_H
34 #include <memory.h>
35 #endif
36 #include <signal.h>
37 #ifdef HAVE_SIGACTION
38 #include <string.h>
39 #endif
40
41 #include "gnuc.h"
42 #ifdef HAVE_OS_PROTO_H
43 #include "os-proto.h"
44 #endif
45
46 #include "setsignal.h"
47
48 /*
49 * An os independent signal() with BSD semantics, e.g. the signal
50 * catcher is restored following service of the signal.
51 *
52 * When sigset() is available, signal() has SYSV semantics and sigset()
53 * has BSD semantics and call interface. Unfortunately, Linux does not
54 * have sigset() so we use the more complicated sigaction() interface
55 * there.
56 *
57 * Did I mention that signals suck?
58 */
59 RETSIGTYPE
60 (*setsignal (int sig, RETSIGTYPE (*func)(int)))(int)
61 {
62 #ifdef HAVE_SIGACTION
63 struct sigaction old, new;
64
65 memset(&new, 0, sizeof(new));
66 new.sa_handler = func;
67 #ifdef SA_RESTART
68 new.sa_flags |= SA_RESTART;
69 #endif
70 if (sigaction(sig, &new, &old) < 0)
71 return (SIG_ERR);
72 return (old.sa_handler);
73
74 #else
75 #ifdef HAVE_SIGSET
76 return (sigset(sig, func));
77 #else
78 return (signal(sig, func));
79 #endif
80 #endif
81 }
82