]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/io/launcher/unix/unix.factor
Updating code to use with-out-parameters
[factor.git] / basis / io / launcher / unix / unix.factor
index 5424ab423823c3d4bc0e88670cfd66a9673c66fb..e036f34cc600bb1bde297bb206259867791b92d5 100644 (file)
@@ -1,15 +1,15 @@
-! Copyright (C) 2007, 2008 Slava Pestov.
+! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays assocs combinators
-continuations environment io io.backend io.backend.unix
-io.files io.files.private io.files.unix io.launcher
-io.launcher.unix.parser io.pathnames io.ports kernel math
-namespaces sequences strings system threads unix
-unix.process ;
+USING: accessors alien.c-types alien.data arrays assocs
+combinators continuations environment io io.backend
+io.backend.unix io.files io.files.private io.files.unix
+io.launcher io.pathnames io.ports kernel math namespaces
+sequences strings system threads unix unix.process unix.ffi
+simple-tokenizer ;
 IN: io.launcher.unix
 
 : get-arguments ( process -- seq )
-    command>> dup string? [ tokenize-command ] when ;
+    command>> dup string? [ tokenize ] when ;
 
 : assoc>env ( assoc -- env )
     [ "=" glue ] { } assoc>map ;
@@ -69,12 +69,13 @@ IN: io.launcher.unix
     ] when ;
 
 : spawn-process ( process -- * )
-    [ setup-priority ] [ 250 _exit ] recover
-    [ setup-redirection ] [ 251 _exit ] recover
-    [ current-directory get (normalize-path) cd ] [ 252 _exit ] recover
-    [ setup-environment ] [ 253 _exit ] recover
-    [ get-arguments exec-args-with-path ] [ 254 _exit ] recover
-    255 _exit ;
+    [ setup-priority ] [ 2drop 250 _exit ] recover
+    [ setup-redirection ] [ 2drop 251 _exit ] recover
+    [ current-directory get absolute-path cd ] [ 2drop 252 _exit ] recover
+    [ setup-environment ] [ 2drop 253 _exit ] recover
+    [ get-arguments exec-args-with-path ] [ 2drop 254 _exit ] recover
+    255 _exit
+    f throw ;
 
 M: unix current-process-handle ( -- handle ) getpid ;
 
@@ -91,13 +92,13 @@ M: unix kill-process* ( pid -- )
 TUPLE: signal n ;
 
 : code>status ( code -- obj )
-    dup WIFEXITED [ WEXITSTATUS ] [ WTERMSIG signal boa ] if ;
+    dup WIFSIGNALED [ WTERMSIG signal boa ] [ WEXITSTATUS ] if ;
 
 M: unix wait-for-processes ( -- ? )
-    0 <int> -1 over WNOHANG waitpid
-    dup 0 <= [
+    { int } [ -1 swap WNOHANG waitpid ] [ ] with-out-parameters
+    swap dup 0 <= [
         2drop t
     ] [
         find-process dup
-        [ swap *int code>status notify-exit f ] [ 2drop f ] if
+        [ swap code>status notify-exit f ] [ 2drop f ] if
     ] if ;