dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit 5e492634032f66a0ea3a17322265eca49efc2592
parent bbae2410b3c189917a266eb6fbca6781051e8951
Author: sin <sin@2f30.org>
Date:   Mon, 18 Feb 2019 19:37:51 +0000

Lock the index/store/cache file descriptors

This is to prevent two invocations of dedup to corrupt the store.

Diffstat:
MTODO | 1-
Mdedup.c | 6++++++
2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/TODO b/TODO @@ -1,3 +1,2 @@ endianness agnostic -file locking overflow checks diff --git a/dedup.c b/dedup.c @@ -1,4 +1,5 @@ #include <sys/stat.h> +#include <sys/file.h> #include <err.h> #include <fcntl.h> #include <stdio.h> @@ -678,6 +679,11 @@ init(void) if (cfd < 0) err(1, "open %s", CACHEF); + if (flock(ifd, LOCK_NB | LOCK_EX) < 0 || + flock(sfd, LOCK_NB | LOCK_EX) < 0 || + flock(cfd, LOCK_NB | LOCK_EX) < 0) + errx(1, "busy lock"); + if (fstat(ifd, &sb) < 0) err(1, "fstat %s", INDEXF); if (sb.st_size != 0) {