diff options
Diffstat (limited to 'libdaemon')
-rw-r--r-- | libdaemon/dexec.c | 29 | ||||
-rw-r--r-- | libdaemon/dexec.h | 3 | ||||
-rw-r--r-- | libdaemon/dfork.c | 2 | ||||
-rw-r--r-- | libdaemon/dlog.c | 2 | ||||
-rw-r--r-- | libdaemon/dlog.h | 2 |
5 files changed, 26 insertions, 12 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; + } + } } diff --git a/libdaemon/dexec.h b/libdaemon/dexec.h index dd863fc..4bcc48d 100644 --- a/libdaemon/dexec.h +++ b/libdaemon/dexec.h @@ -38,7 +38,8 @@ extern "C" { * specified directory and return the return value of the program in * the specified pointer. The calling process is blocked until the * child finishes and all child output (either STDOUT or STDIN) has - * been written to syslog. + * been written to syslog. Running this function requires that + * daemon_siginal() has been called with SIGCHLD as argument. * * @param dir Working directory for the process. * @param ret A pointer to an integer to write the return value of the program to. diff --git a/libdaemon/dfork.c b/libdaemon/dfork.c index c84cb58..263c6f5 100644 --- a/libdaemon/dfork.c +++ b/libdaemon/dfork.c @@ -285,7 +285,7 @@ int daemon_retval_send(int i) { if (r != sizeof(i)) { if (r < 0) - daemon_log(LOG_ERR, "read() failed while writing return value to pipe: %s", strerror(errno)); + daemon_log(LOG_ERR, "write() failed while writing return value to pipe: %s", strerror(errno)); else daemon_log(LOG_ERR, "write() too short while writing return value from pipe"); diff --git a/libdaemon/dlog.c b/libdaemon/dlog.c index 88c4e60..64f5227 100644 --- a/libdaemon/dlog.c +++ b/libdaemon/dlog.c @@ -29,7 +29,7 @@ #include "dlog.h" enum daemon_log_flags daemon_log_use = DAEMON_LOG_AUTO|DAEMON_LOG_STDERR; -char* daemon_log_ident = NULL; +const char* daemon_log_ident = NULL; void daemon_log(int prio, const char* template, ...) { va_list arglist; diff --git a/libdaemon/dlog.h b/libdaemon/dlog.h index 8e42c86..a09bf41 100644 --- a/libdaemon/dlog.h +++ b/libdaemon/dlog.h @@ -48,7 +48,7 @@ extern enum daemon_log_flags daemon_log_use; /** Specifies the syslog identification, use daemon_ident_from_argv0() * to set this to a sensible value or generate your own. */ -extern char* daemon_log_ident; +extern const char* daemon_log_ident; #ifdef __GNUC__ /** A macro for making use of GCCs printf compilation warnings */ |