From: Colin Percival Date: Fri, 5 Jun 2009 06:15:50 +0000 (-0400) Subject: Use sigaction instead of signal. This unbreaks Solaris and other X-Git-Tag: v2.8.0~598 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c86304e278fa20ce84db67eeed6a0888b097cf17;p=thirdparty%2Flibarchive.git Use sigaction instead of signal. This unbreaks Solaris and other platforms with SysV signal-handling semantics. Obtained from: tarsnap SVN-Revision: 1146 --- diff --git a/tar/siginfo.c b/tar/siginfo.c index 8ecdaa7ea..9b00cfa8b 100644 --- a/tar/siginfo.c +++ b/tar/siginfo.c @@ -50,9 +50,9 @@ struct siginfo_data { /* Old signal handlers. */ #ifdef SIGINFO - void (*siginfo_old)(int); + struct sigaction siginfo_old; #endif - void (*sigusr1_old)(int); + struct sigaction sigusr1_old; }; static void siginfo_handler(int sig); @@ -71,6 +71,7 @@ siginfo_handler(int sig) void siginfo_init(struct bsdtar *bsdtar) { + struct sigaction sa; /* Allocate space for internal structure. */ if ((bsdtar->siginfo = malloc(sizeof(struct siginfo_data))) == NULL) @@ -79,13 +80,18 @@ siginfo_init(struct bsdtar *bsdtar) /* Set the strings to NULL so that free() is safe. */ bsdtar->siginfo->path = bsdtar->siginfo->oper = NULL; -#ifdef SIGINFO /* We want to catch SIGINFO, if it exists. */ - bsdtar->siginfo->siginfo_old = signal(SIGINFO, siginfo_handler); + sa.sa_handler = siginfo_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; +#ifdef SIGINFO + if (sigaction(SIGINFO, &sa, &bsdtar->siginfo->siginfo_old)) + bsdtar_errc(bsdtar, 1, errno, "sigaction(SIGINFO) failed"); #endif #ifdef SIGUSR1 /* ... and treat SIGUSR1 the same way as SIGINFO. */ - bsdtar->siginfo->sigusr1_old = signal(SIGUSR1, siginfo_handler); + if (sigaction(SIGUSR1, &sa, &bsdtar->siginfo->sigusr1_old)) + bsdtar_errc(bsdtar, 1, errno, "sigaction(SIGUSR1) failed"); #endif } @@ -136,11 +142,11 @@ siginfo_done(struct bsdtar *bsdtar) #ifdef SIGINFO /* Restore old SIGINFO handler. */ - signal(SIGINFO, bsdtar->siginfo->siginfo_old); + sigaction(SIGINFO, &bsdtar->siginfo->siginfo_old, NULL); #endif #ifdef SIGUSR1 /* And the old SIGUSR1 handler, too. */ - signal(SIGUSR1, bsdtar->siginfo->sigusr1_old); + sigaction(SIGUSR1, &bsdtar->siginfo->sigusr1_old, NULL); #endif /* Free strings. */