From b38eb34d289866be7fd3adb1f005126facfcd280 Mon Sep 17 00:00:00 2001 From: tenox7 Date: Tue, 1 May 2018 02:51:34 -0700 Subject: file locking support --- fileio.c | 7 ++++++- wfm.h | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fileio.c b/fileio.c index c703898..0e2b389 100644 --- a/fileio.c +++ b/fileio.c @@ -2,7 +2,6 @@ #include "wfm.h" - /* // Debug dump vars //void debugdumpvars(void) { @@ -104,6 +103,9 @@ void receivefile(void) { if(!output) error("Unable to open file %s for writing.
%s", virt_filename, strerror(errno)); + if(flock(fileno(output), LOCK_EX) == -1) + error("Unable to lock file %s.
%s", virt_filename, strerror(errno)); + while(cgiFormFileRead(input, buff, sizeof(buff), &got) == cgiFormSuccess) if(got) if(fwrite(buff, got, 1, output) != 1) @@ -221,6 +223,9 @@ void edit_save(void) { if(!tempf) error("Unable to open temporary file %s.
%s", basename(tempname), strerror(errno)); + if(flock(fileno(tempf), LOCK_EX) == -1) + error("Unable to lock file %s.
%s", basename(tempname), strerror(errno)); + if(fwrite(buff, strlen(buff), 1, tempf) != 1) error("Unable to write to temporary file %s.
%s", basename(tempname), strerror(errno)); diff --git a/wfm.h b/wfm.h index 5657590..7e315bd 100644 --- a/wfm.h +++ b/wfm.h @@ -1,4 +1,4 @@ -#define VERSION "1.3.1" +#define VERSION "1.3.2" #define copyright "\n" \ "\n" @@ -52,6 +52,7 @@ #include #include #include +#include //#include #include "md5.h" #include "cgic.h" -- cgit v1.2.3