diff --git a/basis/io/launcher/unix/unix-tests.factor b/basis/io/launcher/unix/unix-tests.factor index fef6b076ba..44c67b1bab 100644 --- a/basis/io/launcher/unix/unix-tests.factor +++ b/basis/io/launcher/unix/unix-tests.factor @@ -3,7 +3,8 @@ USING: io.files io.files.temp io.directories io.pathnames tools.test io.launcher arrays io namespaces continuations math io.encodings.binary io.encodings.ascii accessors kernel sequences io.encodings.utf8 destructors io.streams.duplex locals -concurrency.promises threads unix.process calendar unix ; +concurrency.promises threads unix.process calendar unix +unix.process debugger.unix io.timeouts io.launcher.unix ; [ ] [ [ "launcher-test-1" temp-file delete-file ] ignore-errors @@ -138,3 +139,21 @@ concurrency.promises threads unix.process calendar unix ; s 3 seconds ?promise-timeout 0 = ] ] unit-test + +! Make sure that subprocesses don't inherit our signal mask + +! First, ensure that the Factor VM ignores SIGPIPE +: send-sigpipe ( pid -- ) + "SIGPIPE" signal-names index 1 + + kill io-error ; + +[ ] [ current-process-handle send-sigpipe ] unit-test + +! Spawn a process +[ T{ signal f 13 } ] [ + "sleep 1000" run-detached + [ handle>> send-sigpipe ] + [ 2 seconds swap set-timeout ] + [ wait-for-process ] + tri +] unit-test diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index 1916dcc86f..2e4aed436e 100755 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -135,6 +135,10 @@ void misc_signal_handler(int signal, siginfo_t *siginfo, void *uap) vm->dispatch_signal(uap,factor::misc_signal_handler_impl); } +void ignore_signal_handler(int signal, siginfo_t *siginfo, void *uap) +{ +} + void fpe_signal_handler(int signal, siginfo_t *siginfo, void *uap) { factor_vm *vm = current_vm(); @@ -206,9 +210,13 @@ void factor_vm::unix_init_signals() sigaction_safe(SIGQUIT,&misc_sigaction,NULL); sigaction_safe(SIGILL,&misc_sigaction,NULL); + /* We don't use SA_IGN here because then the ignore action is inherited + by subprocesses, which we don't want. There is a unit test in + io.launcher.unix for this. */ memset(&ignore_sigaction,0,sizeof(struct sigaction)); sigemptyset(&ignore_sigaction.sa_mask); - ignore_sigaction.sa_handler = SIG_IGN; + ignore_sigaction.sa_sigaction = ignore_signal_handler; + ignore_sigaction.sa_flags = SA_SIGINFO | SA_ONSTACK; sigaction_safe(SIGPIPE,&ignore_sigaction,NULL); } diff --git a/vm/os-unix.hpp b/vm/os-unix.hpp index c774707a76..2c7dde9c61 100644 --- a/vm/os-unix.hpp +++ b/vm/os-unix.hpp @@ -37,9 +37,6 @@ typedef pthread_t THREADHANDLE; THREADHANDLE start_thread(void *(*start_routine)(void *),void *args); inline static THREADHANDLE thread_id() { return pthread_self(); } -void signal_handler(int signal, siginfo_t* siginfo, void* uap); -void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap); - u64 nano_count(); void sleep_nanos(u64 nsec); void open_console();