about summary refs log tree commit diff
path: root/support/support_subprocess.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2021-04-09 20:55:45 +0530
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2021-04-12 19:03:19 +0530
commit716a3bdc41b2b4b864dc64475015ba51e35e1273 (patch)
tree103a573114c8263cec174ca7fd655ff4612f0ee9 /support/support_subprocess.c
parent8d4d77f6c848538cfb9e5ad0a14825e7ae4a1657 (diff)
downloadglibc-716a3bdc41b2b4b864dc64475015ba51e35e1273.tar.gz
glibc-716a3bdc41b2b4b864dc64475015ba51e35e1273.tar.xz
glibc-716a3bdc41b2b4b864dc64475015ba51e35e1273.zip
support: Add capability to fork an sgid child
Add a new function support_capture_subprogram_self_sgid that spawns an
sgid child of the running program with its own image and returns the
exit code of the child process.  This functionality is used by at
least three tests in the testsuite at the moment, so it makes sense to
consolidate.

There is also a new function support_subprogram_wait which should
provide simple system() like functionality that does not set up file
actions.  This is useful in cases where only the return code of the
spawned subprocess is interesting.

This patch also ports tst-secure-getenv to this new function.  A
subsequent patch will port other tests.  This also brings an important
change to tst-secure-getenv behaviour.  Now instead of succeeding, the
test fails as UNSUPPORTED if it is unable to spawn a setgid child,
which is how it should have been in the first place.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'support/support_subprocess.c')
-rw-r--r--support/support_subprocess.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/support/support_subprocess.c b/support/support_subprocess.c
index 2acfc57b7e..89e767ae47 100644
--- a/support/support_subprocess.c
+++ b/support/support_subprocess.c
@@ -93,6 +93,19 @@ support_subprogram (const char *file, char *const argv[])
 }
 
 int
+support_subprogram_wait (const char *file, char *const argv[])
+{
+  posix_spawn_file_actions_t fa;
+
+  posix_spawn_file_actions_init (&fa);
+  struct support_subprocess res = support_subprocess_init ();
+
+  res.pid = xposix_spawn (file, &fa, NULL, argv, environ);
+
+  return support_process_wait (&res);
+}
+
+int
 support_process_wait (struct support_subprocess *proc)
 {
   xclose (proc->stdout_pipe[0]);