Added exec* words and wait-for-pid to io.unix.launcher
parent
2dad70372d
commit
81c0bef366
|
@ -1,11 +1,36 @@
|
|||
IN: io.unix.launcher
|
||||
|
||||
USING: io io.launcher io.unix.backend io.nonblocking
|
||||
sequences kernel namespaces math system alien.c-types
|
||||
debugger continuations ;
|
||||
|
||||
IN: io.unix.launcher
|
||||
|
||||
! Search unix first
|
||||
USE: unix
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
! Factor friendly versions of the exec functions
|
||||
|
||||
: >argv ( seq -- alien ) [ malloc-char-string ] map f add >c-void*-array ;
|
||||
|
||||
: execv* ( pathname argv -- int ) [ malloc-char-string ] [ >argv ] bi* execv ;
|
||||
: execvp* ( filename argv -- int ) [ malloc-char-string ] [ >argv ] bi* execvp ;
|
||||
|
||||
: execve* ( pathname argv envp -- int )
|
||||
[ malloc-char-string ] [ >argv ] [ >argv ] tri* execve ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
! Wait for a pid to finish without freezing up all the Factor threads.
|
||||
! Need to find a less kludgy way to do this.
|
||||
|
||||
: wait-for-pid ( pid -- )
|
||||
dup "int" <c-object> WNOHANG waitpid
|
||||
0 = [ 100 sleep wait-for-pid ] [ drop ] if ;
|
||||
|
||||
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
: with-fork ( quot -- pid )
|
||||
fork [ zero? -rot if ] keep ; inline
|
||||
|
||||
|
|
Loading…
Reference in New Issue