diff options
author | Darren Tucker <dtucker@dtucker.net> | 2018-02-11 21:25:11 +1300 |
---|---|---|
committer | Darren Tucker <dtucker@dtucker.net> | 2018-02-11 21:24:48 +1100 |
commit | fbfa6f980d7460b3e12b0ce88ed3b6018edf4711 (patch) | |
tree | 0c75a95f5f6e2a1e7d2de891f7b7476e41574f56 /openbsd-compat | |
parent | 24d2a33bd3bf5170700bfdd8675498aa09a79eab (diff) |
Move signal compat code into bsd-signal.{c,h}
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/Makefile.in | 2 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.c | 37 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.h | 10 | ||||
-rw-r--r-- | openbsd-compat/bsd-signal.c | 62 | ||||
-rw-r--r-- | openbsd-compat/bsd-signal.h | 39 | ||||
-rw-r--r-- | openbsd-compat/openbsd-compat.h | 1 | ||||
-rw-r--r-- | openbsd-compat/readpassphrase.c | 8 |
7 files changed, 103 insertions, 56 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index 5eef024b5..213ded4d4 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in | |||
@@ -18,7 +18,7 @@ LDFLAGS=-L. @LDFLAGS@ | |||
18 | 18 | ||
19 | OPENBSD=base64.o basename.o bcrypt_pbkdf.o bindresvport.o blowfish.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt_long.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o reallocarray.o realpath.o recallocarray.o rresvport.o setenv.o setproctitle.o sha1.o sha2.o rmd160.o md5.o sigact.o strcasestr.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o blowfish.o bcrypt_pbkdf.o explicit_bzero.o freezero.o | 19 | OPENBSD=base64.o basename.o bcrypt_pbkdf.o bindresvport.o blowfish.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt_long.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o reallocarray.o realpath.o recallocarray.o rresvport.o setenv.o setproctitle.o sha1.o sha2.o rmd160.o md5.o sigact.o strcasestr.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o blowfish.o bcrypt_pbkdf.o explicit_bzero.o freezero.o |
20 | 20 | ||
21 | COMPAT=arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-err.o bsd-getpagesize.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-malloc.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xcrypt.o kludge-fd_set.o | 21 | COMPAT=arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-err.o bsd-getpagesize.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-malloc.o bsd-setres_id.o bsd-signal.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xcrypt.o kludge-fd_set.o |
22 | 22 | ||
23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-net.o port-uw.o | 23 | PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-net.o port-uw.o |
24 | 24 | ||
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 29f6ad38c..9f6dc8af2 100644 --- a/openbsd-compat/bsd-misc.c +++ b/openbsd-compat/bsd-misc.c | |||
@@ -104,16 +104,6 @@ const char *strerror(int e) | |||
104 | } | 104 | } |
105 | #endif | 105 | #endif |
106 | 106 | ||
107 | #if !defined(HAVE_STRSIGNAL) | ||
108 | char *strsignal(int sig) | ||
109 | { | ||
110 | static char buf[16]; | ||
111 | |||
112 | (void)snprintf(buf, sizeof(buf), "%d", sig); | ||
113 | return buf; | ||
114 | } | ||
115 | #endif | ||
116 | |||
117 | #ifndef HAVE_UTIMES | 107 | #ifndef HAVE_UTIMES |
118 | int utimes(char *filename, struct timeval *tvp) | 108 | int utimes(char *filename, struct timeval *tvp) |
119 | { | 109 | { |
@@ -221,33 +211,6 @@ tcsendbreak(int fd, int duration) | |||
221 | } | 211 | } |
222 | #endif /* HAVE_TCSENDBREAK */ | 212 | #endif /* HAVE_TCSENDBREAK */ |
223 | 213 | ||
224 | mysig_t | ||
225 | mysignal(int sig, mysig_t act) | ||
226 | { | ||
227 | #ifdef HAVE_SIGACTION | ||
228 | struct sigaction sa, osa; | ||
229 | |||
230 | if (sigaction(sig, NULL, &osa) == -1) | ||
231 | return (mysig_t) -1; | ||
232 | if (osa.sa_handler != act) { | ||
233 | memset(&sa, 0, sizeof(sa)); | ||
234 | sigemptyset(&sa.sa_mask); | ||
235 | sa.sa_flags = 0; | ||
236 | #ifdef SA_INTERRUPT | ||
237 | if (sig == SIGALRM) | ||
238 | sa.sa_flags |= SA_INTERRUPT; | ||
239 | #endif | ||
240 | sa.sa_handler = act; | ||
241 | if (sigaction(sig, &sa, NULL) == -1) | ||
242 | return (mysig_t) -1; | ||
243 | } | ||
244 | return (osa.sa_handler); | ||
245 | #else | ||
246 | #undef signal | ||
247 | return (signal(sig, act)); | ||
248 | #endif | ||
249 | } | ||
250 | |||
251 | #ifndef HAVE_STRDUP | 214 | #ifndef HAVE_STRDUP |
252 | char * | 215 | char * |
253 | strdup(const char *str) | 216 | strdup(const char *str) |
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h index 0b1a3504f..2cfd5dae6 100644 --- a/openbsd-compat/bsd-misc.h +++ b/openbsd-compat/bsd-misc.h | |||
@@ -49,10 +49,6 @@ int setegid(uid_t); | |||
49 | const char *strerror(int); | 49 | const char *strerror(int); |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | #if !defined(HAVE_STRSIGNAL) | ||
53 | char *strsignal(int); | ||
54 | #endif | ||
55 | |||
56 | #if !defined(HAVE_SETLINEBUF) | 52 | #if !defined(HAVE_SETLINEBUF) |
57 | #define setlinebuf(a) (setvbuf((a), NULL, _IOLBF, 0)) | 53 | #define setlinebuf(a) (setvbuf((a), NULL, _IOLBF, 0)) |
58 | #endif | 54 | #endif |
@@ -98,12 +94,6 @@ int tcsendbreak(int, int); | |||
98 | int unsetenv(const char *); | 94 | int unsetenv(const char *); |
99 | #endif | 95 | #endif |
100 | 96 | ||
101 | /* wrapper for signal interface */ | ||
102 | typedef void (*mysig_t)(int); | ||
103 | mysig_t mysignal(int sig, mysig_t act); | ||
104 | |||
105 | #define signal(a,b) mysignal(a,b) | ||
106 | |||
107 | #ifndef HAVE_ISBLANK | 97 | #ifndef HAVE_ISBLANK |
108 | int isblank(int); | 98 | int isblank(int); |
109 | #endif | 99 | #endif |
diff --git a/openbsd-compat/bsd-signal.c b/openbsd-compat/bsd-signal.c new file mode 100644 index 000000000..979010e84 --- /dev/null +++ b/openbsd-compat/bsd-signal.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "includes.h" | ||
18 | |||
19 | #include <signal.h> | ||
20 | #include <string.h> | ||
21 | #include <unistd.h> | ||
22 | |||
23 | #include "openbsd-compat/bsd-signal.h" | ||
24 | |||
25 | #undef signal | ||
26 | |||
27 | mysig_t | ||
28 | mysignal(int sig, mysig_t act) | ||
29 | { | ||
30 | #ifdef HAVE_SIGACTION | ||
31 | struct sigaction sa, osa; | ||
32 | |||
33 | if (sigaction(sig, NULL, &osa) == -1) | ||
34 | return (mysig_t) -1; | ||
35 | if (osa.sa_handler != act) { | ||
36 | memset(&sa, 0, sizeof(sa)); | ||
37 | sigemptyset(&sa.sa_mask); | ||
38 | sa.sa_flags = 0; | ||
39 | #ifdef SA_INTERRUPT | ||
40 | if (sig == SIGALRM) | ||
41 | sa.sa_flags |= SA_INTERRUPT; | ||
42 | #endif | ||
43 | sa.sa_handler = act; | ||
44 | if (sigaction(sig, &sa, NULL) == -1) | ||
45 | return (mysig_t) -1; | ||
46 | } | ||
47 | return (osa.sa_handler); | ||
48 | #else | ||
49 | return (signal(sig, act)); | ||
50 | #endif | ||
51 | } | ||
52 | |||
53 | #if !defined(HAVE_STRSIGNAL) | ||
54 | char *strsignal(int sig) | ||
55 | { | ||
56 | static char buf[16]; | ||
57 | |||
58 | (void)snprintf(buf, sizeof(buf), "%d", sig); | ||
59 | return buf; | ||
60 | } | ||
61 | #endif | ||
62 | |||
diff --git a/openbsd-compat/bsd-signal.h b/openbsd-compat/bsd-signal.h new file mode 100644 index 000000000..4cb8cb7a0 --- /dev/null +++ b/openbsd-compat/bsd-signal.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #ifndef _BSD_SIGNAL_H | ||
18 | #define _BSD_SIGNAL_H | ||
19 | |||
20 | #include "includes.h" | ||
21 | |||
22 | #ifndef _NSIG | ||
23 | # ifdef NSIG | ||
24 | # define _NSIG NSIG | ||
25 | # else | ||
26 | # define _NSIG 128 | ||
27 | # endif | ||
28 | #endif | ||
29 | |||
30 | /* wrapper for signal interface */ | ||
31 | typedef void (*mysig_t)(int); | ||
32 | mysig_t mysignal(int sig, mysig_t act); | ||
33 | #define signal(a,b) mysignal(a,b) | ||
34 | |||
35 | #if !defined(HAVE_STRSIGNAL) | ||
36 | char *strsignal(int); | ||
37 | #endif | ||
38 | |||
39 | #endif /* _BSD_SIGNAL_H */ | ||
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 73123bb3f..c7f660609 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -179,6 +179,7 @@ int writev(int, struct iovec *, int); | |||
179 | /* Home grown routines */ | 179 | /* Home grown routines */ |
180 | #include "bsd-misc.h" | 180 | #include "bsd-misc.h" |
181 | #include "bsd-setres_id.h" | 181 | #include "bsd-setres_id.h" |
182 | #include "bsd-signal.h" | ||
182 | #include "bsd-statvfs.h" | 183 | #include "bsd-statvfs.h" |
183 | #include "bsd-waitpid.h" | 184 | #include "bsd-waitpid.h" |
184 | #include "bsd-poll.h" | 185 | #include "bsd-poll.h" |
diff --git a/openbsd-compat/readpassphrase.c b/openbsd-compat/readpassphrase.c index 24aed6e46..ff8ff3dec 100644 --- a/openbsd-compat/readpassphrase.c +++ b/openbsd-compat/readpassphrase.c | |||
@@ -46,14 +46,6 @@ | |||
46 | # define _POSIX_VDISABLE VDISABLE | 46 | # define _POSIX_VDISABLE VDISABLE |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | #ifndef _NSIG | ||
50 | # ifdef NSIG | ||
51 | # define _NSIG NSIG | ||
52 | # else | ||
53 | # define _NSIG 128 | ||
54 | # endif | ||
55 | #endif | ||
56 | |||
57 | static volatile sig_atomic_t signo[_NSIG]; | 49 | static volatile sig_atomic_t signo[_NSIG]; |
58 | 50 | ||
59 | static void handler(int); | 51 | static void handler(int); |