diff options
author | Mattias Andrée <maandree@kth.se> | 2023-06-23 11:52:23 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-06-23 11:52:23 +0200 |
commit | 3361d8512c4d6dfeda55280a077d951a3382ddae (patch) | |
tree | 96f668ab177e84ac9246e49e2c97bfc35de8f12e | |
parent | Fix comment (diff) | |
download | key2root-3361d8512c4d6dfeda55280a077d951a3382ddae.tar.gz key2root-3361d8512c4d6dfeda55280a077d951a3382ddae.tar.bz2 key2root-3361d8512c4d6dfeda55280a077d951a3382ddae.tar.xz |
Fix error handling in key2root-rmkey on failure to commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | key2root-rmkey.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/key2root-rmkey.c b/key2root-rmkey.c index 82f04eb..dd7274d 100644 --- a/key2root-rmkey.c +++ b/key2root-rmkey.c @@ -210,14 +210,18 @@ out: fprintf(stderr, "%s: open %s O_WRONLY|O_CREAT|O_EXCL 0600: %s\n", argv0, path2, strerror(errno)); exit(1); } - if (writeall(fd, data, data_len) || close(fd)) { + if (writeall(fd, data, data_len)) { fprintf(stderr, "%s: write %s: %s\n", argv0, path2, strerror(errno)); - if (unlink(path2)) - fprintf(stderr, "%s: unlink %s: %s\n", argv0, path2, strerror(errno)); - exit(1); + close(fd) + goto saved_failed; + } + if (close(fd)) { + fprintf(stderr, "%s: write %s: %s\n", argv0, path2, strerror(errno)); + goto saved_failed; } if (rename(path2, path)) { fprintf(stderr, "%s: rename %s %s: %s\n", argv0, path2, path, strerror(errno)); + saved_failed: if (unlink(path2)) fprintf(stderr, "%s: unlink %s: %s\n", argv0, path2, strerror(errno)); exit(1); |