Hi/2. Bruno Haible wrote: > KO Myung-Hun wrote: >> LIBCx is the kLIBC extension library which provides some enhanced >> features to OS/2 kLIBC. >> >> It provides its own waitpid() to support its spawn2(). Use it if >> possible. >> >> * lib/wait-process.c (klibc_waitpid) [kLIBC]: New function. >> (waitpid) [kLIBC]: Define it to klibc_waitpid. > > The code looks good, but lacks comments. In the ChangeLog or git commit > entry, please state *what* has changed, not *why* or *how* the code works. > The *why* and *how* belong in comments. >
How about this? -- KO Myung-Hun Korean OS/2 User Community : https://www.os2.kr/
From 6eb8f9718c78e2090b73593f6b2b02c41eba7760 Mon Sep 17 00:00:00 2001 From: KO Myung-Hun <komh78@gmail.com> Date: Thu, 19 Sep 2024 22:45:04 +0900 Subject: [PATCH v3] wait-process: Use waitpid() of LIBCx on OS/2 kLIBC if avilable Try to use waitpid() of LIBCx first. * lib/wait-process.c (klibc_waitpid) [kLIBC]: New function. (waitpid) [kLIBC]: Define it to klibc_waitpid. --- lib/wait-process.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/wait-process.c b/lib/wait-process.c index afb88ebe23..76fe83c521 100644 --- a/lib/wait-process.c +++ b/lib/wait-process.c @@ -194,6 +194,41 @@ unregister_slave_subprocess (pid_t child) s->used = 0; } +#ifdef __KLIBC__ +# include <dlfcn.h> + +# undef waitpid + +/* Replacement of waitpid() to support spawn2() of LIBCx which is the kLIBC + extension library. See for details: + <https://github.com/bitwiseworks/libcx/blob/master/src/spawn/libcx/spawn2.h#L194>. + */ +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 + /* Wait for a subprocess to finish. Return its exit code. If it didn't terminate correctly, exit if exit_on_error is true, otherwise -- 2.42.0