]> Savannah Git Hosting - gnulib.git/commitdiff
wait-process: Use waitpid() of LIBCx on OS/2 kLIBC if available.
authorKO Myung-Hun <komh78@gmail.com>
Thu, 19 Sep 2024 13:45:04 +0000 (22:45 +0900)
committerBruno Haible <bruno@clisp.org>
Tue, 1 Oct 2024 21:00:43 +0000 (23:00 +0200)
* lib/wait-process.c (klibc_waitpid) [kLIBC]: New function.
(waitpid) [kLIBC]: Define it to klibc_waitpid.

ChangeLog
lib/wait-process.c

index ac8e65ecb9a7dce83ab560ed945c934862e96724..56c270222d115c33ed8f6012161a2151d2d151c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-09-20  KO Myung-Hun  <komh78@gmail.com>
+
+       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  <bruno@clisp.org>
 
        spawn-pipe: Simplify.
index afb88ebe236ecdca9bb46f04a32c5b7c1a1203b8..f424e1bc74759efb956177c22272a7469247e97b 100644 (file)
 
 #endif
 
+#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
+
 
 /* Type of an entry in the slaves array.
    The 'used' bit determines whether this entry is currently in use.