]> Savannah Git Hosting - gnulib.git/commitdiff
posix_spawn_file_actions_addfchdir tests: Fix test failure on Android.
authorBruno Haible <bruno@clisp.org>
Wed, 11 Jan 2023 18:51:43 +0000 (19:51 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 11 Jan 2023 18:51:43 +0000 (19:51 +0100)
* tests/test-posix_spawn-fchdir.c: Include xvasprintf.h.
(test): On Android, use "/proc" instead of "/".
(main): Determine the relative location of the 'pwd' program
accordingly.
* modules/posix_spawn_file_actions_addfchdir-tests (Depends-on): Add
xvasprintf.

ChangeLog
modules/posix_spawn_file_actions_addfchdir-tests
tests/test-posix_spawn-fchdir.c

index ade7eaab85baa564daa724200a0f5ce00adac8a3..537b5526b76606a59ba73be422aad990b9a110c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-01-11  Bruno Haible  <bruno@clisp.org>
+
+       posix_spawn_file_actions_addfchdir tests: Fix test failure on Android.
+       * tests/test-posix_spawn-fchdir.c: Include xvasprintf.h.
+       (test): On Android, use "/proc" instead of "/".
+       (main): Determine the relative location of the 'pwd' program
+       accordingly.
+       * modules/posix_spawn_file_actions_addfchdir-tests (Depends-on): Add
+       xvasprintf.
+
 2023-01-11  Bruno Haible  <bruno@clisp.org>
 
        rename, renameat, renameatu: Fix test failures on Android/Termux.
index d32dbba2ae23e91814d7bda9b207d447a1ee07c1..5f41961ab2c975c68f737f38f13e8081a9623542 100644 (file)
@@ -11,6 +11,7 @@ posix_spawn_file_actions_destroy
 posix_spawnp-tests
 stdbool
 findprog
+xvasprintf
 
 configure.ac:
 AC_EGREP_CPP([notposix], [[
index f7fec7873bb486e26bf04a610b528397eca288a1..4d06899306e9c0b676de8770304e7f9d6296e9da 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "findprog.h"
 #include "qemu.h"
+#include "xvasprintf.h"
 
 static bool is_qemu;
 
@@ -54,7 +55,13 @@ static void
 test (const char *pwd_prog)
 {
   char *argv[2] = { (char *) "pwd", NULL };
-  int rootfd;
+  /* The name of a directory that most likely is accessible.  */
+  #if defined __ANDROID__
+    #define KNOWNDIR "/proc"
+  #else
+    #define KNOWNDIR "/"
+  #endif
+  int knownfd;
   int ifd[2];
   sigset_t blocked_signals;
   sigset_t fatal_signal_set;
@@ -70,8 +77,8 @@ test (const char *pwd_prog)
   int status;
   int exitstatus;
 
-  rootfd = open ("/", O_RDONLY);
-  if (rootfd < 0)
+  knownfd = open (KNOWNDIR, O_RDONLY);
+  if (knownfd < 0)
     {
       perror ("cannot open directory");
       exit (1);
@@ -100,7 +107,7 @@ test (const char *pwd_prog)
           || (err = posix_spawn_file_actions_addclose (&actions, ifd[1])) != 0
           || (err = posix_spawn_file_actions_addclose (&actions, ifd[0])) != 0
           || (err = posix_spawn_file_actions_addopen (&actions, STDIN_FILENO, "/dev/null", O_RDONLY, 0)) != 0
-          || (err = posix_spawn_file_actions_addfchdir (&actions, rootfd)) != 0
+          || (err = posix_spawn_file_actions_addfchdir (&actions, knownfd)) != 0
           || (err = posix_spawnattr_init (&attrs)) != 0
           || (attrs_allocated = true,
               #if defined _WIN32 && !defined __CYGWIN__
@@ -137,13 +144,13 @@ test (const char *pwd_prog)
       fprintf (stderr, "could not read expected output\n");
       exit (1);
     }
-  /* For a process running under QEMU user-mode, rootfd points to the directory
+  /* For a process running under QEMU user-mode, knownfd points to the directory
      that is the value of the QEMU_LD_PREFIX environment variable or of the -L
      command-line option, and the line produced by 'pwd' is that directory, not
      "/".  */
   if (!is_qemu)
     {
-      if (memcmp (line, "/\n", 2) != 0)
+      if (memcmp (line, KNOWNDIR "\n", strlen (KNOWNDIR) + 1) != 0)
         {
           fprintf (stderr, "read output is not the expected output\n");
           exit (1);
@@ -183,7 +190,18 @@ main ()
       if (abs_pwd_prog != NULL
           && abs_pwd_prog[0] == '/'
           && abs_pwd_prog[1] != '0' && abs_pwd_prog[1] != '/')
-        test (&abs_pwd_prog[1]);
+        {
+          /* Determine the location of the 'pwd' program, relative to
+             KNOWNDIR.  */
+          const char *relative_pwd_prog;
+          #if defined __ANDROID__
+          relative_pwd_prog = xasprintf ("..%s", abs_pwd_prog);
+          #else
+          relative_pwd_prog = &abs_pwd_prog[1];
+          #endif
+
+          test (relative_pwd_prog);
+        }
     }
 
   return 0;