From ce36dd0994ffa833ff0ce18e57a8776ff1103d8d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Oct 2003 21:53:46 +0000 Subject: commit release 0.3 git-svn-id: file:///home/lennart/svn/public/libdaemon/trunk@41 153bfa13-eec0-0310-be40-b0cb6a0e1b4b --- src/Makefile.am | 1 + src/dpid.c | 31 +++++++++++++++++++++++++++++++ src/dpid.h | 14 ++++++++++++++ 3 files changed, 46 insertions(+) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 129660f..c2719ed 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,3 +27,4 @@ libdaemon_la_SOURCES = \ dnonblock.c dnonblock.h \ dpid.c dpid.h +libdaemon_la_LDFLAGS = -version-info 1:0:1 diff --git a/src/dpid.c b/src/dpid.c index 6d91cae..6731573 100644 --- a/src/dpid.c +++ b/src/dpid.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "dpid.h" #include "dlog.h" @@ -89,6 +90,36 @@ int daemon_pid_file_kill(int s) { return 0; } +int daemon_pid_file_kill_wait(int s, int m) { + pid_t pid; + time_t t; + + if ((pid = daemon_pid_file_is_running()) < 0) + return -1; + + if (kill(pid, s) < 0) + return -1; + + t = time(NULL) + m; + + for (;;) { + int r; + struct timeval tv = { 0, 100000 }; + + if (time(NULL) > t) + return -1; + + if ((r = kill(pid, 0)) < 0 && errno != ESRCH) + return -1; + + if (r) + return 0; + + if (select(0, NULL, NULL, NULL, &tv) < 0) + return -1; + } +} + int daemon_pid_file_create(void) { const char *fn; FILE *f; diff --git a/src/dpid.h b/src/dpid.h index 8dde464..9812ad9 100644 --- a/src/dpid.h +++ b/src/dpid.h @@ -70,4 +70,18 @@ pid_t daemon_pid_file_is_running(void); */ int daemon_pid_file_kill(int s); +/** If this variable is defined to 1 iff daemon_pid_file_kill_wait() is supported.*/ +#define DAEMON_PID_FILE_KILL_WAIT_AVAILABLE 1 + +/** Similar to daemon_pid_file_kill() but waits until the process + * died. This functions is new in libdaemon 0.3. The macro + * DAEMON_PID_FILE_KILL_WAIT_AVAILABLE is defined iff libdaemon + * supports this function. + * + * @param s The signal to send + * @param m Seconds to wait at maximum + * @return zero on success, nonzero on failure (timeout condition is considered a failure) + */ +int daemon_pid_file_kill_wait(int s, int m); + #endif -- cgit