Added exec* words and wait-for-pid to io.unix.launcher

release
Eduardo Cavazos 2007-11-08 21:41:36 -06:00
parent 2dad70372d
commit 81c0bef366
1 changed files with 26 additions and 1 deletions

View File

@ -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