]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sysdeps/posix/spawni.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / posix / spawni.c
index 73d51e6cbe28eec981a3122b414de612ac1890e8..55950501ac7a30f7047e821961d3f8657d326029 100644 (file)
@@ -1,5 +1,5 @@
 /* Guts of POSIX spawn interface.  Generic POSIX.1 version.
-   Copyright (C) 2000-2018 Free Software Foundation, Inc.
+   Copyright (C) 2000-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -14,7 +14,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
+   <https://www.gnu.org/licenses/>.  */
 
 #include <spawn.h>
 #include <assert.h>
@@ -72,7 +72,7 @@ maybe_script_execute (struct posix_spawn_args *args)
       new_argv[0] = (char *) _PATH_BSHELL;
       new_argv[1] = (char *) args->file;
       if (argc > 1)
-       memcpy (new_argv + 2, argv + 1, argc * sizeof(char *));
+       memcpy (new_argv + 2, argv + 1, argc * sizeof (char *));
       else
        new_argv[2] = NULL;
 
@@ -204,9 +204,21 @@ __spawni_child (void *arguments)
              break;
 
            case spawn_do_dup2:
-             if (__dup2 (action->action.dup2_action.fd,
-                         action->action.dup2_action.newfd)
-                 != action->action.dup2_action.newfd)
+             /* Austin Group issue #411 requires adddup2 action with source
+                and destination being equal to remove close-on-exec flag.  */
+             if (action->action.dup2_action.fd
+                 == action->action.dup2_action.newfd)
+               {
+                 int fd = action->action.dup2_action.newfd;
+                 int flags = __fcntl (fd, F_GETFD, 0);
+                 if (flags == -1)
+                   goto fail;
+                 if (__fcntl (fd, F_SETFD, flags & ~FD_CLOEXEC) == -1)
+                   goto fail;
+               }
+             else if (__dup2 (action->action.dup2_action.fd,
+                              action->action.dup2_action.newfd)
+                      != action->action.dup2_action.newfd)
                goto fail;
              break;