From 8c44c885e160296b75c55363a8ec6b1178dc9cb7 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 23 Nov 2022 15:34:07 +0100 Subject: [PATCH] Added calls to flock() in object functions. --- data.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/data.c b/data.c index 457219c..6d48fd4 100644 --- a/data.c +++ b/data.c @@ -10,8 +10,9 @@ #include "snac.h" #include -#include #include +#include +#include double db_layout = 2.1; @@ -218,6 +219,8 @@ int object_get(const char *id, d_char **obj, const char *type) FILE *f; if ((f = fopen(fn, "r")) != NULL) { + flock(fileno(f), LOCK_SH); + xs *j = xs_readall(f); fclose(f); @@ -252,6 +255,8 @@ int object_add(const char *id, d_char *obj) FILE *f; if ((f = fopen(fn, "w")) != NULL) { + flock(fileno(f), LOCK_EX); + xs *j = xs_json_dumps_pp(obj, 4); fwrite(j, strlen(j), 1, f);