dedup

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

commit ba824c61fa56f57bb37251927c5b8d2b687167af
parent 8eb1fae6267c34433156caab59ca534e06b85901
Author: sin <sin@2f30.org>
Date:   Sun, 12 May 2019 19:27:38 +0100

Set errors in key.c

Diffstat:
Mdup-check.c | 2+-
Mdup-gc.c | 2+-
Mdup-init.c | 2+-
Mdup-keygen.c | 5+++--
Mdup-pack.c | 2+-
Mdup-unpack.c | 2+-
Mkey.c | 24++++++++++++++++++------
7 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/dup-check.c b/dup-check.c @@ -52,7 +52,7 @@ loadkey(char *keyfile) if (fd < 0) err(1, "open: %s", keyfile); if (readkey(fd, param.key, sizeof(param.key)) < 0) - errx(1, "readkey: failed"); + printerr("readkey: %s", keyfile); param.keyloaded = 1; if (close(fd) < 0) err(1, "close: %s", keyfile); diff --git a/dup-gc.c b/dup-gc.c @@ -50,7 +50,7 @@ loadkey(char *keyfile) if (fd < 0) err(1, "open: %s", keyfile); if (readkey(fd, param.key, sizeof(param.key)) < 0) - errx(1, "readkey: failed"); + printerr("readkey: %s", keyfile); param.keyloaded = 1; if (close(fd) < 0) err(1, "close: %s", keyfile); diff --git a/dup-init.c b/dup-init.c @@ -50,7 +50,7 @@ loadkey(char *keyfile) if (fd < 0) err(1, "open: %s", keyfile); if (readkey(fd, param.key, sizeof(param.key)) < 0) - errx(1, "readkey: failed"); + printerr("readkey: %s", keyfile); param.keyloaded = 1; if (close(fd) < 0) err(1, "close: %s", keyfile); diff --git a/dup-keygen.c b/dup-keygen.c @@ -10,6 +10,7 @@ #include "arg.h" #include "config.h" #include "key.h" +#include "misc.h" #include "state.h" struct param param; /* unused */ @@ -44,9 +45,9 @@ main(int argc, char *argv[]) if (fd < 0) err(1, "open: %s", argv[0]); if (keygen(key, sizeof(key)) < 0) - errx(1, "keygen: failed"); + printerr("keygen"); if (writekey(fd, key, sizeof(key)) < 0) - errx(1, "writekey: failed"); + printerr("writekey: %s", argv[0]); fsync(fd); if (close(fd) < 0) err(1, "close: %s", argv[0]); diff --git a/dup-pack.c b/dup-pack.c @@ -51,7 +51,7 @@ loadkey(char *keyfile) if (fd < 0) err(1, "open: %s", keyfile); if (readkey(fd, param.key, sizeof(param.key)) < 0) - errx(1, "readkey: failed"); + printerr("readkey: %s", keyfile); param.keyloaded = 1; if (close(fd) < 0) err(1, "close: %s", keyfile); diff --git a/dup-unpack.c b/dup-unpack.c @@ -50,7 +50,7 @@ loadkey(char *keyfile) if (fd < 0) err(1, "open: %s", keyfile); if (readkey(fd, param.key, sizeof(param.key)) < 0) - errx(1, "readkey: failed"); + printerr("readkey: %s", keyfile); param.keyloaded = 1; if (close(fd) < 0) err(1, "close: %s", keyfile); diff --git a/key.c b/key.c @@ -10,10 +10,14 @@ int keygen(unsigned char *key, size_t n) { assert(KEYSIZE == crypto_aead_xchacha20poly1305_ietf_KEYBYTES); - if (n != KEYSIZE) + if (n != KEYSIZE) { + seterr("invalid key size"); return -1; - if (sodium_init() < 0) + } + if (sodium_init() < 0) { + seterr("sodium_init: failed"); return -1; + } crypto_aead_xchacha20poly1305_ietf_keygen(key); return 0; } @@ -22,10 +26,14 @@ int writekey(int fd, unsigned char *key, size_t n) { assert(KEYSIZE == crypto_aead_xchacha20poly1305_ietf_KEYBYTES); - if (n != KEYSIZE) + if (n != KEYSIZE) { + seterr("invalid key size"); return -1; - if (xwrite(fd, key, n) != n) + } + if (xwrite(fd, key, n) != n) { + seterr("failed to write key"); return -1; + } return 0; } @@ -33,9 +41,13 @@ int readkey(int fd, unsigned char *key, size_t n) { assert(KEYSIZE == crypto_aead_xchacha20poly1305_ietf_KEYBYTES); - if (n != KEYSIZE) + if (n != KEYSIZE) { + seterr("invalid key size"); return -1; - if (xread(fd, key, n) != n) + } + if (xread(fd, key, n) != n) { + seterr("failed to read key"); return -1; + } return 0; }