Skip to content

Commit f98b087

Browse files
committed
New libc function posix_xspawn_np(3)
Wholly non-portable function that allows you to specify a custom exec function that will get invoked within the context of a (probably vfork'd) child process **after** all other `file_actions` and `attrp` have already been applied (essentially allowing you to do something other than calling `exec` (or one of its friends) once the new child process was set-up)
1 parent e8081be commit f98b087

File tree

16 files changed

+318
-84
lines changed

16 files changed

+318
-84
lines changed

kos/include/bits/posix_opt.h

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

kos/include/i386-kos/crt-features/crt-kos32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4549,6 +4549,7 @@
45494549
#define __CRT_HAVE_pidfd_fspawn_np
45504550
#define __CRT_HAVE_pidfd_spawn
45514551
#define __CRT_HAVE_pidfd_spawnp
4552+
#define __CRT_HAVE_pidfd_xspawn_np
45524553
#define __CRT_HAVE_pipe
45534554
#define __CRT_HAVE_pipe2
45544555
#define __CRT_HAVE_pkey_alloc
@@ -4597,6 +4598,7 @@
45974598
#define __CRT_HAVE_posix_spawnattr_setsigdefault
45984599
#define __CRT_HAVE_posix_spawnattr_setsigmask
45994600
#define __CRT_HAVE_posix_spawnp
4601+
#define __CRT_HAVE_posix_xspawn_np
46004602
#define __CRT_HAVE_pow
46014603
#define __CRT_HAVE_pow10
46024604
#define __CRT_HAVE_pow10f

kos/include/i386-kos/crt-features/crt-kos64.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,6 +4232,7 @@
42324232
#define __CRT_HAVE_pidfd_fspawn_np
42334233
#define __CRT_HAVE_pidfd_spawn
42344234
#define __CRT_HAVE_pidfd_spawnp
4235+
#define __CRT_HAVE_pidfd_xspawn_np
42354236
#define __CRT_HAVE_pipe
42364237
#define __CRT_HAVE_pipe2
42374238
#define __CRT_HAVE_pkey_alloc
@@ -4280,6 +4281,7 @@
42804281
#define __CRT_HAVE_posix_spawnattr_setsigdefault
42814282
#define __CRT_HAVE_posix_spawnattr_setsigmask
42824283
#define __CRT_HAVE_posix_spawnp
4284+
#define __CRT_HAVE_posix_xspawn_np
42834285
#define __CRT_HAVE_pow
42844286
#define __CRT_HAVE_pow10
42854287
#define __CRT_HAVE_pow10f
@@ -10221,6 +10223,7 @@
1022110223
#define __CRT_HAVE_KOS$pidfd_fspawn_np
1022210224
#define __CRT_HAVE_KOS$pidfd_spawn
1022310225
#define __CRT_HAVE_KOS$pidfd_spawnp
10226+
#define __CRT_HAVE_KOS$pidfd_xspawn_np
1022410227
#define __CRT_HAVE_KOS$pipe
1022510228
#define __CRT_HAVE_KOS$pipe2
1022610229
#define __CRT_HAVE_KOS$pkey_alloc
@@ -10269,6 +10272,7 @@
1026910272
#define __CRT_HAVE_KOS$posix_spawnattr_setsigdefault
1027010273
#define __CRT_HAVE_KOS$posix_spawnattr_setsigmask
1027110274
#define __CRT_HAVE_KOS$posix_spawnp
10275+
#define __CRT_HAVE_KOS$posix_xspawn_np
1027210276
#define __CRT_HAVE_KOS$pow
1027310277
#define __CRT_HAVE_KOS$pow10
1027410278
#define __CRT_HAVE_KOS$pow10f
@@ -15181,6 +15185,7 @@
1518115185
#define __CRT_HAVE_DOS$pidfd_fspawn_np
1518215186
#define __CRT_HAVE_DOS$pidfd_spawn
1518315187
#define __CRT_HAVE_DOS$pidfd_spawnp
15188+
#define __CRT_HAVE_DOS$pidfd_xspawn_np
1518415189
#define __CRT_HAVE_DOS$pipe
1518515190
#define __CRT_HAVE_DOS$pipe2
1518615191
#define __CRT_HAVE_DOS$pkey_alloc
@@ -15229,6 +15234,7 @@
1522915234
#define __CRT_HAVE_DOS$posix_spawnattr_setsigdefault
1523015235
#define __CRT_HAVE_DOS$posix_spawnattr_setsigmask
1523115236
#define __CRT_HAVE_DOS$posix_spawnp
15237+
#define __CRT_HAVE_DOS$posix_xspawn_np
1523215238
#define __CRT_HAVE_DOS$pow
1523315239
#define __CRT_HAVE_DOS$pow10
1523415240
#define __CRT_HAVE_DOS$pow10f

kos/include/libc/local/spawn/posix_fspawn_np.h

Lines changed: 10 additions & 17 deletions
Large diffs are not rendered by default.

kos/include/libc/local/spawn/posix_spawn.h

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

kos/include/libc/local/spawn/posix_spawn_child.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* HASH CRC-32:0xcbef8e31 */
1+
/* HASH CRC-32:0x33b9c38a */
22
/* Copyright (c) 2019-2025 Griefer@Work *
33
* *
44
* This software is provided 'as-is', without any express or implied *
@@ -826,9 +826,15 @@ __NOTHROW_RPC(__LIBCCALL __LIBC_LOCAL_NAME(posix_spawn_child))(unsigned int __ex
826826
(__NAMESPACE_LOCAL_SYM __localdep_fexecve)((__fd_t)(__UINTPTR_TYPE__)__exec_arg, ___argv, ___envp);
827827
break;
828828
#endif /* __CRT_HAVE_fexecve || (__OS_HAVE_PROCFS_SELF_FD && (__CRT_HAVE_execve || __CRT_HAVE__execve || __CRT_HAVE___execve || __CRT_HAVE___libc_execve)) */
829-
case 3:
830-
(*(void (__LIBCCALL *)(char **, char **))__exec_arg)((char **)___argv, (char **)___envp);
831-
break;
829+
case 3: {
830+
__errno_t __error;
831+
__error = (*(__errno_t (__LIBCCALL *)(void *))__exec_arg)((void *)___argv);
832+
#ifdef __POSIX_SPAWN_NOEXECERR
833+
if (__attrp && __attrp->__flags & __POSIX_SPAWN_NOEXECERR)
834+
__error = 0; /* Suppress the exec error. */
835+
#endif /* __POSIX_SPAWN_NOEXECERR */
836+
return __error;
837+
} break;
832838
default: __builtin_unreachable();
833839
}
834840

kos/include/libc/local/spawn/posix_spawn_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* HASH CRC-32:0x105182eb */
1+
/* HASH CRC-32:0x20650686 */
22
/* Copyright (c) 2019-2025 Griefer@Work *
33
* *
44
* This software is provided 'as-is', without any express or implied *
@@ -26,7 +26,7 @@
2626
#include <asm/os/features.h>
2727
#include <hybrid/__alloca.h>
2828
#include <libc/template/environ.h>
29-
#if ((defined(__ARCH_HAVE_SHARED_VM_VFORK) && (defined(__CRT_HAVE_vfork) || defined(__CRT_HAVE___vfork) || defined(__CRT_HAVE___libc_vfork))) || ((defined(__CRT_HAVE_fork) || defined(__CRT_HAVE___fork) || defined(__CRT_HAVE___libc_fork)) && (defined(__CRT_HAVE_pipe2) || defined(__CRT_HAVE_pipe) || defined(__CRT_HAVE___pipe) || defined(__CRT_HAVE___libc_pipe) || defined(__CRT_HAVE__pipe)) && defined(__O_CLOEXEC) && (defined(__CRT_HAVE_read) || defined(__CRT_HAVE__read) || defined(__CRT_HAVE___read) || defined(__CRT_HAVE___libc_read)) && (defined(__CRT_HAVE_write) || defined(__CRT_HAVE__write) || defined(__CRT_HAVE___write) || defined(__CRT_HAVE___libc_write)) && (defined(__CRT_HAVE_close) || defined(__CRT_HAVE__close) || defined(__CRT_HAVE___close) || defined(__CRT_HAVE___libc_close)))) && defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_fexecve) || defined(__CRT_HAVE_execve) || defined(__CRT_HAVE__execve) || defined(__CRT_HAVE___execve) || defined(__CRT_HAVE___libc_execve) || defined(__CRT_HAVE_execvpe) || defined(__CRT_HAVE__execvpe)) && (defined(__CRT_HAVE_waitpid) || defined(__CRT_HAVE___waitpid))
29+
#if ((defined(__ARCH_HAVE_SHARED_VM_VFORK) && (defined(__CRT_HAVE_vfork) || defined(__CRT_HAVE___vfork) || defined(__CRT_HAVE___libc_vfork))) || ((defined(__CRT_HAVE_fork) || defined(__CRT_HAVE___fork) || defined(__CRT_HAVE___libc_fork)) && (defined(__CRT_HAVE_read) || defined(__CRT_HAVE__read) || defined(__CRT_HAVE___read) || defined(__CRT_HAVE___libc_read)) && (defined(__CRT_HAVE_write) || defined(__CRT_HAVE__write) || defined(__CRT_HAVE___write) || defined(__CRT_HAVE___libc_write)) && (defined(__CRT_HAVE_close) || defined(__CRT_HAVE__close) || defined(__CRT_HAVE___close) || defined(__CRT_HAVE___libc_close)) && (defined(__CRT_HAVE_pipe2) || defined(__CRT_HAVE_pipe) || defined(__CRT_HAVE___pipe) || defined(__CRT_HAVE___libc_pipe) || defined(__CRT_HAVE__pipe)) && defined(__O_CLOEXEC))) && defined(__POSIX_SPAWN_USE_KOS) && (defined(__CRT_HAVE_fexecve) || defined(__CRT_HAVE_execve) || defined(__CRT_HAVE__execve) || defined(__CRT_HAVE___execve) || defined(__CRT_HAVE___libc_execve) || defined(__CRT_HAVE_execvpe) || defined(__CRT_HAVE__execvpe)) && (defined(__CRT_HAVE_waitpid) || defined(__CRT_HAVE___waitpid))
3030
#include <bits/crt/posix_spawn.h>
3131
#include <bits/types.h>
3232
#include <features.h>
@@ -269,7 +269,7 @@ __NAMESPACE_LOCAL_END
269269
#define __local___localdep_posix_spawn_impl_defined
270270
#define __localdep_posix_spawn_impl __LIBC_LOCAL_NAME(posix_spawn_impl)
271271
#endif /* !__local___localdep_posix_spawn_impl_defined */
272-
#else /* ((__ARCH_HAVE_SHARED_VM_VFORK && (__CRT_HAVE_vfork || __CRT_HAVE___vfork || __CRT_HAVE___libc_vfork)) || ((__CRT_HAVE_fork || __CRT_HAVE___fork || __CRT_HAVE___libc_fork) && (__CRT_HAVE_pipe2 || __CRT_HAVE_pipe || __CRT_HAVE___pipe || __CRT_HAVE___libc_pipe || __CRT_HAVE__pipe) && __O_CLOEXEC && (__CRT_HAVE_read || __CRT_HAVE__read || __CRT_HAVE___read || __CRT_HAVE___libc_read) && (__CRT_HAVE_write || __CRT_HAVE__write || __CRT_HAVE___write || __CRT_HAVE___libc_write) && (__CRT_HAVE_close || __CRT_HAVE__close || __CRT_HAVE___close || __CRT_HAVE___libc_close))) && __POSIX_SPAWN_USE_KOS && (__CRT_HAVE_fexecve || __CRT_HAVE_execve || __CRT_HAVE__execve || __CRT_HAVE___execve || __CRT_HAVE___libc_execve || __CRT_HAVE_execvpe || __CRT_HAVE__execvpe) && (__CRT_HAVE_waitpid || __CRT_HAVE___waitpid) */
272+
#else /* ((__ARCH_HAVE_SHARED_VM_VFORK && (__CRT_HAVE_vfork || __CRT_HAVE___vfork || __CRT_HAVE___libc_vfork)) || ((__CRT_HAVE_fork || __CRT_HAVE___fork || __CRT_HAVE___libc_fork) && (__CRT_HAVE_read || __CRT_HAVE__read || __CRT_HAVE___read || __CRT_HAVE___libc_read) && (__CRT_HAVE_write || __CRT_HAVE__write || __CRT_HAVE___write || __CRT_HAVE___libc_write) && (__CRT_HAVE_close || __CRT_HAVE__close || __CRT_HAVE___close || __CRT_HAVE___libc_close) && (__CRT_HAVE_pipe2 || __CRT_HAVE_pipe || __CRT_HAVE___pipe || __CRT_HAVE___libc_pipe || __CRT_HAVE__pipe) && __O_CLOEXEC)) && __POSIX_SPAWN_USE_KOS && (__CRT_HAVE_fexecve || __CRT_HAVE_execve || __CRT_HAVE__execve || __CRT_HAVE___execve || __CRT_HAVE___libc_execve || __CRT_HAVE_execvpe || __CRT_HAVE__execvpe) && (__CRT_HAVE_waitpid || __CRT_HAVE___waitpid) */
273273
#undef __local_posix_spawn_impl_defined
274-
#endif /* ((!__ARCH_HAVE_SHARED_VM_VFORK || (!__CRT_HAVE_vfork && !__CRT_HAVE___vfork && !__CRT_HAVE___libc_vfork)) && ((!__CRT_HAVE_fork && !__CRT_HAVE___fork && !__CRT_HAVE___libc_fork) || (!__CRT_HAVE_pipe2 && !__CRT_HAVE_pipe && !__CRT_HAVE___pipe && !__CRT_HAVE___libc_pipe && !__CRT_HAVE__pipe) || !__O_CLOEXEC || (!__CRT_HAVE_read && !__CRT_HAVE__read && !__CRT_HAVE___read && !__CRT_HAVE___libc_read) || (!__CRT_HAVE_write && !__CRT_HAVE__write && !__CRT_HAVE___write && !__CRT_HAVE___libc_write) || (!__CRT_HAVE_close && !__CRT_HAVE__close && !__CRT_HAVE___close && !__CRT_HAVE___libc_close))) || !__POSIX_SPAWN_USE_KOS || (!__CRT_HAVE_fexecve && !__CRT_HAVE_execve && !__CRT_HAVE__execve && !__CRT_HAVE___execve && !__CRT_HAVE___libc_execve && !__CRT_HAVE_execvpe && !__CRT_HAVE__execvpe) || (!__CRT_HAVE_waitpid && !__CRT_HAVE___waitpid) */
274+
#endif /* ((!__ARCH_HAVE_SHARED_VM_VFORK || (!__CRT_HAVE_vfork && !__CRT_HAVE___vfork && !__CRT_HAVE___libc_vfork)) && ((!__CRT_HAVE_fork && !__CRT_HAVE___fork && !__CRT_HAVE___libc_fork) || (!__CRT_HAVE_read && !__CRT_HAVE__read && !__CRT_HAVE___read && !__CRT_HAVE___libc_read) || (!__CRT_HAVE_write && !__CRT_HAVE__write && !__CRT_HAVE___write && !__CRT_HAVE___libc_write) || (!__CRT_HAVE_close && !__CRT_HAVE__close && !__CRT_HAVE___close && !__CRT_HAVE___libc_close) || (!__CRT_HAVE_pipe2 && !__CRT_HAVE_pipe && !__CRT_HAVE___pipe && !__CRT_HAVE___libc_pipe && !__CRT_HAVE__pipe) || !__O_CLOEXEC)) || !__POSIX_SPAWN_USE_KOS || (!__CRT_HAVE_fexecve && !__CRT_HAVE_execve && !__CRT_HAVE__execve && !__CRT_HAVE___execve && !__CRT_HAVE___libc_execve && !__CRT_HAVE_execvpe && !__CRT_HAVE__execvpe) || (!__CRT_HAVE_waitpid && !__CRT_HAVE___waitpid) */
275275
#endif /* !__local_posix_spawn_impl_defined */

0 commit comments

Comments
 (0)