The Austin Group has now clarified the interaction between
posix_spawn_file_actions_addchdir, posix_spawn_file_actions_addfchdir
and relative file names passed as program names. [1]

Let me enhance the gnulib tests accordingly.

[1] https://www.austingroupbugs.net/view.php?id=1208


2020-04-28  Bruno Haible  <br...@clisp.org>

        posix_spawn_file_actions_addfchdir tests: Enhance test.
        * tests/test-posix_spawn5.c: Include findprog.h.
        (test): New function, extracted from main.
        (main): Invoke it. Also, invoke it with a program name such as
        "bin/pwd".
        * modules/posix_spawn_file_actions_addfchdir-tests (Depends-on): Add
        findprog.

2020-04-28  Bruno Haible  <br...@clisp.org>

        posix_spawn_file_actions_addchdir tests: Enhance test.
        * tests/test-posix_spawn4.c: Include findprog.h.
        (test): New function, extracted from main.
        (main): Invoke it. Also, invoke it with a program name such as
        "bin/pwd".
        * modules/posix_spawn_file_actions_addchdir-tests (Depends-on): Add
        findprog.

>From 038d5b4a42cf1e242ef97c8f29c152e35782ed10 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 28 Apr 2020 12:34:19 +0200
Subject: [PATCH 1/2] posix_spawn_file_actions_addchdir tests: Enhance test.

* tests/test-posix_spawn4.c: Include findprog.h.
(test): New function, extracted from main.
(main): Invoke it. Also, invoke it with a program name such as
"bin/pwd".
* modules/posix_spawn_file_actions_addchdir-tests (Depends-on): Add
findprog.
---
 ChangeLog                                       | 10 +++++++++
 modules/posix_spawn_file_actions_addchdir-tests |  1 +
 tests/test-posix_spawn4.c                       | 27 ++++++++++++++++++++++---
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4388740..4986ad2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2020-04-28  Bruno Haible  <br...@clisp.org>
 
+	posix_spawn_file_actions_addchdir tests: Enhance test.
+	* tests/test-posix_spawn4.c: Include findprog.h.
+	(test): New function, extracted from main.
+	(main): Invoke it. Also, invoke it with a program name such as
+	"bin/pwd".
+	* modules/posix_spawn_file_actions_addchdir-tests (Depends-on): Add
+	findprog.
+
+2020-04-28  Bruno Haible  <br...@clisp.org>
+
 	posix_spawn_file_actions_destroy: Fix a crash (bug from 2019-06-10).
 	* lib/spawn_faction_destroy.c (posix_spawn_file_actions_destroy): Don't
 	access elements of the wrong union member.
diff --git a/modules/posix_spawn_file_actions_addchdir-tests b/modules/posix_spawn_file_actions_addchdir-tests
index 9c31f21..d5af0ae 100644
--- a/modules/posix_spawn_file_actions_addchdir-tests
+++ b/modules/posix_spawn_file_actions_addchdir-tests
@@ -7,6 +7,7 @@ tests/macros.h
 Depends-on:
 posix_spawn_file_actions_init
 posix_spawnp-tests
+findprog
 
 configure.ac:
 
diff --git a/tests/test-posix_spawn4.c b/tests/test-posix_spawn4.c
index 1ecb1ee..91a5497 100644
--- a/tests/test-posix_spawn4.c
+++ b/tests/test-posix_spawn4.c
@@ -31,6 +31,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#include "findprog.h"
+
 static int
 fd_safer (int fd)
 {
@@ -46,8 +48,8 @@ fd_safer (int fd)
   return fd;
 }
 
-int
-main ()
+static void
+test (const char *pwd_prog)
 {
   char *argv[2] = { (char *) "pwd", NULL };
   int ifd[2];
@@ -90,7 +92,7 @@ main ()
           || (attrs_allocated = true,
               (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
               || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0)
-          || (err = posix_spawnp (&child, "pwd", &actions, &attrs, argv, environ)) != 0))
+          || (err = posix_spawnp (&child, pwd_prog, &actions, &attrs, argv, environ)) != 0))
     {
       if (actions_allocated)
         posix_spawn_file_actions_destroy (&actions);
@@ -137,5 +139,24 @@ main ()
       fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus);
       exit (1);
     }
+}
+
+int
+main ()
+{
+  test ("pwd");
+
+  /* Verify that if a program is given as a relative file name with at least one
+     slash, it is interpreted w.r.t. the current directory after chdir has been
+     executed.  */
+  {
+    const char *abs_pwd_prog = find_in_path ("pwd");
+
+    if (abs_pwd_prog != NULL
+        && abs_pwd_prog[0] == '/'
+        && abs_pwd_prog[1] != '0' && abs_pwd_prog[1] != '/')
+      test (&abs_pwd_prog[1]);
+  }
+
   return 0;
 }
-- 
2.7.4

>From 5ec4d920e4acb45225320c3df9ae32fdff928413 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 28 Apr 2020 12:35:19 +0200
Subject: [PATCH 2/2] posix_spawn_file_actions_addfchdir tests: Enhance test.

* tests/test-posix_spawn5.c: Include findprog.h.
(test): New function, extracted from main.
(main): Invoke it. Also, invoke it with a program name such as
"bin/pwd".
* modules/posix_spawn_file_actions_addfchdir-tests (Depends-on): Add
findprog.
---
 ChangeLog                                        | 10 +++++++++
 modules/posix_spawn_file_actions_addfchdir-tests |  1 +
 tests/test-posix_spawn5.c                        | 27 +++++++++++++++++++++---
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4986ad2..ec8db18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2020-04-28  Bruno Haible  <br...@clisp.org>
 
+	posix_spawn_file_actions_addfchdir tests: Enhance test.
+	* tests/test-posix_spawn5.c: Include findprog.h.
+	(test): New function, extracted from main.
+	(main): Invoke it. Also, invoke it with a program name such as
+	"bin/pwd".
+	* modules/posix_spawn_file_actions_addfchdir-tests (Depends-on): Add
+	findprog.
+
+2020-04-28  Bruno Haible  <br...@clisp.org>
+
 	posix_spawn_file_actions_addchdir tests: Enhance test.
 	* tests/test-posix_spawn4.c: Include findprog.h.
 	(test): New function, extracted from main.
diff --git a/modules/posix_spawn_file_actions_addfchdir-tests b/modules/posix_spawn_file_actions_addfchdir-tests
index 5e50695..809d238 100644
--- a/modules/posix_spawn_file_actions_addfchdir-tests
+++ b/modules/posix_spawn_file_actions_addfchdir-tests
@@ -7,6 +7,7 @@ tests/macros.h
 Depends-on:
 posix_spawn_file_actions_init
 posix_spawnp-tests
+findprog
 
 configure.ac:
 
diff --git a/tests/test-posix_spawn5.c b/tests/test-posix_spawn5.c
index 375f08f..c5ca2a3 100644
--- a/tests/test-posix_spawn5.c
+++ b/tests/test-posix_spawn5.c
@@ -31,6 +31,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#include "findprog.h"
+
 static int
 fd_safer (int fd)
 {
@@ -46,8 +48,8 @@ fd_safer (int fd)
   return fd;
 }
 
-int
-main ()
+static void
+test (const char *pwd_prog)
 {
   char *argv[2] = { (char *) "pwd", NULL };
   int rootfd;
@@ -97,7 +99,7 @@ main ()
           || (attrs_allocated = true,
               (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
               || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0)
-          || (err = posix_spawnp (&child, "pwd", &actions, &attrs, argv, environ)) != 0))
+          || (err = posix_spawnp (&child, pwd_prog, &actions, &attrs, argv, environ)) != 0))
     {
       if (actions_allocated)
         posix_spawn_file_actions_destroy (&actions);
@@ -144,5 +146,24 @@ main ()
       fprintf (stderr, "subprocess terminated with unexpected exit status %d\n", exitstatus);
       exit (1);
     }
+}
+
+int
+main ()
+{
+  test ("pwd");
+
+  /* Verify that if a program is given as a relative file name with at least one
+     slash, it is interpreted w.r.t. the current directory after fchdir has been
+     executed.  */
+  {
+    const char *abs_pwd_prog = find_in_path ("pwd");
+
+    if (abs_pwd_prog != NULL
+        && abs_pwd_prog[0] == '/'
+        && abs_pwd_prog[1] != '0' && abs_pwd_prog[1] != '/')
+      test (&abs_pwd_prog[1]);
+  }
+
   return 0;
 }
-- 
2.7.4

Reply via email to