From f165b45c2c2f702ca63b58c4eda154afaba7ec7a Mon Sep 17 00:00:00 2001 From: KO Myung-Hun Date: Thu, 19 Sep 2024 22:45:04 +0900 Subject: [PATCH] wait-process: Use waitpid() of LIBCx on OS/2 kLIBC if available. * lib/wait-process.c (klibc_waitpid) [kLIBC]: New function. (waitpid) [kLIBC]: Define it to klibc_waitpid. --- ChangeLog | 6 ++++++ lib/wait-process.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/ChangeLog b/ChangeLog index ac8e65ecb9..56c270222d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-09-20 KO Myung-Hun + + wait-process: Use waitpid() of LIBCx on OS/2 kLIBC if available. + * lib/wait-process.c (klibc_waitpid) [kLIBC]: New function. + (waitpid) [kLIBC]: Define it to klibc_waitpid. + 2024-09-19 Bruno Haible spawn-pipe: Simplify. diff --git a/lib/wait-process.c b/lib/wait-process.c index afb88ebe23..f424e1bc74 100644 --- a/lib/wait-process.c +++ b/lib/wait-process.c @@ -50,6 +50,41 @@ #endif +#ifdef __KLIBC__ +# include + +# undef waitpid + +/* Replacement of waitpid() to support spawn2() of LIBCx which is the kLIBC + extension library. See for details: + . + */ +static pid_t +klibc_waitpid (pid_t pid, int *statusp, int options) +{ + static pid_t (*waitpid_pfn) (pid_t, int *, int) = NULL; + + if (waitpid_pfn == NULL) + { + void *libcx_handle; + + /* Try to use waitpid() of LIBCx first if available because it can + process the return value of spawn-family of kLIBC as well as spawn2() + of LIBCx. */ + libcx_handle = dlopen ("libcx0", RTLD_LAZY); + if (libcx_handle != NULL) + waitpid_pfn = dlsym (libcx_handle, "_waitpid"); + /* If not available, falls back to waitpid() of kLIBC. */ + if (waitpid_pfn == NULL) + waitpid_pfn = waitpid; + } + + return waitpid_pfn (pid, statusp, options); +} + +# define waitpid klibc_waitpid +#endif + /* Type of an entry in the slaves array. The 'used' bit determines whether this entry is currently in use. -- 2.39.5