diff options
author | Roy Marples <roy@marples.name> | 2007-09-21 08:49:43 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-09-21 08:49:43 +0000 |
commit | 45bd125dccdc7aef32af99cc6624a74dd2e24371 (patch) | |
tree | 130770fac1c33514444f9155947f56fc5bcb84ff /src/librc.c | |
parent | ca58877ed06b259ce37a6240746c733d47b0a179 (diff) |
Use a pty for prefixed output instead of pipes for stdout/stderr. This
is so that programs can get information about the controlling terminal.
This change was triggered by bug #188506 where it's possible that
stdin, stdout and stderr didn't point to a terminal but ended up on one
via our pipes. Using a pty means that stdout and stderr always point to
a terminal, but we lose the ability to tell them apart.
If there is not a pty available then we use un-prefixed output as normal.
This change has also introduced the need for a signal pipe so that
SIGCHLD can exit the loop cleanly.
Diffstat (limited to 'src/librc.c')
-rw-r--r-- | src/librc.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/librc.c b/src/librc.c index 728f1c45..f501719e 100644 --- a/src/librc.c +++ b/src/librc.c @@ -558,18 +558,15 @@ static pid_t _exec_service (const char *service, const char *arg) int rc_waitpid (pid_t pid) { int status = 0; pid_t savedpid = pid; + int retval = -1; errno = 0; - do { - pid = waitpid (savedpid, &status, 0); - if (pid < 0) { - if (errno != ECHILD) - eerror ("waitpid %d: %s", savedpid, strerror (errno)); - return (-1); - } - } while (! WIFEXITED (status) && ! WIFSIGNALED (status)); - - return (WIFEXITED (status) ? WEXITSTATUS (status) : EXIT_FAILURE); + while ((pid = waitpid (savedpid, &status, 0)) > 0) { + if (pid == savedpid) + retval = WIFEXITED (status) ? WEXITSTATUS (status) : EXIT_FAILURE; + } + + return (retval); } pid_t rc_stop_service (const char *service) |