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

index 438874067e59eb6d908137c4ad6e93265bc11dfa..4986ad214cf1c2ff5fc15bc99061d444a4a18d09 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-04-28  Bruno Haible  <bruno@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  <bruno@clisp.org>
 
        posix_spawn_file_actions_destroy: Fix a crash (bug from 2019-06-10).
index 9c31f21e66a1a590de475d27f3baba81ed4dc590..d5af0ae0ef396ba8cca3ecebeb35a4f79040c842 100644 (file)
@@ -7,6 +7,7 @@ tests/macros.h
 Depends-on:
 posix_spawn_file_actions_init
 posix_spawnp-tests
+findprog
 
 configure.ac:
 
index 1ecb1ee33973918c1e8d9313a93f53a099baf57f..91a5497ede2678480f2ddc7e6320fbe5120f49d0 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 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;
 }