]> The Tcpdump Group git mirrors - tcpdump/blob - setsignal.c
(packetp, snapend): remove duplicate static declarations
[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.6 2000-07-01 03:39:12 assar Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <sys/types.h>
32
33 #include <signal.h>
34 #ifdef HAVE_SIGACTION
35 #include <string.h>
36 #endif
37
38 #include "gnuc.h"
39 #ifdef HAVE_OS_PROTO_H
40 #include "os-proto.h"
41 #endif
42
43 #include "setsignal.h"
44
45 /*
46 * An os independent signal() with BSD semantics, e.g. the signal
47 * catcher is restored following service of the signal.
48 *
49 * When sigset() is available, signal() has SYSV semantics and sigset()
50 * has BSD semantics and call interface. Unfortunately, Linux does not
51 * have sigset() so we use the more complicated sigaction() interface
52 * there.
53 *
54 * Did I mention that signals suck?
55 */
56 RETSIGTYPE
57 (*setsignal (int sig, RETSIGTYPE (*func)(int)))(int)
58 {
59 #ifdef HAVE_SIGACTION
60 struct sigaction old, new;
61
62 memset(&new, 0, sizeof(new));
63 new.sa_handler = func;
64 #ifdef SA_RESTART
65 new.sa_flags |= SA_RESTART;
66 #endif
67 if (sigaction(sig, &new, &old) < 0)
68 return (SIG_ERR);
69 return (old.sa_handler);
70
71 #else
72 #ifdef HAVE_SIGSET
73 return (sigset(sig, func));
74 #else
75 return (signal(sig, func));
76 #endif
77 #endif
78 }
79