From ea96ef48cbf4980b7dd3dd61f944091ead821f20 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 17 Aug 2020 16:06:40 -0400 Subject: Use a non-blocking lock on the PID file --- daemon.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/daemon.c b/daemon.c index 1643200..a1be594 100644 --- a/daemon.c +++ b/daemon.c @@ -247,11 +247,13 @@ int main(int argc, char *argv[]) { int pidFile = -1; if (pidPath) { - pidFile = open( - pidPath, O_WRONLY | O_CREAT | O_EXLOCK | O_CLOEXEC, 0600 - ); + pidFile = open(pidPath, O_WRONLY | O_CREAT | O_CLOEXEC, 0600); if (pidFile < 0) err(EX_CANTCREAT, "%s", pidPath); + error = flock(pidFile, LOCK_EX | LOCK_NB); + if (error && errno != EWOULDBLOCK) err(EX_IOERR, "%s", pidPath); + if (error) errx(EX_CANTCREAT, "%s: file is locked", pidPath); + error = ftruncate(pidFile, 0); if (error) err(EX_IOERR, "%s", pidPath); } -- cgit 1.4.1 ed='selected'>daemon collaborative ASCII art
about summary refs log tree commit diff homepage
path: root/torus.h (unfollow)
Commit message (Collapse)Author
2017-07-30Add tile create and access timestampsJune McEnroe
2017-07-30Assert stable struct Tile field offsetsJune McEnroe
2017-07-30Add chroot.shJune McEnroe
2017-07-30Add ` commandJune McEnroe
2017-07-30Add sshd_configJune McEnroe
2017-07-30Add termcap patchJune McEnroe