]> gitweb.factorcode.org Git - factor.git/commitdiff
unix.process: Add posix_spawn stub.
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 15 Mar 2020 22:18:37 +0000 (17:18 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 15 Mar 2020 22:23:21 +0000 (17:23 -0500)
I couldn't get this to work in all cases to replace spawn-process yet.

```
! works
{ "/bin/ls" "-al" } posix-spawn-args-with-path

! Broken on Linux64 for some reason
{
    "/usr/bin/code"
    "-g"
    "-r"
    "/home/erg/factor-master/basis/io/launcher/launcher.factor"
} posix-spawn-args-with-path
```

basis/unix/process/process.factor
basis/unix/types/linux/linux.factor

index b33b824a73a735fcdeebe1469f1b3e38b742967a..de63b8449c3fdf85a48f876d1e07c0acdb01ac8b 100644 (file)
@@ -1,5 +1,6 @@
-USING: alien.c-types alien.data alien.syntax io.encodings.utf8
-kernel libc math sequences unix unix.types unix.utilities ;
+USING: alien.c-types alien.data alien.syntax classes.struct
+generalizations io.encodings.utf8 kernel libc math sequences
+unix unix.types unix.utilities ;
 IN: unix.process
 
 ! Low-level Unix process launching utilities. These are used
@@ -14,6 +15,30 @@ FUNCTION: int execv ( c-string path, c-string* argv )
 FUNCTION: int execvp ( c-string path, c-string* argv )
 FUNCTION: int execve ( c-string path, c-string* argv, c-string* envp )
 
+
+TYPEDEF: void posix_spawn_file_actions_t
+TYPEDEF: void posix_spawnattr_t
+
+FUNCTION: int posix_spawn ( pid_t *pid, c-string path,
+                       posix_spawn_file_actions_t *file_actions,
+                       posix_spawnattr_t *attrp,
+                       c-string* argv, c-string* envp )
+
+FUNCTION: int posix_spawnp ( pid_t *pid, c-string file,
+                       posix_spawn_file_actions_t *file_actions,
+                       posix_spawnattr_t *attrp,
+                       c-string* argv, c-string* envp )
+
+: posix-spawn ( path posix_spawn_file_actions_t* posix_spawnattr_t* argv envp -- pid_t )
+    [ [ 0 pid_t <ref> ] dip utf8 malloc-string ] 4dip
+    [ utf8 strings>alien ] bi@
+    [
+        posix_spawnp dup 0 = [ drop ] [ throw-errno ] if
+    ] 6 nkeep 5drop pid_t deref ;
+
+: posix-spawn-args-with-path ( seq -- int )
+    [ first f f ] keep f posix-spawn ;
+
 : exec ( pathname argv -- int )
     [ utf8 malloc-string ] [ utf8 strings>alien ] bi* execv ;
 
index 9380e50d84ce3d8770bb2ccaa6cd0f2d296e636a..c5de4c2c920187e1ddf03281422728d07ced5c9b 100644 (file)
@@ -6,6 +6,8 @@ TYPEDEF: ulong     __ulongword_type
 TYPEDEF: long      __sword_type
 TYPEDEF: ulong     __uword_type
 TYPEDEF: long      __slongword_type
+TYPEDEF: uint      __u32
+TYPEDEF: ulonglong __u64
 TYPEDEF: uint      __u32_type
 TYPEDEF: int       __s32_type
 
@@ -22,6 +24,7 @@ TYPEDEF: __slongword_type blksize_t
 TYPEDEF: __slongword_type blkcnt_t
 TYPEDEF: __sword_type     ssize_t
 TYPEDEF: __s32_type       pid_t
+TYPEDEF: ulong sigset_t
 TYPEDEF: __slongword_type time_t
 TYPEDEF: __slongword_type __time_t