changeset 39828:8d755c31408d

posix_spawn_file_actions_addchdir: New module. Suggested by Eric Blake in <https://lists.gnu.org/archive/html/bug-findutils/2018-09/msg00007.html>. * lib/spawn.in.h (posix_spawn_file_actions_addchdir): New declaration. * lib/spawn_int.h (struct __spawn_action): Add tag 'spawn_do_chdir' and union member 'chdir_action'. * lib/spawn_faction_addchdir.c: New file. * lib/spawni.c (__spawni): Implement the spawn_do_chdir action. * lib/spawn_faction_addclose.c: Test REPLACE_POSIX_SPAWN instead of HAVE_WORKING_POSIX_SPAWN. * lib/spawn_faction_adddup2.c: Likewise. * lib/spawn_faction_addopen.c: Likewise. * m4/posix_spawn_faction_addchdir.m4: New file. * m4/posix_spawn.m4 (gl_POSIX_SPAWN_BODY): Test whether module 'posix_spawn_file_actions_addchdir' is present and whether posix_spawn_file_actions_addchdir_np exists. Define REPLACE_POSIX_SPAWN instead of HAVE_WORKING_POSIX_SPAWN. * m4/spawn_h.m4 (gl_SPAWN_H): Test whether posix_spawn_file_actions_addchdir is declared. (gl_SPAWN_H_DEFAULTS): Initialize GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR, HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR, REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR. * modules/spawn (Makefile.am): Substitute GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR, HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR, REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR. * modules/posix_spawn_file_actions_addchdir: New file. * modules/posix_spawn_file_actions_addclose (Depends-on, configure.ac): Test also REPLACE_POSIX_SPAWN. * modules/posix_spawn_file_actions_adddup2 (Depends-on, configure.ac): Likewise. * modules/posix_spawn_file_actions_addopen (Depends-on, configure.ac): Likewise. * tests/test-spawn-c++.cc (posix_spawn_file_actions_addchdir): Check signature. * doc/posix-functions/posix_spawn.texi: Mention the new module. * doc/posix-functions/posix_spawnp.texi: Likewise.
author Bruno Haible <bruno@clisp.org>
date Fri, 07 Sep 2018 23:35:52 +0200
parents 96fe1f932130
children aa6d47aae153
files ChangeLog doc/posix-functions/posix_spawn.texi doc/posix-functions/posix_spawnp.texi lib/spawn.in.h lib/spawn_faction_addchdir.c lib/spawn_faction_addclose.c lib/spawn_faction_adddup2.c lib/spawn_faction_addopen.c lib/spawn_int.h lib/spawni.c m4/posix_spawn.m4 m4/posix_spawn_faction_addchdir.m4 m4/spawn_h.m4 modules/posix_spawn_file_actions_addchdir modules/posix_spawn_file_actions_addclose modules/posix_spawn_file_actions_adddup2 modules/posix_spawn_file_actions_addopen modules/spawn tests/test-spawn-c++.cc
diffstat 19 files changed, 275 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 07 09:57:25 2018 +0200
+++ b/ChangeLog	Fri Sep 07 23:35:52 2018 +0200
@@ -1,3 +1,44 @@
+2018-09-07  Bruno Haible  <bruno@clisp.org>
+
+	posix_spawn_file_actions_addchdir: New module.
+	Suggested by Eric Blake in
+	<https://lists.gnu.org/archive/html/bug-findutils/2018-09/msg00007.html>.
+	* lib/spawn.in.h (posix_spawn_file_actions_addchdir): New declaration.
+	* lib/spawn_int.h (struct __spawn_action): Add tag 'spawn_do_chdir' and
+	union member 'chdir_action'.
+	* lib/spawn_faction_addchdir.c: New file.
+	* lib/spawni.c (__spawni): Implement the spawn_do_chdir action.
+	* lib/spawn_faction_addclose.c: Test REPLACE_POSIX_SPAWN instead of
+	HAVE_WORKING_POSIX_SPAWN.
+	* lib/spawn_faction_adddup2.c: Likewise.
+	* lib/spawn_faction_addopen.c: Likewise.
+	* m4/posix_spawn_faction_addchdir.m4: New file.
+	* m4/posix_spawn.m4 (gl_POSIX_SPAWN_BODY): Test whether module
+	'posix_spawn_file_actions_addchdir' is present and whether
+	posix_spawn_file_actions_addchdir_np exists. Define REPLACE_POSIX_SPAWN
+	instead of HAVE_WORKING_POSIX_SPAWN.
+	* m4/spawn_h.m4 (gl_SPAWN_H): Test whether
+	posix_spawn_file_actions_addchdir is declared.
+	(gl_SPAWN_H_DEFAULTS): Initialize
+	GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR,
+	HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR,
+	REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR.
+	* modules/spawn (Makefile.am): Substitute
+	GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR,
+	HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR,
+	REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR.
+	* modules/posix_spawn_file_actions_addchdir: New file.
+	* modules/posix_spawn_file_actions_addclose (Depends-on,
+	configure.ac): Test also REPLACE_POSIX_SPAWN.
+	* modules/posix_spawn_file_actions_adddup2 (Depends-on,
+	configure.ac): Likewise.
+	* modules/posix_spawn_file_actions_addopen (Depends-on,
+	configure.ac): Likewise.
+	* tests/test-spawn-c++.cc (posix_spawn_file_actions_addchdir): Check
+	signature.
+	* doc/posix-functions/posix_spawn.texi: Mention the new module.
+	* doc/posix-functions/posix_spawnp.texi: Likewise.
+
 2018-09-06  Bruno Haible  <bruno@clisp.org>
 
 	stddef: Override max_align_t on NetBSD 8.0/x86.
--- a/doc/posix-functions/posix_spawn.texi	Fri Sep 07 09:57:25 2018 +0200
+++ b/doc/posix-functions/posix_spawn.texi	Fri Sep 07 23:35:52 2018 +0200
@@ -23,3 +23,7 @@
 This function does not work on some platforms:
 AIX 6.1 (under particular circumstances), mingw.
 @end itemize
+
+The Gnulib module @code{posix_spawn_file_actions_addchdir} provides an
+additional action, that consists in changing the current directory of
+the child process before starting the specified program.
--- a/doc/posix-functions/posix_spawnp.texi	Fri Sep 07 09:57:25 2018 +0200
+++ b/doc/posix-functions/posix_spawnp.texi	Fri Sep 07 23:35:52 2018 +0200
@@ -23,3 +23,7 @@
 This function does not work on some platforms:
 AIX 6.1 (under particular circumstances), mingw.
 @end itemize
+
+The Gnulib module @code{posix_spawn_file_actions_addchdir} provides an
+additional action, that consists in changing the current directory of
+the child process before starting the specified program.
--- a/lib/spawn.in.h	Fri Sep 07 09:57:25 2018 +0200
+++ b/lib/spawn.in.h	Fri Sep 07 23:35:52 2018 +0200
@@ -878,6 +878,41 @@
 # endif
 #endif
 
+#if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+   'chdir' to the given directory during the 'spawn' call.  */
+# if @REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define posix_spawn_file_actions_addchdir rpl_posix_spawn_file_actions_addchdir
+#  endif
+_GL_FUNCDECL_RPL (posix_spawn_file_actions_addchdir, int,
+                  (posix_spawn_file_actions_t *_Restrict_ __file_actions,
+                   const char *_Restrict_ __path)
+                  __THROW _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_RPL (posix_spawn_file_actions_addchdir, int,
+                  (posix_spawn_file_actions_t *_Restrict_ __file_actions,
+                   const char *_Restrict_ __path));
+# else
+#  if !@HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR@
+_GL_FUNCDECL_SYS (posix_spawn_file_actions_addchdir, int,
+                  (posix_spawn_file_actions_t *_Restrict_ __file_actions,
+                   const char *_Restrict_ __path)
+                  __THROW _GL_ARG_NONNULL ((1, 2)));
+#  endif
+_GL_CXXALIAS_SYS (posix_spawn_file_actions_addchdir, int,
+                  (posix_spawn_file_actions_t *_Restrict_ __file_actions,
+                   const char *_Restrict_ __path));
+# endif
+_GL_CXXALIASWARN (posix_spawn_file_actions_addchdir);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_spawn_file_actions_addchdir
+# if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR
+_GL_WARN_ON_USE (posix_spawn_file_actions_addchdir,
+                 "posix_spawn_file_actions_addchdir is unportable - "
+                 "use gnulib module posix_spawn_file_actions_addchdir for portability");
+# endif
+#endif
+
 
 #endif /* _@GUARD_PREFIX@_SPAWN_H */
 #endif /* _@GUARD_PREFIX@_SPAWN_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/spawn_faction_addchdir.c	Fri Sep 07 23:35:52 2018 +0200
@@ -0,0 +1,57 @@
+/* Copyright (C) 2018 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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 <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <spawn.h>
+
+#include <errno.h>
+
+#if REPLACE_POSIX_SPAWN
+# include "spawn_int.h"
+#endif
+
+/* Add an action to FILE-ACTIONS which tells the implementation to call
+   'chdir' to the given directory during the 'spawn' call.  */
+int
+posix_spawn_file_actions_addchdir (posix_spawn_file_actions_t *file_actions,
+                                   const char *path)
+#undef posix_spawn_file_actions_addchdir
+{
+#if !REPLACE_POSIX_SPAWN
+  return posix_spawn_file_actions_addchdir_np (file_actions, path);
+#else
+  /* Allocate more memory if needed.  */
+  if (file_actions->_used == file_actions->_allocated
+      && __posix_spawn_file_actions_realloc (file_actions) != 0)
+    /* This can only mean we ran out of memory.  */
+    return ENOMEM;
+
+  {
+    struct __spawn_action *rec;
+
+    /* Add the new value.  */
+    rec = &file_actions->_actions[file_actions->_used];
+    rec->tag = spawn_do_chdir;
+    rec->action.chdir_action.path = path;
+
+    /* Account for the new entry.  */
+    ++file_actions->_used;
+
+    return 0;
+  }
+#endif
+}
--- a/lib/spawn_faction_addclose.c	Fri Sep 07 09:57:25 2018 +0200
+++ b/lib/spawn_faction_addclose.c	Fri Sep 07 23:35:52 2018 +0200
@@ -26,7 +26,7 @@
 # define __sysconf(open_max) getdtablesize ()
 #endif
 
-#if !HAVE_WORKING_POSIX_SPAWN
+#if REPLACE_POSIX_SPAWN
 # include "spawn_int.h"
 #endif
 
@@ -43,7 +43,7 @@
   if (fd < 0 || fd >= maxfd)
     return EBADF;
 
-#if HAVE_WORKING_POSIX_SPAWN
+#if !REPLACE_POSIX_SPAWN
   return posix_spawn_file_actions_addclose (file_actions, fd);
 #else
   /* Allocate more memory if needed.  */
--- a/lib/spawn_faction_adddup2.c	Fri Sep 07 09:57:25 2018 +0200
+++ b/lib/spawn_faction_adddup2.c	Fri Sep 07 23:35:52 2018 +0200
@@ -26,7 +26,7 @@
 # define __sysconf(open_max) getdtablesize ()
 #endif
 
-#if !HAVE_WORKING_POSIX_SPAWN
+#if REPLACE_POSIX_SPAWN
 # include "spawn_int.h"
 #endif
 
@@ -43,7 +43,7 @@
   if (fd < 0 || newfd < 0 || fd >= maxfd || newfd >= maxfd)
     return EBADF;
 
-#if HAVE_WORKING_POSIX_SPAWN
+#if !REPLACE_POSIX_SPAWN
   return posix_spawn_file_actions_adddup2 (file_actions, fd, newfd);
 #else
   /* Allocate more memory if needed.  */
--- a/lib/spawn_faction_addopen.c	Fri Sep 07 09:57:25 2018 +0200
+++ b/lib/spawn_faction_addopen.c	Fri Sep 07 23:35:52 2018 +0200
@@ -26,7 +26,7 @@
 # define __sysconf(open_max) getdtablesize ()
 #endif
 
-#if !HAVE_WORKING_POSIX_SPAWN
+#if REPLACE_POSIX_SPAWN
 # include "spawn_int.h"
 #endif
 
@@ -44,7 +44,7 @@
   if (fd < 0 || fd >= maxfd)
     return EBADF;
 
-#if HAVE_WORKING_POSIX_SPAWN
+#if !REPLACE_POSIX_SPAWN
   return posix_spawn_file_actions_addopen (file_actions, fd, path, oflag, mode);
 #else
   /* Allocate more memory if needed.  */
--- a/lib/spawn_int.h	Fri Sep 07 09:57:25 2018 +0200
+++ b/lib/spawn_int.h	Fri Sep 07 23:35:52 2018 +0200
@@ -23,7 +23,8 @@
   {
     spawn_do_close,
     spawn_do_dup2,
-    spawn_do_open
+    spawn_do_open,
+    spawn_do_chdir
   } tag;
 
   union
@@ -44,6 +45,10 @@
       int oflag;
       mode_t mode;
     } open_action;
+    struct
+    {
+      const char *path;
+    } chdir_action;
   } action;
 };
 
--- a/lib/spawni.c	Fri Sep 07 09:57:25 2018 +0200
+++ b/lib/spawni.c	Fri Sep 07 23:35:52 2018 +0200
@@ -284,6 +284,12 @@
                 /* The 'dup2' call failed.  */
                 _exit (SPAWN_ERROR);
               break;
+
+            case spawn_do_chdir:
+              if (chdir (action->action.chdir_action.path) < 0)
+                /* The 'chdir' call failed.  */
+                _exit (SPAWN_ERROR);
+              break;
             }
         }
     }
--- a/m4/posix_spawn.m4	Fri Sep 07 09:57:25 2018 +0200
+++ b/m4/posix_spawn.m4	Fri Sep 07 23:35:52 2018 +0200
@@ -1,4 +1,4 @@
-# posix_spawn.m4 serial 14
+# posix_spawn.m4 serial 15
 dnl Copyright (C) 2008-2018 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -33,45 +33,57 @@
   dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setsigmask])
   dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_destroy])
   if test $ac_cv_func_posix_spawn = yes; then
-    gl_POSIX_SPAWN_WORKS
-    case "$gl_cv_func_posix_spawn_works" in
-      *yes)
-        AC_DEFINE([HAVE_WORKING_POSIX_SPAWN], [1],
-          [Define if you have the posix_spawn and posix_spawnp functions and
-           they work.])
-        dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDULER
-        dnl evaluates to nonzero.
-        dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedpolicy])
-        dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedpolicy])
-        AC_CACHE_CHECK([whether posix_spawnattr_setschedpolicy is supported],
-          [gl_cv_func_spawnattr_setschedpolicy],
-          [AC_EGREP_CPP([POSIX scheduling supported], [
+    m4_ifdef([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR],
+      [dnl Module 'posix_spawn_file_actions_addchdir' is present.
+       AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addchdir_np])
+       if test $ac_cv_func_posix_spawn_file_actions_addchdir_np = no; then
+         dnl In order to implement the posix_spawn_file_actions_addchdir
+         dnl function, we need to replace the entire posix_spawn facility.
+         REPLACE_POSIX_SPAWN=1
+       fi
+      ])
+    if test $REPLACE_POSIX_SPAWN = 0; then
+      gl_POSIX_SPAWN_WORKS
+      case "$gl_cv_func_posix_spawn_works" in
+        *yes)
+          dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDULER
+          dnl evaluates to nonzero.
+          dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedpolicy])
+          dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedpolicy])
+          AC_CACHE_CHECK([whether posix_spawnattr_setschedpolicy is supported],
+            [gl_cv_func_spawnattr_setschedpolicy],
+            [AC_EGREP_CPP([POSIX scheduling supported], [
 #include <spawn.h>
 #if POSIX_SPAWN_SETSCHEDULER
  POSIX scheduling supported
 #endif
 ],
-             [gl_cv_func_spawnattr_setschedpolicy=yes],
-             [gl_cv_func_spawnattr_setschedpolicy=no])
-          ])
-        dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDPARAM
-        dnl evaluates to nonzero.
-        dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedparam])
-        dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedparam])
-        AC_CACHE_CHECK([whether posix_spawnattr_setschedparam is supported],
-          [gl_cv_func_spawnattr_setschedparam],
-          [AC_EGREP_CPP([POSIX scheduling supported], [
+               [gl_cv_func_spawnattr_setschedpolicy=yes],
+               [gl_cv_func_spawnattr_setschedpolicy=no])
+            ])
+          dnl Assume that these functions are available if POSIX_SPAWN_SETSCHEDPARAM
+          dnl evaluates to nonzero.
+          dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_getschedparam])
+          dnl AC_CHECK_FUNCS_ONCE([posix_spawnattr_setschedparam])
+          AC_CACHE_CHECK([whether posix_spawnattr_setschedparam is supported],
+            [gl_cv_func_spawnattr_setschedparam],
+            [AC_EGREP_CPP([POSIX scheduling supported], [
 #include <spawn.h>
 #if POSIX_SPAWN_SETSCHEDPARAM
  POSIX scheduling supported
 #endif
 ],
-             [gl_cv_func_spawnattr_setschedparam=yes],
-             [gl_cv_func_spawnattr_setschedparam=no])
-          ])
-        ;;
-      *) REPLACE_POSIX_SPAWN=1 ;;
-    esac
+               [gl_cv_func_spawnattr_setschedparam=yes],
+               [gl_cv_func_spawnattr_setschedparam=no])
+            ])
+          ;;
+        *) REPLACE_POSIX_SPAWN=1 ;;
+      esac
+    fi
+  fi
+  if test $ac_cv_func_posix_spawn != yes || test $REPLACE_POSIX_SPAWN = 1; then
+    AC_DEFINE([REPLACE_POSIX_SPAWN], [1],
+      [Define if gnulib uses its own posix_spawn and posix_spawnp functions.])
   fi
 ])
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m4/posix_spawn_faction_addchdir.m4	Fri Sep 07 23:35:52 2018 +0200
@@ -0,0 +1,20 @@
+# posix_spawn_faction_addchdir.m4 serial 1
+dnl Copyright (C) 2018 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR],
+[
+  AC_REQUIRE([gl_SPAWN_H_DEFAULTS])
+  AC_REQUIRE([AC_PROG_CC])
+  gl_POSIX_SPAWN
+  AC_CHECK_FUNCS_ONCE([posix_spawn_file_actions_addchdir posix_spawn_file_actions_addchdir_np])
+  if test $ac_cv_func_posix_spawn_file_actions_addchdir = yes; then
+    dnl This function is not yet standardized. Therefore override the
+    dnl system's implementation always.
+    REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=1
+  else
+    HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0
+  fi
+])
--- a/m4/spawn_h.m4	Fri Sep 07 09:57:25 2018 +0200
+++ b/m4/spawn_h.m4	Fri Sep 07 23:35:52 2018 +0200
@@ -1,4 +1,4 @@
-# spawn_h.m4 serial 16
+# spawn_h.m4 serial 17
 dnl Copyright (C) 2008-2018 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -53,7 +53,7 @@
     posix_spawnattr_getschedparam posix_spawnattr_setschedparam
     posix_spawn_file_actions_init posix_spawn_file_actions_destroy
     posix_spawn_file_actions_addopen posix_spawn_file_actions_addclose
-    posix_spawn_file_actions_adddup2])
+    posix_spawn_file_actions_adddup2 posix_spawn_file_actions_addchdir])
 ])
 
 dnl Checks whether the system has the functions posix_spawn.
@@ -92,6 +92,7 @@
   GNULIB_POSIX_SPAWN=0;                       AC_SUBST([GNULIB_POSIX_SPAWN])
   GNULIB_POSIX_SPAWNP=0;                      AC_SUBST([GNULIB_POSIX_SPAWNP])
   GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT=0;     AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT])
+  GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
   GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=0; AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE])
   GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=0;  AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2])
   GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN=0;  AC_SUBST([GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN])
@@ -115,7 +116,11 @@
   HAVE_POSIX_SPAWNATTR_T=1;  AC_SUBST([HAVE_POSIX_SPAWNATTR_T])
   HAVE_POSIX_SPAWN_FILE_ACTIONS_T=1;
                              AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_T])
+  HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=1;
+                             AC_SUBST([HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
   REPLACE_POSIX_SPAWN=0;     AC_SUBST([REPLACE_POSIX_SPAWN])
+  REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR=0;
+                             AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR])
   REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE=0;
                              AC_SUBST([REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE])
   REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2=0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/posix_spawn_file_actions_addchdir	Fri Sep 07 23:35:52 2018 +0200
@@ -0,0 +1,30 @@
+Description:
+posix_spawn_file_actions_addchdir() function: augment a child process actions
+specification.
+
+Files:
+lib/spawn_faction_addchdir.c
+lib/spawn_int.h
+m4/posix_spawn_faction_addchdir.m4
+
+Depends-on:
+spawn
+posix_spawn_file_actions_init [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = 1]
+
+configure.ac:
+gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR
+if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR = 1; then
+  AC_LIBOBJ([spawn_faction_addchdir])
+fi
+gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_addchdir])
+
+Makefile.am:
+
+Include:
+<spawn.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
--- a/modules/posix_spawn_file_actions_addclose	Fri Sep 07 09:57:25 2018 +0200
+++ b/modules/posix_spawn_file_actions_addclose	Fri Sep 07 23:35:52 2018 +0200
@@ -9,12 +9,12 @@
 
 Depends-on:
 spawn
-getdtablesize                 [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = 1]
-posix_spawn_file_actions_init [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = 1]
+getdtablesize                 [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = 1]
+posix_spawn_file_actions_init [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = 1]
 
 configure.ac:
 gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE
-if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = 1; then
+if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE = 1; then
   AC_LIBOBJ([spawn_faction_addclose])
 fi
 gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_addclose])
--- a/modules/posix_spawn_file_actions_adddup2	Fri Sep 07 09:57:25 2018 +0200
+++ b/modules/posix_spawn_file_actions_adddup2	Fri Sep 07 23:35:52 2018 +0200
@@ -9,12 +9,12 @@
 
 Depends-on:
 spawn
-getdtablesize                 [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1]
-posix_spawn_file_actions_init [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1]
+getdtablesize                 [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1]
+posix_spawn_file_actions_init [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1]
 
 configure.ac:
 gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2
-if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1; then
+if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2 = 1; then
   AC_LIBOBJ([spawn_faction_adddup2])
 fi
 gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_adddup2])
--- a/modules/posix_spawn_file_actions_addopen	Fri Sep 07 09:57:25 2018 +0200
+++ b/modules/posix_spawn_file_actions_addopen	Fri Sep 07 23:35:52 2018 +0200
@@ -9,12 +9,12 @@
 
 Depends-on:
 spawn
-getdtablesize                 [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = 1]
-posix_spawn_file_actions_init [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = 1]
+getdtablesize                 [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = 1]
+posix_spawn_file_actions_init [test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = 1]
 
 configure.ac:
 gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN
-if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = 1; then
+if test $HAVE_POSIX_SPAWN = 0 || test $REPLACE_POSIX_SPAWN = 1 || test $REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN = 1; then
   AC_LIBOBJ([spawn_faction_addopen])
 fi
 gl_SPAWN_MODULE_INDICATOR([posix_spawn_file_actions_addopen])
--- a/modules/spawn	Fri Sep 07 09:57:25 2018 +0200
+++ b/modules/spawn	Fri Sep 07 23:35:52 2018 +0200
@@ -32,6 +32,7 @@
 	      -e 's/@''GNULIB_POSIX_SPAWN''@/$(GNULIB_POSIX_SPAWN)/g' \
 	      -e 's/@''GNULIB_POSIX_SPAWNP''@/$(GNULIB_POSIX_SPAWNP)/g' \
 	      -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT)/g' \
+	      -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)/g' \
 	      -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE)/g' \
 	      -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2)/g' \
 	      -e 's/@''GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN''@/$(GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN)/g' \
@@ -53,7 +54,9 @@
 	      -e 's|@''HAVE_POSIX_SPAWN''@|$(HAVE_POSIX_SPAWN)|g' \
 	      -e 's|@''HAVE_POSIX_SPAWNATTR_T''@|$(HAVE_POSIX_SPAWNATTR_T)|g' \
 	      -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_T''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_T)|g' \
+	      -e 's|@''HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@|$(HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)|g' \
 	      -e 's|@''REPLACE_POSIX_SPAWN''@|$(REPLACE_POSIX_SPAWN)|g' \
+	      -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR)|g' \
 	      -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE)|g' \
 	      -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2)|g' \
 	      -e 's|@''REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN''@|$(REPLACE_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN)|g' \
--- a/tests/test-spawn-c++.cc	Fri Sep 07 09:57:25 2018 +0200
+++ b/tests/test-spawn-c++.cc	Fri Sep 07 23:35:52 2018 +0200
@@ -132,6 +132,11 @@
                  (posix_spawn_file_actions_t *, int, int));
 #endif
 
+#if GNULIB_TEST_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR
+SIGNATURE_CHECK (GNULIB_NAMESPACE::posix_spawn_file_actions_addchdir, int,
+                 (posix_spawn_file_actions_t *, const char *));
+#endif
+
 
 int
 main ()