diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2006-10-18 16:47:35 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:21:25 -0500 |
commit | e2383f7ecb5cb5de364a30bed57db32c0e0890c8 (patch) | |
tree | 6036d6f9b5ef58458ec2ddfae2b220468e9df26d /source4/torture | |
parent | 3a479ae55085e8dd315429dc5979534628891bbc (diff) | |
download | samba-e2383f7ecb5cb5de364a30bed57db32c0e0890c8.tar.gz samba-e2383f7ecb5cb5de364a30bed57db32c0e0890c8.tar.bz2 samba-e2383f7ecb5cb5de364a30bed57db32c0e0890c8.zip |
r19396: Assume socketpair() is always available (cared for by libreplace) and
create a socket for stderr.
(This used to be commit 16b6dbd713e306c88b5251e5092b8731749c5263)
Diffstat (limited to 'source4/torture')
-rw-r--r-- | source4/torture/subunit.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/source4/torture/subunit.c b/source4/torture/subunit.c index bed1972079..b7d2ad405c 100644 --- a/source4/torture/subunit.c +++ b/source4/torture/subunit.c @@ -89,23 +89,26 @@ bool torture_subunit_load_testsuites(const char *directory, bool recursive, return true; } -static pid_t piped_child(char* const command[], int *f_in) +static pid_t piped_child(char* const command[], int *f_stdout, int *f_stderr) { pid_t pid; - int sock[2]; + int sock_out[2], sock_err[2]; -#ifdef HAVE_SOCKETPAIR - if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) { -#else - if (pipe(sock) == -1) { -#endif + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock_out) == -1) { DEBUG(0, ("socketpair: %s", strerror(errno))); return -1; } - *f_in = sock[0]; + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock_err) == -1) { + DEBUG(0, ("socketpair: %s", strerror(errno))); + return -1; + } + + *f_stdout = sock_out[0]; + *f_stderr = sock_err[0]; - fcntl(sock[0], F_SETFL, O_NONBLOCK); + fcntl(sock_out[0], F_SETFL, O_NONBLOCK); + fcntl(sock_err[0], F_SETFL, O_NONBLOCK); pid = fork(); @@ -118,15 +121,18 @@ static pid_t piped_child(char* const command[], int *f_in) close(0); close(1); close(2); - close(sock[0]); + close(sock_out[0]); + close(sock_err[0]); - dup2(sock[1], 0); - dup2(sock[1], 1); + dup2(sock_out[1], 0); + dup2(sock_out[1], 1); + dup2(sock_err[1], 2); execvp(command[0], command); exit(-1); } - close(sock[1]); + close(sock_out[1]); + close(sock_err[1]); return pid; } @@ -171,7 +177,7 @@ bool torture_subunit_run_suite(struct torture_context *context, struct torture_suite *suite) { static char *command[2]; - int fd; + int fd_out, fd_err; pid_t pid; size_t size; char *p, *q; @@ -185,7 +191,7 @@ bool torture_subunit_run_suite(struct torture_context *context, command[0] = talloc_strdup(context, suite->path); command[1] = NULL; - pid = piped_child(command, &fd); + pid = piped_child(command, &fd_out, &fd_err); if (pid == -1) return false; @@ -199,7 +205,7 @@ bool torture_subunit_run_suite(struct torture_context *context, return false; } - while ((size = read(fd, buffer+offset, sizeof(buffer-offset) > 0))) { + while ((size = read(fd_out, buffer+offset, sizeof(buffer-offset) > 0))) { char *eol; buffer[offset+size] = '\0'; |