]> mj.ucw.cz Git - libucw.git/commitdiff
Daemon: Reverted to one-level locking and added bits of docs
authorMartin Mares <mj@ucw.cz>
Tue, 17 Jul 2012 20:50:50 +0000 (22:50 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 17 Jul 2012 20:50:50 +0000 (22:50 +0200)
ucw/daemon.c
ucw/daemon.h

index 04060afd3257fa93cd4a7a0b401eed95faabdc3c..0012db4605bb111e30bcd6c65a729312c5a10956 100644 (file)
@@ -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);
     }
 }
 
index c00f00d1a5762d5e79b1729bc685ed352e03f503..0cf87086ff86d20d6c159d9428d0545476e2c452 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <sys/types.h>
 
+/** 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("/")
 };