diff options
author | Daniel Mack <github@zonque.org> | 2015-07-29 20:43:54 +0200 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2015-07-29 20:43:54 +0200 |
commit | 65c85ef5118d88bc0d3459b6e8854bf1846190b9 (patch) | |
tree | 3c60aceafd3cbf6fe12eb6db934350950f4425cd /src/machine/machine.c | |
parent | 1051d049a8a5811135d83a89a430c5be846866ca (diff) | |
parent | dacd6cee76a08331b8c8616c5f30f70ee49aa2f9 (diff) |
Merge pull request #779 from poettering/fflush-and-check
tree-wide: port everything over to fflush_and_check()
Diffstat (limited to 'src/machine/machine.c')
-rw-r--r-- | src/machine/machine.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/machine/machine.c b/src/machine/machine.c index 05fc4f849f..ab26803683 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -112,13 +112,13 @@ int machine_save(Machine *m) { r = mkdir_safe_label("/run/systemd/machines", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(m->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; - fchmod(fileno(f), 0644); + (void) fchmod(fileno(f), 0644); fprintf(f, "# This is private data. Do not parse.\n" @@ -131,7 +131,7 @@ int machine_save(Machine *m) { escaped = cescape(m->unit); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "SCOPE=%s\n", escaped); /* We continue to call this "SCOPE=" because it is internal only, and we want to stay compatible with old files */ @@ -146,7 +146,7 @@ int machine_save(Machine *m) { escaped = cescape(m->service); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "SERVICE=%s\n", escaped); } @@ -157,7 +157,7 @@ int machine_save(Machine *m) { escaped = cescape(m->root_directory); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "ROOT=%s\n", escaped); } @@ -195,16 +195,13 @@ int machine_save(Machine *m) { r = fflush_and_check(f); if (r < 0) - goto finish; + goto fail; if (rename(temp_path, m->state_file) < 0) { r = -errno; - goto finish; + goto fail; } - free(temp_path); - temp_path = NULL; - if (m->unit) { char *sl; @@ -215,14 +212,15 @@ int machine_save(Machine *m) { (void) symlink(m->name, sl); } -finish: - if (temp_path) - unlink(temp_path); + return 0; - if (r < 0) - log_error_errno(r, "Failed to save machine data %s: %m", m->state_file); +fail: + (void) unlink(m->state_file); - return r; + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save machine data %s: %m", m->state_file); } static void machine_unlink(Machine *m) { |