summaryrefslogtreecommitdiffstats
path: root/libdaemon/dexec.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-09-10 09:52:24 +0000
committerLennart Poettering <lennart@poettering.net>2005-09-10 09:52:24 +0000
commit5e88553351ad70b610f1e2197699b87ab0f9da18 (patch)
tree41ba1a4b1f861e83dfc5bdfdbacb9b0c50cd82f4 /libdaemon/dexec.c
parent2948e925db6cbe9e355d6d8268e864b537ea63af (diff)
* 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
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;
+ }
+ }
}