summaryrefslogtreecommitdiffstats
path: root/libdaemon/dexec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdaemon/dexec.c')
-rw-r--r--libdaemon/dexec.c29
1 files changed, 21 insertions, 8 deletions
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 <fcntl.h>
#include <stdio.h>
#include <stdarg.h>
+#include <assert.h>
#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;
+ }
+ }
}