From 81c0bef366228f216094d21f3b608b9d35fd440a Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Thu, 8 Nov 2007 21:41:36 -0600 Subject: [PATCH] Added exec* words and wait-for-pid to io.unix.launcher --- extra/io/unix/launcher/launcher.factor | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/extra/io/unix/launcher/launcher.factor b/extra/io/unix/launcher/launcher.factor index 7b286feae1..d9490d6725 100644 --- a/extra/io/unix/launcher/launcher.factor +++ b/extra/io/unix/launcher/launcher.factor @@ -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" WNOHANG waitpid + 0 = [ 100 sleep wait-for-pid ] [ drop ] if ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + : with-fork ( quot -- pid ) fork [ zero? -rot if ] keep ; inline