summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--libdaemon/dexec.c29
-rw-r--r--libdaemon/dexec.h3
-rw-r--r--libdaemon/dfork.c2
-rw-r--r--libdaemon/dlog.c2
-rw-r--r--libdaemon/dlog.h2
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 */