support: Close original descriptors in support_capture_subprocess

This commit is contained in:
Florian Weimer 2018-12-01 21:43:36 +01:00
parent fc493bc9e6
commit 02cd5c1a8d
2 changed files with 12 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2018-12-01 Florian Weimer <fweimer@redhat.com>
* support/support_capture_subprocess.c
(support_capture_subprocess): Check that pipe descriptors have
expected values. Close original pipe descriptors in subprocess.
2018-12-01 Samuel Thibault <samuel.thibault@ens-lyon.org> 2018-12-01 Samuel Thibault <samuel.thibault@ens-lyon.org>
[BZ #23032] [BZ #23032]

View File

@ -59,8 +59,12 @@ support_capture_subprocess (void (*callback) (void *), void *closure)
int stdout_pipe[2]; int stdout_pipe[2];
xpipe (stdout_pipe); xpipe (stdout_pipe);
TEST_VERIFY (stdout_pipe[0] > STDERR_FILENO);
TEST_VERIFY (stdout_pipe[1] > STDERR_FILENO);
int stderr_pipe[2]; int stderr_pipe[2];
xpipe (stderr_pipe); xpipe (stderr_pipe);
TEST_VERIFY (stderr_pipe[0] > STDERR_FILENO);
TEST_VERIFY (stderr_pipe[1] > STDERR_FILENO);
TEST_VERIFY (fflush (stdout) == 0); TEST_VERIFY (fflush (stdout) == 0);
TEST_VERIFY (fflush (stderr) == 0); TEST_VERIFY (fflush (stderr) == 0);
@ -72,6 +76,8 @@ support_capture_subprocess (void (*callback) (void *), void *closure)
xclose (stderr_pipe[0]); xclose (stderr_pipe[0]);
xdup2 (stdout_pipe[1], STDOUT_FILENO); xdup2 (stdout_pipe[1], STDOUT_FILENO);
xdup2 (stderr_pipe[1], STDERR_FILENO); xdup2 (stderr_pipe[1], STDERR_FILENO);
xclose (stdout_pipe[1]);
xclose (stderr_pipe[1]);
callback (closure); callback (closure);
_exit (0); _exit (0);
} }