exit(0);
}
- // Write PID and downgrade the lock to shared
+ // Write PID
if (dp->pid_file)
{
char buf[32];
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);
}
}
#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)
int pid_fd;
};
+/** Flags passed to the daemon helper. **/
enum daemon_flags {
DAEMON_FLAG_PRESERVE_CWD = 1, // Skip chdir("/")
};