summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-09 18:58:47 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-09 22:06:46 -0400
commitfaf9da01ad93bd48523f0966646bbd3ca85a2951 (patch)
tree1cee8ffb941c22c54c4b1c70bb5e2cb6ef3a80d4 /src/journal
parent977eaa1eae53af7f418d87fcb42f4a4d34aad739 (diff)
journalctl: unlink without checking with access first
It is more elegant to do this in one step. Coverity complains about the TOCTOU difference, but it is not an actual problem (CID #1237777).
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journalctl.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 2b0e00ee8f..f0f03b0697 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1316,19 +1316,16 @@ static int setup_keys(void) {
SD_ID128_FORMAT_VAL(machine)) < 0)
return log_oom();
- if (access(p, F_OK) >= 0) {
- if (arg_force) {
- r = unlink(p);
- if (r < 0) {
- log_error_errno(errno, "unlink(\"%s\") failed: %m", p);
- r = -errno;
- goto finish;
- }
- } else {
- log_error("Sealing key file %s exists already. (--force to recreate)", p);
- r = -EEXIST;
+ if (arg_force) {
+ r = unlink(p);
+ if (r < 0 && errno != ENOENT) {
+ r = log_error_errno(errno, "unlink(\"%s\") failed: %m", p);
goto finish;
}
+ } else if (access(p, F_OK) >= 0) {
+ log_error("Sealing key file %s exists already. Use --force to recreate.", p);
+ r = -EEXIST;
+ goto finish;
}
if (asprintf(&k, "/var/log/journal/" SD_ID128_FORMAT_STR "/fss.tmp.XXXXXX",