dedup

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

commit dcd160319defab89c482448737c8f80a6b005570
parent 2fcad321a15f6d09e77b70650e9737bd2d370a6e
Author: sin <sin@2f30.org>
Date:   Sun,  5 May 2019 17:50:02 +0100

Avoid chdir calls in dup-gc(1) and dup-init(1)

chdir() interferes with the locking logic.

Diffstat:
Mdup-gc.c | 15+++++++++------
Mdup-init.c | 24++++++++++++++++--------
2 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/dup-gc.c b/dup-gc.c @@ -3,6 +3,7 @@ #include <err.h> #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -26,6 +27,7 @@ usage(void) int main(int argc, char *argv[]) { + char path[PATH_MAX]; unsigned char key[KEYSIZE]; struct bctx *bctx; /* block context */ struct bparam bpar; @@ -69,14 +71,15 @@ main(int argc, char *argv[]) bpar.key = NULL; } - if (chdir(repo) < 0) - err(1, "chdir: %s", repo); + if (snprintf(path, sizeof(path), "%s/%s", + repo, STORAGEPATH) >= sizeof(path)) + errx(1, "snprintf: %s: path too long", path); - if (bopen(STORAGEPATH, B_RDWR, 0600, &bpar, &bctx) < 0) - berr("bopen: %s", STORAGEPATH); + if (bopen(path, B_RDWR, 0600, &bpar, &bctx) < 0) + berr("bopen: %s", path); if (bgc(bctx) < 0) - berr("bgc: %s", STORAGEPATH); + berr("bgc: %s", path); if (bclose(bctx) < 0) - berr("bclose: %s", STORAGEPATH); + berr("bclose: %s", path); return 0; } diff --git a/dup-init.c b/dup-init.c @@ -3,6 +3,7 @@ #include <err.h> #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -11,6 +12,7 @@ #include "block.h" #include "config.h" #include "key.h" +#include "misc.h" #include "snap.h" int verbose; @@ -26,6 +28,8 @@ usage(void) int main(int argc, char *argv[]) { + char spath[PATH_MAX]; + char bpath[PATH_MAX]; unsigned char key[KEYSIZE]; struct bctx *bctx; /* block context */ struct bparam bpar; @@ -78,16 +82,20 @@ main(int argc, char *argv[]) bpar.key = NULL; } + if (snprintf(spath, sizeof(spath), "%s/%s", + repo, ARCHIVEPATH) >= sizeof(spath)) + errx(1, "snprintf: %s: path too long", spath); + if (snprintf(bpath, sizeof(bpath), "%s/%s", + repo, STORAGEPATH) >= sizeof(bpath)) + errx(1, "snprintf: %s: path too long", bpath); + if (mkdir(repo, 0700) < 0) err(1, "mkdir: %s", repo); - if (chdir(repo) < 0) - err(1, "chdir: %s", repo); - - if (mkdir(ARCHIVEPATH, 0700) < 0) - err(1, "mkdir: %s", ARCHIVEPATH); - if (bcreat(STORAGEPATH, 0600, &bpar, &bctx) < 0) - berr("bcreat: %s", STORAGEPATH); + if (mkdir(spath, 0700) < 0) + err(1, "mkdir: %s", spath); + if (bcreat(bpath, 0600, &bpar, &bctx) < 0) + berr("bcreat: %s", bpath); if (bclose(bctx) < 0) - berr("bclose: %s", STORAGEPATH); + berr("bclose: %s", bpath); return 0; }