about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-06-11 21:09:46 -0400
committerJune McEnroe <june@causal.agency>2021-06-11 21:15:34 -0400
commitf6e8078c4698d371359ff8827a017535e421496c (patch)
tree2dbe42ed831a8bcbc1a337fe75f2a5e4f764cd42
parentOpen save file with "a+" (diff)
downloadcatgirl-f6e8078c4698d371359ff8827a017535e421496c.tar.gz
catgirl-f6e8078c4698d371359ff8827a017535e421496c.zip
Exclusively lock save file
Prevents two instances of catgirl from using the same save file and
clobbering each other's data.
Diffstat (limited to '')
-rw-r--r--ui.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ui.c b/ui.c
index 22b098e..2beba88 100644
--- a/ui.c
+++ b/ui.c
@@ -32,6 +32,7 @@
 #include <curses.h>
 #include <err.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <limits.h>
 #include <signal.h>
 #include <stdarg.h>
@@ -1183,6 +1184,11 @@ void uiLoad(const char *name) {
 	if (!saveFile) exit(EX_CANTCREAT);
 	rewind(saveFile);
 
+	int error = flock(fileno(saveFile), LOCK_EX | LOCK_NB);
+	if (error && errno == EWOULDBLOCK) {
+		errx(EX_CANTCREAT, "%s: save file in use", name);
+	}
+
 	time_t signature;
 	fread(&signature, sizeof(signature), 1, saveFile);
 	if (ferror(saveFile)) err(EX_IOERR, "fread");
77e6922ba0abdbc5&follow=1'>Actually do HTML &quot; escapingJune McEnroe 2019-02-10Set git commit.verboseJune McEnroe 2019-02-10Add back missing static keywordJune McEnroe2021-01-12Use hilex for bin HTMLJune McEnroe 2021-01-12Don't output a pre in hilex by defaultJune McEnroe 2021-01-12Move hilex out of hilex directoryJune McEnroe 2021-01-12Consolidate hilex formatters into hilex.cJune McEnroe 2021-01-12Remove hacky tagging from hilexJune McEnroe 2021-01-12Add htagml -iJune McEnroe 2021-01-12Render tag index in HTMLJune McEnroe 2021-01-12Add htagml -xJune McEnroe 2021-01-12Prevent matching the same tag twiceJune McEnroe 2021-01-12Process htagml file line by lineJune McEnroe 2021-01-12Split fields by tab onlyJune McEnroe 2021-01-12List both Makefile and html.sh under README.7June McEnroe 2021-01-12Add htagml exampleJune McEnroe 2021-01-12Use mandoc and htagml for bin htmlJune McEnroe 2021-01-12Add htagmlJune McEnroe 2021-01-12Replace causal.agency with a simple mdoc pageJune McEnroe 2021-01-11Publish "Using vi"June McEnroe 2021-01-11Enable diff.colorMovedJune McEnroe 2021-01-10Set less search case-insensitiveJune McEnroe 2021-01-10Set EXINITJune McEnroe 2021-01-09Add c -t flag to print expression typeJune McEnroe 2021-01-05Update taglineJune McEnroe