X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=rts%2Fposix%2FSignals.c;h=493b083401c42a4c8313c3cce92f46f6bfa9309e;hb=337d98de1eaf6689269c9788d1983569a98d46a0;hp=a902b809a5650c7c232ba5c3bf0a6954c66675b1;hpb=10ba2ab9fb729215f5e30654527a5d882a3a01f7;p=ghc-hetmet.git diff --git a/rts/posix/Signals.c b/rts/posix/Signals.c index a902b80..493b083 100644 --- a/rts/posix/Signals.c +++ b/rts/posix/Signals.c @@ -148,7 +148,7 @@ ioManagerStart (void) Capability *cap; if (io_manager_pipe < 0) { cap = rts_lock(); - rts_evalIO(cap,&base_GHCziConc_ensureIOManagerIsRunning_closure,NULL); + cap = rts_evalIO(cap,&base_GHCziConc_ensureIOManagerIsRunning_closure,NULL); rts_unlock(cap); } } @@ -226,14 +226,14 @@ generic_handler(int sig) stg_exit(EXIT_FAILURE); } + MainCapability.context_switch = 1; + #endif /* THREADED_RTS */ // re-establish the signal handler, and carry on sigemptyset(&signals); sigaddset(&signals, sig); sigprocmask(SIG_UNBLOCK, &signals, NULL); - - context_switch = 1; } /* ----------------------------------------------------------------------------- @@ -392,19 +392,19 @@ startSignalHandlers(Capability *cap) #if !defined(THREADED_RTS) void -markSignalHandlers (evac_fn evac) +markSignalHandlers (evac_fn evac, void *user) { StgPtr *p; p = next_pending_handler; while (p != pending_handler_buf) { p--; - evac((StgClosure **)p); + evac(user, (StgClosure **)p); } } #else void -markSignalHandlers (evac_fn evac STG_UNUSED) +markSignalHandlers (evac_fn evac STG_UNUSED, void *user STG_UNUSED) { } #endif @@ -429,24 +429,9 @@ stg_sig_install(StgInt sig STG_UNUSED, * We like to shutdown nicely after receiving a SIGINT, write out the * stats, write profiling info, close open files and flush buffers etc. * -------------------------------------------------------------------------- */ -#ifdef SMP -pthread_t startup_guy; -#endif - static void shutdown_handler(int sig STG_UNUSED) { -#ifdef SMP - // if I'm a worker thread, send this signal to the guy who - // originally called startupHaskell(). Since we're handling - // the signal, it won't be a "send to all threads" type of signal - // (according to the POSIX threads spec). - if (pthread_self() != startup_guy) { - pthread_kill(startup_guy, sig); - return; - } -#endif - // If we're already trying to interrupt the RTS, terminate with // extreme prejudice. So the first ^C tries to exit the program // cleanly, and the second one just kills it. @@ -473,14 +458,10 @@ shutdown_handler(int sig STG_UNUSED) * doesn't seem to do so. * -------------------------------------------------------------------------- */ void -initDefaultHandlers() +initDefaultHandlers(void) { struct sigaction action,oact; -#ifdef SMP - startup_guy = pthread_self(); -#endif - // install the SIGINT handler action.sa_handler = shutdown_handler; sigemptyset(&action.sa_mask); @@ -515,6 +496,33 @@ initDefaultHandlers() #ifdef alpha_HOST_ARCH ieee_set_fp_control(0); #endif + + // ignore SIGPIPE; see #1619 + action.sa_handler = SIG_IGN; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + if (sigaction(SIGPIPE, &action, &oact) != 0) { + sysErrorBelch("warning: failed to install SIGPIPE handler"); + } +} + +void +resetDefaultHandlers(void) +{ + struct sigaction action; + + action.sa_handler = SIG_DFL; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + + // restore SIGINT + if (sigaction(SIGINT, &action, NULL) != 0) { + sysErrorBelch("warning: failed to uninstall SIGINT handler"); + } + // restore SIGPIPE + if (sigaction(SIGPIPE, &action, NULL) != 0) { + sysErrorBelch("warning: failed to uninstall SIGPIPE handler"); + } } void