From 5cc97a4d1b8e8685cf53c9bf0a3d19bea99a428d Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sun, 15 Mar 2020 17:18:37 -0500 Subject: [PATCH] unix.process: Add posix_spawn stub. 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 | 29 +++++++++++++++++++++++++++-- basis/unix/types/linux/linux.factor | 3 +++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/basis/unix/process/process.factor b/basis/unix/process/process.factor index b33b824a73..de63b8449c 100644 --- a/basis/unix/process/process.factor +++ b/basis/unix/process/process.factor @@ -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 ] 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 ; diff --git a/basis/unix/types/linux/linux.factor b/basis/unix/types/linux/linux.factor index 9380e50d84..c5de4c2c92 100644 --- a/basis/unix/types/linux/linux.factor +++ b/basis/unix/types/linux/linux.factor @@ -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