From 5e88553351ad70b610f1e2197699b87ab0f9da18 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 10 Sep 2005 09:52:24 +0000 Subject: * add a "const" to daemon_log_ident * fix log message in dfork.c * in dexec.c: call waitpid() in a loop and ignore EINTR * add a "const" to daemon_log_ident * minor doc update git-svn-id: file:///home/lennart/svn/public/libdaemon/trunk@90 153bfa13-eec0-0310-be40-b0cb6a0e1b4b --- libdaemon/dexec.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'libdaemon/dexec.c') diff --git a/libdaemon/dexec.c b/libdaemon/dexec.c index b8f74c1..347dfa6 100644 --- a/libdaemon/dexec.c +++ b/libdaemon/dexec.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "dlog.h" #include "dsignal.h" @@ -51,6 +52,8 @@ int daemon_exec(const char *dir, int *ret, const char *prog, ...) { fd_set fds; va_list ap; + assert(daemon_signal_fd() >= 0); + if (pipe(p) < 0) { daemon_log(LOG_ERR, "pipe() failed: %s", strerror(errno)); return -1; @@ -164,15 +167,25 @@ int daemon_exec(const char *dir, int *ret, const char *prog, ...) { buf[n] = 0; daemon_log(LOG_WARNING, "client: %s", buf); } - - waitpid(pid, &r, 0); - + close(p[0]); - if (!WIFEXITED(r)) - return -1; + for (;;) { + if (waitpid(pid, &r, 0) < 0) { + + if (errno == EINTR) + continue; + + daemon_log(LOG_ERR, "waitpid(): %s", strerror(errno)); + return -1; + } else { + if (!WIFEXITED(r)) + return -1; - if (ret) - *ret = WEXITSTATUS(r); - return 0; + if (ret) + *ret = WEXITSTATUS(r); + + return 0; + } + } } -- cgit