Imported Upstream version 1.4.19
[platform/upstream/m4.git] / tests / test-posix_spawn-dup2-stdin.c
similarity index 84%
rename from tests/test-posix_spawn2.c
rename to tests/test-posix_spawn-dup2-stdin.c
index 041e0bb..8184f2c 100644 (file)
@@ -1,5 +1,5 @@
-/* Test of posix_spawn() function.
-   Copyright (C) 2008-2016 Free Software Foundation, Inc.
+/* Test of posix_spawn() function: writing to a subprocess.
+   Copyright (C) 2008-2021 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,7 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2008.  */
 
@@ -31,9 +31,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-extern char **environ;
-
-#define CHILD_PROGRAM_FILENAME "test-posix_spawn2.sh"
+#define CHILD_PROGRAM_FILENAME "test-posix_spawn-dup2-stdin.sh"
 
 static int
 fd_safer (int fd)
@@ -53,7 +51,7 @@ fd_safer (int fd)
 int
 main ()
 {
-  char *argv[3] = { (char *) "/bin/sh", (char *) CHILD_PROGRAM_FILENAME, NULL };
+  char *argv[3] = { (char *) BOURNE_SHELL, (char *) CHILD_PROGRAM_FILENAME, NULL };
   int ofd[2];
   sigset_t blocked_signals;
   sigset_t fatal_signal_set;
@@ -78,8 +76,12 @@ main ()
   sigemptyset (&fatal_signal_set);
   sigaddset (&fatal_signal_set, SIGINT);
   sigaddset (&fatal_signal_set, SIGTERM);
+  #ifdef SIGHUP
   sigaddset (&fatal_signal_set, SIGHUP);
+  #endif
+  #ifdef SIGPIPE
   sigaddset (&fatal_signal_set, SIGPIPE);
+  #endif
   sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
   actions_allocated = false;
   attrs_allocated = false;
@@ -90,9 +92,14 @@ main ()
           || (err = posix_spawn_file_actions_addclose (&actions, ofd[1])) != 0
           || (err = posix_spawnattr_init (&attrs)) != 0
           || (attrs_allocated = true,
+              #if defined _WIN32 && !defined __CYGWIN__
+              0
+              #else
               (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
-              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0)
-          || (err = posix_spawnp (&child, "/bin/sh", &actions, &attrs, argv, environ)) != 0))
+              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0
+              #endif
+             )
+          || (err = posix_spawnp (&child, BOURNE_SHELL, &actions, &attrs, argv, environ)) != 0))
     {
       if (actions_allocated)
         posix_spawn_file_actions_destroy (&actions);