]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
posix_spawn_file_actions_addfchdir tests: Enhance test.
authorBruno Haible <bruno@clisp.org>
Tue, 28 Apr 2020 10:35:19 +0000 (12:35 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 28 Apr 2020 10:35:19 +0000 (12:35 +0200)
* 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
modules/posix_spawn_file_actions_addfchdir-tests
tests/test-posix_spawn5.c

index 4986ad214cf1c2ff5fc15bc99061d444a4a18d09..ec8db184392d525c7d23d5630cdc843e2276cfb2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-04-28  Bruno Haible  <bruno@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  <bruno@clisp.org>
 
        posix_spawn_file_actions_addchdir tests: Enhance test.
index 5e50695345b33924022cd65b8ffca3025a0ef1ae..809d2381d8d7d7259440a4ab92a6fdefa2c3d4d2 100644 (file)
@@ -7,6 +7,7 @@ tests/macros.h
 Depends-on:
 posix_spawn_file_actions_init
 posix_spawnp-tests
+findprog
 
 configure.ac:
 
index 375f08ff7ca58d7241853e39cf2780a22b5ed0b8..c5ca2a33a8a8a33f04eb44261e427970564d2d7d 100644 (file)
@@ -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;
 }