diff options
author | Bill Kendall <wkendall@sgi.com> | 2011-08-04 22:30:06 +0000 |
---|---|---|
committer | Alex Elder <aelder@sgi.com> | 2011-08-09 17:18:48 -0500 |
commit | 4c6bc536e37cd629a9ec738934d4b126e61f07a1 (patch) | |
tree | b9048fa4abbdea0156d5f5dd7a12906002ce29a6 | |
parent | 9e40e3207015a9c0df0786bf0149a642f4e5b6ea (diff) | |
download | xfsdump-dev-4c6bc536e37cd629a9ec738934d4b126e61f07a1.tar.gz |
xfsdump: process EPIPE instead of catching SIGPIPE
Looking forward towards a multi-threaded xfsdump, it's simpler to
handle pipe failures as a system call failure (EPIPE) rather than
through a signal handler which may run in a separate thread. The
existing error handling code handles EPIPE just fine, so the only
required change is to ignore SIGPIPE. Some sections of code already
temporarily ignore SIGPIPE -- they no longer need to do so since it
will already be ignored.
Signed-off-by: Bill Kendall <wkendall@sgi.com>
Signed-off-by: Alex Elder <aelder@sgi.com>
-rw-r--r-- | common/main.c | 49 | ||||
-rw-r--r-- | common/ring.c | 1 | ||||
-rw-r--r-- | librmt/rmtcommand.c | 7 | ||||
-rw-r--r-- | librmt/rmtwrite.c | 5 |
4 files changed, 7 insertions, 55 deletions
diff --git a/common/main.c b/common/main.c index c4d6878e..d21b559a 100644 --- a/common/main.c +++ b/common/main.c @@ -135,7 +135,6 @@ static time32_t stop_deadline; static bool_t stop_in_progress; static bool_t sighup_received; static bool_t sigterm_received; -static bool_t sigpipe_received; static bool_t sigquit_received; static bool_t sigint_received; static size_t prbcld_cnt; @@ -547,13 +546,18 @@ main( int argc, char *argv[] ) * be released at pre-emption points and upon pausing in the main * loop. */ + + /* always ignore SIGPIPE, instead handle EPIPE as part + * of normal sys call error handling + */ + sigset( SIGPIPE, SIG_IGN ); + if ( ! miniroot && ! pipeline ) { stop_in_progress = BOOL_FALSE; coredump_requested = BOOL_FALSE; sighup_received = BOOL_FALSE; sigterm_received = BOOL_FALSE; sigint_received = BOOL_FALSE; - sigpipe_received = BOOL_FALSE; sigquit_received = BOOL_FALSE; sigstray_received = BOOL_FALSE; prbcld_cnt = 0; @@ -563,8 +567,6 @@ main( int argc, char *argv[] ) sighold( SIGHUP ); sigset( SIGTERM, sighandler ); sighold( SIGTERM ); - sigset( SIGPIPE, sighandler ); - sighold( SIGPIPE ); sigset( SIGQUIT, sighandler ); sighold( SIGQUIT ); alarm( 0 ); @@ -596,7 +598,6 @@ main( int argc, char *argv[] ) sigset( SIGINT, sighandler ); sigset( SIGHUP, sighandler ); sigset( SIGTERM, sighandler ); - sigset( SIGPIPE, sighandler ); ok = drive_init2( argc, argv, @@ -804,16 +805,6 @@ main( int argc, char *argv[] ) sigterm_received = BOOL_FALSE; } - /* request a stop on loss of write pipe - */ - if ( sigpipe_received ) { - mlog( MLOG_DEBUG | MLOG_PROC, - "SIGPIPE received\n" ); - stop_requested = BOOL_TRUE; - stop_timeout = STOP_TIMEOUT; - sigpipe_received = BOOL_FALSE; - } - /* operator send SIGQUIT. treat like an interrupt, * but force a core dump */ @@ -889,14 +880,12 @@ main( int argc, char *argv[] ) sigrelse( SIGINT ); sigrelse( SIGHUP ); sigrelse( SIGTERM ); - sigrelse( SIGPIPE ); sigrelse( SIGQUIT ); sigrelse( SIGALRM ); ( void )sigpause( SIGCLD ); sighold( SIGCLD ); sighold( SIGALRM ); sighold( SIGQUIT ); - sighold( SIGPIPE ); sighold( SIGTERM ); sighold( SIGHUP ); sighold( SIGINT ); @@ -1130,11 +1119,9 @@ preemptchk( int flg ) sigrelse( SIGINT ); sigrelse( SIGHUP ); sigrelse( SIGTERM ); - sigrelse( SIGPIPE ); sigrelse( SIGQUIT ); sighold( SIGQUIT ); - sighold( SIGPIPE ); sighold( SIGTERM ); sighold( SIGHUP ); sighold( SIGINT ); @@ -1170,13 +1157,6 @@ preemptchk( int flg ) sigterm_received = BOOL_FALSE; } - if ( sigpipe_received ) { - mlog( MLOG_DEBUG | MLOG_PROC, - "SIGPIPE received\n" ); - preempt_requested = BOOL_TRUE; - sigpipe_received = BOOL_FALSE; - } - if ( sigquit_received ) { mlog( MLOG_DEBUG | MLOG_PROC, "SIGQUIT received (preempt)\n" ); @@ -1602,14 +1582,6 @@ sighandler( int signo ) dlog_desist( ); sigquit_received = BOOL_TRUE; return; - case SIGPIPE: - /* immediately disable further dialogs, - * and ignore subsequent signals - */ - dlog_desist( ); - sigpipe_received = BOOL_TRUE; - ( void )sigset( signo, SIG_IGN ); - return; case SIGALRM: return; default: @@ -1638,14 +1610,6 @@ sighandler( int signo ) /* can get SIGQUIT during dialog: just dismiss */ return; - case SIGPIPE: - /* forward write pipe failures to parent, - * and ignore subsequent failures - */ - dlog_desist( ); - kill( parentpid, SIGPIPE ); - ( void )sigset( signo, SIG_IGN ); - return; case SIGALRM: /* accept and do nothing about alarm signals */ @@ -1678,7 +1642,6 @@ childmain( void *arg1 ) sigset( SIGTERM, SIG_IGN ); sigset( SIGINT, SIG_IGN ); sigset( SIGQUIT, SIG_IGN ); - sigset( SIGPIPE, SIG_IGN ); sigset( SIGALRM, SIG_IGN ); sigset( SIGCLD, SIG_IGN ); diff --git a/common/ring.c b/common/ring.c index f6fc64d3..b132ab9f 100644 --- a/common/ring.c +++ b/common/ring.c @@ -412,7 +412,6 @@ ring_slave_entry( void *ringctxp ) sigset( SIGHUP, SIG_IGN ); sigset( SIGINT, SIG_IGN ); sigset( SIGQUIT, SIG_IGN ); - sigset( SIGPIPE, SIG_IGN ); sigset( SIGALRM, SIG_IGN ); sigset( SIGCLD, SIG_IGN ); diff --git a/librmt/rmtcommand.c b/librmt/rmtcommand.c index 42587e4e..fbd7a6ac 100644 --- a/librmt/rmtcommand.c +++ b/librmt/rmtcommand.c @@ -21,7 +21,6 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <signal.h> #include <errno.h> #include "rmtlib.h" @@ -36,19 +35,16 @@ int fildes; char *buf; { register int blen; - void (*pstat)(); _rmt_msg(RMTDBG, "rmtcommand: fd = %d, buf = %s\n", fildes, buf); /* - * save current pipe status and try to make the request + * try to make the request */ blen = strlen(buf); - pstat = signal(SIGPIPE, SIG_IGN); if (write(WRITE(fildes), buf, blen) == blen) { - signal(SIGPIPE, pstat); return(0); } @@ -56,7 +52,6 @@ char *buf; * something went wrong. close down and go home */ - signal(SIGPIPE, pstat); _rmt_abort(fildes); setoserror( EIO ); diff --git a/librmt/rmtwrite.c b/librmt/rmtwrite.c index 7f373eea..c42b1abe 100644 --- a/librmt/rmtwrite.c +++ b/librmt/rmtwrite.c @@ -21,7 +21,6 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <signal.h> #include <errno.h> #include "rmtlib.h" @@ -55,20 +54,16 @@ unsigned int nbyte; static int _rmt_write(int fildes, char *buf, unsigned int nbyte) { char buffer[BUFMAGIC]; - void (*pstat)(); sprintf(buffer, "W%d\n", nbyte); if (_rmt_command(fildes, buffer) == -1) return(-1); - pstat = signal(SIGPIPE, SIG_IGN); if (write(WRITE(fildes), buf, nbyte) == nbyte) { - signal (SIGPIPE, pstat); return(_rmt_status(fildes)); } - signal (SIGPIPE, pstat); _rmt_abort(fildes); setoserror( EIO ); return(-1); |