]> gitweb.factorcode.org Git - factor.git/commitdiff
Change how SIGPIPE is ignored, and add a unit test to io.launcher.unix to ensure...
authorSlava Pestov <slava@user-64-9-233-160.googlewifi.com>
Fri, 3 Sep 2010 05:11:45 +0000 (22:11 -0700)
committerSlava Pestov <slava@user-64-9-233-160.googlewifi.com>
Fri, 3 Sep 2010 05:11:45 +0000 (22:11 -0700)
basis/io/launcher/unix/unix-tests.factor
vm/os-unix.cpp
vm/os-unix.hpp

index fef6b076ba2f9890a739ec403df326a6709575fc..44c67b1bab2a3e94d3f5ecc36b07460172bbbd30 100644 (file)
@@ -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
index 1916dcc86f502a4b70892090952f770398b45ad6..2e4aed436e6465acf0a2ac49730789f33dde461a 100755 (executable)
@@ -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);
 }
 
index c774707a767951ee0a9ecfe2efb81d632c13c7ae..2c7dde9c617d3ece6d0a2007964987cb92619513 100644 (file)
@@ -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();