From: Zbigniew Jędrzejewski-Szmek Date: Mon, 9 Mar 2015 22:58:47 +0000 (-0400) Subject: journalctl: unlink without checking with access first X-Git-Tag: v219.0~416 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=faf9da01ad93bd48523f0966646bbd3ca85a2951;p=elogind.git 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). --- diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 2b0e00ee8..f0f03b069 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",