support: Add envp argument to support_capture_subprogram

So tests can specify a list of environment variables.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
This commit is contained in:
Adhemerval Zanella 2024-05-06 13:18:47 -03:00
parent c8a0e21da6
commit 1e1ad714ee
16 changed files with 30 additions and 26 deletions

View File

@ -79,7 +79,7 @@ do_test (int argc, char *argv[])
setenv ("LD_AUDIT", "tst-auditmod18.so", 0); setenv ("LD_AUDIT", "tst-auditmod18.so", 0);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-audit18", 0, sc_allow_stderr); support_capture_subprocess_check (&result, "tst-audit18", 0, sc_allow_stderr);
struct struct

View File

@ -69,7 +69,7 @@ do_test (int argc, char *argv[])
setenv ("LD_AUDIT", "tst-auditmod18b.so", 0); setenv ("LD_AUDIT", "tst-auditmod18b.so", 0);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-audit18b", 0, sc_allow_stderr); support_capture_subprocess_check (&result, "tst-audit18b", 0, sc_allow_stderr);
bool find_symbind = false; bool find_symbind = false;

View File

@ -83,7 +83,7 @@ do_test (int argc, char *argv[])
setenv ("LD_AUDIT", "tst-auditmod22.so", 0); setenv ("LD_AUDIT", "tst-auditmod22.so", 0);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-audit22", 0, sc_allow_stderr); support_capture_subprocess_check (&result, "tst-audit22", 0, sc_allow_stderr);
/* The respawned process should always print the vDSO address (otherwise it /* The respawned process should always print the vDSO address (otherwise it

View File

@ -82,7 +82,7 @@ do_test (int argc, char *argv[])
setenv ("LD_AUDIT", "tst-auditmod23.so", 0); setenv ("LD_AUDIT", "tst-auditmod23.so", 0);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-audit22", 0, sc_allow_stderr); support_capture_subprocess_check (&result, "tst-audit22", 0, sc_allow_stderr);
/* The expected la_objopen/la_objclose: /* The expected la_objopen/la_objclose:

View File

@ -77,7 +77,7 @@ do_test (int argc, char *argv[])
{ {
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-audit25a", 0, support_capture_subprocess_check (&result, "tst-audit25a", 0,
sc_allow_stderr); sc_allow_stderr);
@ -102,7 +102,7 @@ do_test (int argc, char *argv[])
{ {
setenv ("LD_BIND_NOW", "1", 0); setenv ("LD_BIND_NOW", "1", 0);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-audit25a", 0, support_capture_subprocess_check (&result, "tst-audit25a", 0,
sc_allow_stderr); sc_allow_stderr);

View File

@ -76,7 +76,7 @@ do_test (int argc, char *argv[])
{ {
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-audit25a", 0, support_capture_subprocess_check (&result, "tst-audit25a", 0,
sc_allow_stderr); sc_allow_stderr);
@ -102,7 +102,7 @@ do_test (int argc, char *argv[])
{ {
setenv ("LD_BIND_NOW", "1", 0); setenv ("LD_BIND_NOW", "1", 0);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-audit25a", 0, support_capture_subprocess_check (&result, "tst-audit25a", 0,
sc_allow_stderr); sc_allow_stderr);

View File

@ -32,7 +32,7 @@ main (int argc, char **argv)
/* Run ldconfig to populate the cache. */ /* Run ldconfig to populate the cache. */
char *command = xasprintf ("%s/ldconfig", support_install_rootsbindir); char *command = xasprintf ("%s/ldconfig", support_install_rootsbindir);
struct support_capture_subprocess result = struct support_capture_subprocess result =
support_capture_subprogram (command, &((char *) { NULL })); support_capture_subprogram (command, &((char *) { NULL }), NULL);
support_capture_subprocess_check (&result, "ldconfig", 0, sc_allow_none); support_capture_subprocess_check (&result, "ldconfig", 0, sc_allow_none);
free (command); free (command);

View File

@ -30,7 +30,7 @@ do_test (void)
{ {
char *argv[] = { (char *) "ld.so", ldconfig_path, (char *) "--help", NULL }; char *argv[] = { (char *) "ld.so", ldconfig_path, (char *) "--help", NULL };
struct support_capture_subprocess cap struct support_capture_subprocess cap
= support_capture_subprogram (support_objdir_elf_ldso, argv); = support_capture_subprogram (support_objdir_elf_ldso, argv, NULL);
support_capture_subprocess_check (&cap, "no --argv0", 0, sc_allow_stdout); support_capture_subprocess_check (&cap, "no --argv0", 0, sc_allow_stdout);
puts ("info: output without --argv0:"); puts ("info: output without --argv0:");
puts (cap.out.buffer); puts (cap.out.buffer);
@ -46,7 +46,7 @@ do_test (void)
ldconfig_path, (char *) "--help", NULL ldconfig_path, (char *) "--help", NULL
}; };
struct support_capture_subprocess cap struct support_capture_subprocess cap
= support_capture_subprogram (support_objdir_elf_ldso, argv); = support_capture_subprogram (support_objdir_elf_ldso, argv, NULL);
support_capture_subprocess_check (&cap, "with --argv0", 0, sc_allow_stdout); support_capture_subprocess_check (&cap, "with --argv0", 0, sc_allow_stdout);
puts ("info: output with --argv0:"); puts ("info: output with --argv0:");
puts (cap.out.buffer); puts (cap.out.buffer);

View File

@ -113,7 +113,7 @@ do_test (int argc, char *argv[])
printf ("[%d] Spawned test for %s\n", i, tests[i].env); printf ("[%d] Spawned test for %s\n", i, tests[i].env);
setenv ("GLIBC_TUNABLES", tests[i].env, 1); setenv ("GLIBC_TUNABLES", tests[i].env, 1);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-tunables-enable_secure", support_capture_subprocess_check (&result, "tst-tunables-enable_secure",
0, sc_allow_stderr); 0, sc_allow_stderr);
support_capture_subprocess_free (&result); support_capture_subprocess_free (&result);

View File

@ -396,7 +396,7 @@ do_test (int argc, char *argv[])
tests[i].value); tests[i].value);
setenv (tests[i].name, tests[i].value, 1); setenv (tests[i].name, tests[i].value, 1);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-tunables", 0, support_capture_subprocess_check (&result, "tst-tunables", 0,
sc_allow_stderr); sc_allow_stderr);
support_capture_subprocess_free (&result); support_capture_subprocess_free (&result);

View File

@ -35,11 +35,12 @@ struct support_capture_subprocess
struct support_capture_subprocess support_capture_subprocess struct support_capture_subprocess support_capture_subprocess
(void (*callback) (void *), void *closure); (void (*callback) (void *), void *closure);
/* Issue FILE with ARGV arguments by using posix_spawn and capture standard /* Issue FILE with ARGV arguments and ENVP environments by using posix_spawn
output, standard error, and the exit status. The out.buffer and err.buffer and capture standard output, standard error, and the exit status. If
are handle as support_capture_subprocess. */ ENVP is NULL the current environment variable is used. The out.buffer and
err.buffer are handle by support_capture_subprocess. */
struct support_capture_subprocess support_capture_subprogram struct support_capture_subprocess support_capture_subprogram
(const char *file, char *const argv[]); (const char *file, char *const argv[], char *const envp[]);
/* Copy the running program into a setgid binary and run it with CHILD_ID /* Copy the running program into a setgid binary and run it with CHILD_ID
argument. If execution is successful, return the exit status of the child argument. If execution is successful, return the exit status of the child

View File

@ -33,10 +33,11 @@ struct support_subprocess
struct support_subprocess support_subprocess struct support_subprocess support_subprocess
(void (*callback) (void *), void *closure); (void (*callback) (void *), void *closure);
/* Issue FILE with ARGV arguments by using posix_spawn and return is PID, a /* Issue FILE with ARGV arguments and ENVP environments by using posix_spawn
pipe redirected to STDOUT, and a pipe redirected to STDERR. */ and return is PID, a pipe redirected to STDOUT, and a pipe redirected to
STDERR. If ENVP is NULL the current environment variable is used. */
struct support_subprocess support_subprogram struct support_subprocess support_subprogram
(const char *file, char *const argv[]); (const char *file, char *const argv[], char *const envp[]);
/* Invoke program FILE with ARGV arguments by using posix_spawn and wait for it /* Invoke program FILE with ARGV arguments by using posix_spawn and wait for it
to complete. Return program exit status. */ to complete. Return program exit status. */

View File

@ -93,13 +93,14 @@ support_capture_subprocess (void (*callback) (void *), void *closure)
} }
struct support_capture_subprocess struct support_capture_subprocess
support_capture_subprogram (const char *file, char *const argv[]) support_capture_subprogram (const char *file, char *const argv[],
char *const envp[])
{ {
struct support_capture_subprocess result; struct support_capture_subprocess result;
xopen_memstream (&result.out); xopen_memstream (&result.out);
xopen_memstream (&result.err); xopen_memstream (&result.err);
struct support_subprocess proc = support_subprogram (file, argv); struct support_subprocess proc = support_subprogram (file, argv, envp);
support_capture_poll (&result, &proc); support_capture_poll (&result, &proc);
return result; return result;

View File

@ -69,7 +69,7 @@ support_subprocess (void (*callback) (void *), void *closure)
} }
struct support_subprocess struct support_subprocess
support_subprogram (const char *file, char *const argv[]) support_subprogram (const char *file, char *const argv[], char *const envp[])
{ {
struct support_subprocess result = support_subprocess_init (); struct support_subprocess result = support_subprocess_init ();
@ -84,7 +84,8 @@ support_subprogram (const char *file, char *const argv[])
xposix_spawn_file_actions_addclose (&fa, result.stdout_pipe[1]); xposix_spawn_file_actions_addclose (&fa, result.stdout_pipe[1]);
xposix_spawn_file_actions_addclose (&fa, result.stderr_pipe[1]); xposix_spawn_file_actions_addclose (&fa, result.stderr_pipe[1]);
result.pid = xposix_spawn (file, &fa, NULL, argv, environ); result.pid = xposix_spawn (file, &fa, NULL, argv,
envp == NULL ? environ : envp);
xclose (result.stdout_pipe[1]); xclose (result.stdout_pipe[1]);
xclose (result.stderr_pipe[1]); xclose (result.stderr_pipe[1]);

View File

@ -238,7 +238,7 @@ do_subprogram (const struct test *test)
args[argc] = NULL; args[argc] = NULL;
TEST_VERIFY (argc < argv_size); TEST_VERIFY (argc < argv_size);
return support_capture_subprogram (args[0], args); return support_capture_subprogram (args[0], args, NULL);
} }
enum test_type enum test_type

View File

@ -133,7 +133,7 @@ do_test (int argc, char *argv[])
setenv ("GLIBC_TUNABLES", tunable, 1); setenv ("GLIBC_TUNABLES", tunable, 1);
struct support_capture_subprocess result struct support_capture_subprocess result
= support_capture_subprogram (spargv[0], spargv); = support_capture_subprogram (spargv[0], spargv, NULL);
support_capture_subprocess_check (&result, "tst-tunables", 0, support_capture_subprocess_check (&result, "tst-tunables", 0,
sc_allow_stderr); sc_allow_stderr);
support_capture_subprocess_free (&result); support_capture_subprocess_free (&result);