From: Joerg Sonnenberger Date: Tue, 21 Jun 2016 13:21:20 +0000 (+0200) Subject: SIGRTMAX doesn't exist on all systems, so compute the largest used X-Git-Tag: v3.2.2~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cdc276b602d70acd995414ea444cacbc33cb021;p=thirdparty%2Flibarchive.git SIGRTMAX doesn't exist on all systems, so compute the largest used signal number. Don't bother with dynamically allocating the array, just use a static array instead. Fix ctype use. --- diff --git a/libarchive_fe/passphrase.c b/libarchive_fe/passphrase.c index d5ecccc5a..332243758 100644 --- a/libarchive_fe/passphrase.c +++ b/libarchive_fe/passphrase.c @@ -121,14 +121,15 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) #else /* _WIN32 && !__CYGWIN__ */ -#include -#include +#include #include #include #ifdef HAVE_PATHS_H #include #endif +#include #include +#include #include #ifdef TCSASOFT @@ -142,11 +143,18 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) # define _POSIX_VDISABLE VDISABLE #endif -static volatile sig_atomic_t *signo; +#define M(a,b) (a > b ? a : b) +#define MAX_SIGNO M(M(M(SIGALRM, SIGHUP), \ + M(SIGINT, SIGPIPE)), \ + M(M(SIGQUIT, SIGTERM), \ + M(M(SIGTSTP, SIGTTIN), SIGTTOU))) + +static volatile sig_atomic_t signo[MAX_SIGNO + 1]; static void handler(int s) { + assert(s <= MAX_SIGNO); signo[s] = 1; } @@ -166,12 +174,8 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) return(NULL); } - if (signo == NULL) { - signo = calloc(SIGRTMAX, sizeof(sig_atomic_t)); - } - restart: - for (i = 0; i < SIGRTMAX; i++) + for (i = 0; i <= MAX_SIGNO; i++) signo[i] = 0; nr = -1; save_errno = 0; @@ -198,6 +202,7 @@ restart: sigemptyset(&sa.sa_mask); sa.sa_flags = 0; /* don't restart system calls */ sa.sa_handler = handler; + /* Keep this list in sync with MAX_SIGNO! */ (void)sigaction(SIGALRM, &sa, &savealrm); (void)sigaction(SIGHUP, &sa, &savehup); (void)sigaction(SIGINT, &sa, &saveint); @@ -276,7 +281,7 @@ restart: * If we were interrupted by a signal, resend it to ourselves * now that we have restored the signal handlers. */ - for (i = 0; i < SIGRTMAX; i++) { + for (i = 0; i <= MAX_SIGNO; i++) { if (signo[i]) { kill(getpid(), i); switch (i) {