X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-inhibit.c;h=cfae186edd615c5c8e4e3c799acca50f3aaa8c26;hb=059696ac014da265ee2d1b062cd0dc7bee3d2001;hp=a9f76d6c4ed29c963ac986c1936350f9e87e4e83;hpb=79c831b10cef03d95bf387c80c8d95f238fb2e03;p=elogind.git diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index a9f76d6c4..cfae186ed 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -86,11 +86,11 @@ int inhibitor_save(Inhibitor *i) { r = mkdir_safe_label("/run/systemd/inhibit", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(i->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fchmod(fileno(f), 0644); @@ -132,19 +132,24 @@ int inhibitor_save(Inhibitor *i) { if (i->fifo_path) fprintf(f, "FIFO=%s\n", i->fifo_path); - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, i->state_file) < 0) { + if (rename(temp_path, i->state_file) < 0) { r = -errno; - unlink(i->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save inhibit data %s: %m", i->state_file); + return 0; - return r; +fail: + (void) unlink(i->state_file); + + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save inhibit data %s: %m", i->state_file); } int inhibitor_start(Inhibitor *i) {