summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-17 16:06:40 -0400
committerJune McEnroe <june@causal.agency>2020-08-17 16:06:40 -0400
commitea96ef48cbf4980b7dd3dd61f944091ead821f20 (patch)
tree2433e257989c06aa679e3a8983f0f921093d9bdd
parentTruncate PID file after opening and locking (diff)
downloadcatsit-ea96ef48cbf4980b7dd3dd61f944091ead821f20.tar.gz
catsit-ea96ef48cbf4980b7dd3dd61f944091ead821f20.zip
Use a non-blocking lock on the PID file
-rw-r--r--daemon.c8
1 files 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);
 	}
r> 2014-01-17auth: document tweakables in lua scriptJason A. Donenfeld 2014-01-17repolist: make owner clickable to searchJason A. Donenfeld 2014-01-17ui-shared: move about tab all the way to the leftJason A. Donenfeld 2014-01-17filter: don't forget to reap the auth filterJason A. Donenfeld 2014-01-17cgit.c: free tmp variableJason A. Donenfeld 2014-01-17Switch to exclusively using global ctxLukas Fleischer 2014-01-16auth: have cgit calculate login addressJason A. Donenfeld 2014-01-16auth: lua string comparisons are time invariantJason A. Donenfeld 2014-01-16authentication: use hidden form instead of refererJason A. Donenfeld 2014-01-16auth: add basic authentication filter frameworkJason A. Donenfeld 2014-01-16t0111: Additions and fixesLukas Fleischer 2014-01-16parsing.c: Remove leading space from committerLukas Fleischer