From: Martin Mares Date: Tue, 17 Jul 2012 20:50:50 +0000 (+0200) Subject: Daemon: Reverted to one-level locking and added bits of docs X-Git-Tag: v5.99~155 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=7c6ad545b6423bab37bbb8658db9e35964cc9537;p=libucw.git Daemon: Reverted to one-level locking and added bits of docs --- diff --git a/ucw/daemon.c b/ucw/daemon.c index 04060afd..0012db46 100644 --- a/ucw/daemon.c +++ b/ucw/daemon.c @@ -148,7 +148,7 @@ void daemon_run(struct daemon_params *dp, void (*body)(struct daemon_params *dp) exit(0); } - // Write PID and downgrade the lock to shared + // Write PID if (dp->pid_file) { char buf[32]; @@ -156,11 +156,9 @@ void daemon_run(struct daemon_params *dp, void (*body)(struct daemon_params *dp) ASSERT(c <= (int) sizeof(buf)); if (lseek(dp->pid_fd, 0, SEEK_SET) < 0 || write(dp->pid_fd, buf, c) != c || - ftruncate(dp->pid_fd, c)) + ftruncate(dp->pid_fd, c) || + close(dp->pid_fd) < 0) die("Cannot write PID to `%s': %m", dp->pid_file); - if (flock(dp->pid_fd, LOCK_SH | LOCK_NB) < 0) - die("Cannot re-lock `%s': %m", dp->pid_file); - close(dp->pid_fd); } } diff --git a/ucw/daemon.h b/ucw/daemon.h index c00f00d1..0cf87086 100644 --- a/ucw/daemon.h +++ b/ucw/daemon.h @@ -12,6 +12,7 @@ #include +/** Parameters passed to the daemon helper. **/ struct daemon_params { uns flags; // DAEMON_FLAG_xxx const char *pid_file; // A path to PID file (optional) @@ -26,6 +27,7 @@ struct daemon_params { int pid_fd; }; +/** Flags passed to the daemon helper. **/ enum daemon_flags { DAEMON_FLAG_PRESERVE_CWD = 1, // Skip chdir("/") };