tests: tests stderr redirected to the output

This commit is contained in:
Jan Hák 2023-04-26 13:16:48 +02:00 committed by Daniel Salzman
parent 3a9e5d3cd5
commit 3f3d78c19b

View file

@ -384,14 +384,14 @@ skip_whitespace(const char *p)
}
/*
* Start a program, connecting its stdout to a pipe on our end and its stderr
* to /dev/null, and storing the file descriptor to read from in the two
* argument. Returns the PID of the new process. Errors are fatal.
* Start a program, connecting its output (stdout and stderr) to a pipe on our
* end, and storing the file descriptor to read from in the second argument.
* Returns the PID of the new process. Errors are fatal.
*/
static pid_t
test_start(const char *path, int *fd)
{
int fds[2], errfd;
int fds[2];
pid_t child;
if (pipe(fds) == -1) {
@ -406,13 +406,10 @@ test_start(const char *path, int *fd)
sysdie("can't fork");
} else if (child == 0) {
/* In child. Set up our stdout and stderr. */
errfd = open("/dev/null", O_WRONLY);
if (errfd < 0)
_exit(CHILDERR_STDERR);
if (dup2(errfd, 2) == -1)
_exit(CHILDERR_DUP);
close(fds[0]);
if (dup2(fds[1], 1) == -1)
if (dup2(fds[1], STDOUT_FILENO) == -1)
_exit(CHILDERR_DUP);
if (dup2(fds[1], STDERR_FILENO) == -1)
_exit(CHILDERR_DUP);
/* Now, exec our process. */