Exclusively lock save file
Prevents two instances of catgirl from using the same save file and clobbering each other's data.master
parent
c6009cf13c
commit
f6e8078c46
6
ui.c
6
ui.c
|
@ -32,6 +32,7 @@
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
@ -1183,6 +1184,11 @@ void uiLoad(const char *name) {
|
||||||
if (!saveFile) exit(EX_CANTCREAT);
|
if (!saveFile) exit(EX_CANTCREAT);
|
||||||
rewind(saveFile);
|
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;
|
time_t signature;
|
||||||
fread(&signature, sizeof(signature), 1, saveFile);
|
fread(&signature, sizeof(signature), 1, saveFile);
|
||||||
if (ferror(saveFile)) err(EX_IOERR, "fread");
|
if (ferror(saveFile)) err(EX_IOERR, "fread");
|
||||||
|
|
Loading…
Reference in New Issue