commit 8c44c88

default  ·  2022-11-23 14:34:07 +0000 UTC
parent eb2cde3
Added calls to flock() in object functions.
1 files changed,  +6, -1
M data.c
M data.c
+6, -1
 1@@ -10,8 +10,9 @@
 2 #include "snac.h"
 3 
 4 #include <time.h>
 5-#include <glob.h>
 6 #include <sys/stat.h>
 7+#include <sys/file.h>
 8+#include <fcntl.h>
 9 
10 double db_layout = 2.1;
11 
12@@ -218,6 +219,8 @@ int object_get(const char *id, d_char **obj, const char *type)
13     FILE *f;
14 
15     if ((f = fopen(fn, "r")) != NULL) {
16+        flock(fileno(f), LOCK_SH);
17+
18         xs *j = xs_readall(f);
19         fclose(f);
20 
21@@ -252,6 +255,8 @@ int object_add(const char *id, d_char *obj)
22     FILE *f;
23 
24     if ((f = fopen(fn, "w")) != NULL) {
25+        flock(fileno(f), LOCK_EX);
26+
27         xs *j = xs_json_dumps_pp(obj, 4);
28 
29         fwrite(j, strlen(j), 1, f);