diff options
author | Lennart Poettering <lennart@poettering.net> | 2003-10-20 21:53:46 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2003-10-20 21:53:46 +0000 |
commit | ce36dd0994ffa833ff0ce18e57a8776ff1103d8d (patch) | |
tree | b0685edee04c84b0fd1a2593c1afffaa18da0448 /src/dpid.c | |
parent | df2e940cfd540ea46dd95da77ebacc35ae58423e (diff) |
commit release 0.3
git-svn-id: file:///home/lennart/svn/public/libdaemon/trunk@41 153bfa13-eec0-0310-be40-b0cb6a0e1b4b
Diffstat (limited to 'src/dpid.c')
-rw-r--r-- | src/dpid.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -25,6 +25,7 @@ #include <errno.h> #include <sys/types.h> #include <sys/stat.h> +#include <time.h> #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; |