+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.
#include "findprog.h"
#include "qemu.h"
+#include "xvasprintf.h"
static bool is_qemu;
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;
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);
|| (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__
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);
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;