]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
posix: Add POSIX aliases to some spawn functions
authorLucas Chollet <lucas.chollet@free.fr>
Wed, 1 Apr 2026 12:21:39 +0000 (14:21 +0200)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 7 Apr 2026 16:21:13 +0000 (13:21 -0300)
Both `posix_spawn_file_actions_add{,f}chdir` functions are now fully
defined by POSIX-2024, this patch adds both functions as aliases of the
already existing `posix_spawn_file_actions_add{,f}chdir_np` GNU
extensions.

This makes glibc more compliant in regards to POSIX-2024.

Signed-off-by: Lucas Chollet <lucas.chollet@free.fr>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
conform/data/spawn.h-data
posix/Makefile
posix/spawn.h
posix/tst-spawn-chdir-posix.c [new file with mode: 0644]
posix/tst-spawn-chdir.c

index 43aa9cb8aed26bf75768ef3f75b8a4a1f7e394cd..1f332324c2e5fa1a30fa293a9e69b4d809d84669 100644 (file)
@@ -29,6 +29,10 @@ function int posix_spawnattr_setpgroup (posix_spawnattr_t*, pid_t)
 function int posix_spawnattr_setschedparam (posix_spawnattr_t*, const struct sched_param*)
 function int posix_spawnattr_setschedpolicy (posix_spawnattr_t*, int)
 function int posix_spawnattr_setsigmask (posix_spawnattr_t*, const sigset_t*)
+#if defined XOPEN2K24 || defined POSIX2024
+function int posix_spawn_file_actions_addchdir (posix_spawn_file_actions_t*, const char *)
+function int posix_spawn_file_actions_addfchdir (posix_spawn_file_actions_t*, int)
+#endif
 function int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t*, int)
 function int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t*, int, int)
 function int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t*, int, const char *, int, mode_t)
index ec28b9e1dabcf5d22f1e69b6b2bff531e8d804a1..a5e5162c61b5f5f00989f6eb487fd233b62b1cba 100644 (file)
@@ -315,6 +315,7 @@ tests := \
   tst-rxspencer-no-utf8 \
   tst-sched_getaffinity \
   tst-spawn-chdir \
+  tst-spawn-chdir-posix \
   tst-spawn4 \
   tst-spawn5 \
   tst-spawn6 \
index 5e68752a668b7fba67ea4066a64e38e9e3703848..0aabf5ebef0201f1f2970a59133b3784401d3bbf 100644 (file)
@@ -200,6 +200,26 @@ extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *
                                             int __fd, int __newfd)
      __THROW __nonnull ((1));
 
+#ifdef __USE_XOPEN2K24XSI
+
+/* Add an action changing the directory to PATH during spawn.  This
+   affects the subsequent file actions.
+   Alias of posix_spawn_file_actions_addchdir_np.  */
+extern int __REDIRECT_NTH (posix_spawn_file_actions_addchdir,
+                            (posix_spawn_file_actions_t * __restrict __actions,
+                             const char *__restrict __path),
+                            posix_spawn_file_actions_addchdir_np);
+
+/* Add an action changing the directory to FD during spawn.  This
+   affects the subsequent file actions.  FD is not duplicated and must
+   be open when the file action is executed.
+   Alias of posix_spawn_file_actions_addfchdir_np.  */
+extern int __REDIRECT_NTH (posix_spawn_file_actions_addfchdir,
+                           (posix_spawn_file_actions_t *, int __fd),
+                           posix_spawn_file_actions_addfchdir_np);
+
+#endif /* __USE_XOPEN2K24XSI */
+
 #ifdef __USE_MISC
 /* Add an action changing the directory to PATH during spawn.  This
    affects the subsequent file actions.  */
diff --git a/posix/tst-spawn-chdir-posix.c b/posix/tst-spawn-chdir-posix.c
new file mode 100644 (file)
index 0000000..3f8d895
--- /dev/null
@@ -0,0 +1,2 @@
+#define USE_POSIX_ALIASES
+#include "tst-spawn-chdir.c"
index a3478d61f6ec4e9436e81be6d8581ae131287bd7..166f835492b8cf58fb6a29a81b34ac99513b1500 100644 (file)
@@ -78,12 +78,25 @@ add_chdir (posix_spawn_file_actions_t *actions, const char *path,
     {
       TEST_COMPARE (posix_spawn_file_actions_addopen
                     (actions, tmpfd, path, O_DIRECTORY | O_RDONLY, 0), 0);
-      TEST_COMPARE (posix_spawn_file_actions_addfchdir_np
-                    (actions, tmpfd), 0);
+
+#ifdef USE_POSIX_ALIASES
+      int ret = posix_spawn_file_actions_addfchdir (actions, tmpfd);
+#else
+      int ret = posix_spawn_file_actions_addfchdir_np (actions, tmpfd);
+#endif
+      TEST_COMPARE (ret, 0);
+
       TEST_COMPARE (posix_spawn_file_actions_addclose (actions, tmpfd), 0);
     }
   else
-    TEST_COMPARE (posix_spawn_file_actions_addchdir_np (actions, path), 0);
+    {
+#ifdef USE_POSIX_ALIASES
+      int ret = posix_spawn_file_actions_addchdir (actions, path);
+#else
+      int ret = posix_spawn_file_actions_addchdir_np (actions, path);
+#endif
+      TEST_COMPARE (ret, 0);
+    }
 }
 
 static int