]> Savannah Git Hosting - gnulib.git/commitdiff
spawn-pipe: Use posix_spawn by default on native Windows.
authorBruno Haible <bruno@clisp.org>
Fri, 25 Dec 2020 01:16:22 +0000 (02:16 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 25 Dec 2020 01:18:55 +0000 (02:18 +0100)
* lib/spawn-pipe.c (SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN): New macro.
(create_pipe): Use it to decide among the two possible implementations.
* modules/spawn-pipe (Depends-on): Add posix_spawnattr_setpgroup.

ChangeLog
lib/spawn-pipe.c
modules/spawn-pipe

index 3d8478aebd8044512f92f7581268c9809f0ce614..8f27b286efa7d9a1388cd7773050e671a7786094 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-12-24  Bruno Haible  <bruno@clisp.org>
+
+       spawn-pipe: Use posix_spawn by default on native Windows.
+       * lib/spawn-pipe.c (SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN): New macro.
+       (create_pipe): Use it to decide among the two possible implementations.
+       * modules/spawn-pipe (Depends-on): Add posix_spawnattr_setpgroup.
+
 2020-12-24  Bruno Haible  <bruno@clisp.org>
 
        unistd-safer: Implement pipe_safer on native Windows.
index aedbcb2ae5ce6010d1e66dc14998a3677a94a4a2..768c8b67a88e6d9a95eab568baf6cbb2244224a8 100644 (file)
 
 #define _(str) gettext (str)
 
-#if defined _WIN32 && ! defined __CYGWIN__
+
+/* Choice of implementation for native Windows.
+   - Define to 0 to use the posix_spawn facility (modules 'posix_spawn' and
+     'posix_spawnp'), that is based on the module 'windows-spawn'.
+   - Define to 1 to use the older code, that uses the module 'windows-spawn'
+     directly.
+   You can set this macro from a Makefile or at configure time, from the
+   CPPFLAGS.  */
+#ifndef SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN
+# define SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN 0
+#endif
+
+
+#if (defined _WIN32 && !defined __CYGWIN__) && SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN
 
 /* Native Windows API.  */
 # if GNULIB_MSVC_NOTHROW
@@ -89,7 +102,7 @@ nonintr_close (int fd)
 #undef close /* avoid warning related to gnulib module unistd */
 #define close nonintr_close
 
-#if defined _WIN32 && ! defined __CYGWIN__
+#if (defined _WIN32 && !defined __CYGWIN__) && SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN
 static int
 nonintr_open (const char *pathname, int oflag, mode_t mode)
 {
@@ -181,7 +194,7 @@ create_pipe (const char *progname,
         }
     }
 
-#if (defined _WIN32 && ! defined __CYGWIN__) || defined __KLIBC__
+#if ((defined _WIN32 && !defined __CYGWIN__) && SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN) || defined __KLIBC__
 
   /* Native Windows API.
      This uses _pipe(), dup2(), and _spawnv().  It could also be implemented
@@ -217,7 +230,7 @@ create_pipe (const char *progname,
 
   child = -1;
 
-# if defined _WIN32 && ! defined __CYGWIN__
+# if (defined _WIN32 && !defined __CYGWIN__) && SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN
   bool must_close_ifd1 = pipe_stdout;
   bool must_close_ofd0 = pipe_stdin;
 
@@ -512,12 +525,20 @@ create_pipe (const char *progname,
           || (slave_process
               && ((err = posix_spawnattr_init (&attrs)) != 0
                   || (attrs_allocated = true,
+# if defined _WIN32 && !defined __CYGWIN__
+                      (err = posix_spawnattr_setpgroup (&attrs, 0)) != 0
+                      || (err = posix_spawnattr_setflags (&attrs,
+                                                         POSIX_SPAWN_SETPGROUP))
+                         != 0
+# else
                       (err = posix_spawnattr_setsigmask (&attrs,
                                                          &blocked_signals))
                       != 0
                       || (err = posix_spawnattr_setflags (&attrs,
                                                         POSIX_SPAWN_SETSIGMASK))
-                         != 0)))
+                         != 0
+# endif
+             )   )   )
           || (err = (directory != NULL
                      ? posix_spawn (&child, prog_path, &actions,
                                     attrs_allocated ? &attrs : NULL,
index 7ad384b524adc2f97b0d2ffa7007fc25072c2f55..f0e8dafc17821f695c67f6e470d86c164414a518 100644 (file)
@@ -31,6 +31,7 @@ posix_spawn_file_actions_addopen
 posix_spawn_file_actions_addchdir
 posix_spawn_file_actions_destroy
 posix_spawnattr_init
+posix_spawnattr_setpgroup
 posix_spawnattr_setsigmask
 posix_spawnattr_setflags
 posix_spawnattr_destroy