diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-06-12 23:06:56 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-06-12 23:07:33 +0200 |
commit | 034753ac13a9d4b308eee1e8d7c3285f6646c0d8 (patch) | |
tree | a4988fc72b7e8f905da0071386ff7f59c520b812 /src/machine/machine.c | |
parent | 1b99214789101976d6bbf75c351279584b071998 (diff) |
machine: minor modernizations
Diffstat (limited to 'src/machine/machine.c')
-rw-r--r-- | src/machine/machine.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/machine/machine.c b/src/machine/machine.c index a49cf81906..0b0d45bb26 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -176,12 +176,13 @@ int machine_save(Machine *m) { m->timestamp.realtime, m->timestamp.monotonic); - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto finish; - if (ferror(f) || rename(temp_path, m->state_file) < 0) { + if (rename(temp_path, m->state_file) < 0) { r = -errno; - unlink(m->state_file); - unlink(temp_path); + goto finish; } if (m->unit) { @@ -195,8 +196,12 @@ int machine_save(Machine *m) { } finish: - if (r < 0) + if (r < 0) { + if (temp_path) + unlink(temp_path); + log_error("Failed to save machine data %s: %s", m->state_file, strerror(-r)); + } return r; } |