From: Lennart Poettering Date: Wed, 22 Feb 2023 22:13:31 +0000 (+0100) Subject: tree-wide: use unlink_and_freep() moreover X-Git-Tag: v254-rc1~1187 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=70f1280c83ce4cc9f11fa99f1386cdf621e70ee4;p=thirdparty%2Fsystemd.git tree-wide: use unlink_and_freep() moreover --- diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 5a34b73f761..fc55f13bab9 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -18,6 +18,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "fs-util.h" #include "glob-util.h" #include "journal-upload.h" #include "log.h" @@ -116,7 +117,7 @@ static int check_cursor_updating(Uploader *u) { } static int update_cursor_state(Uploader *u) { - _cleanup_free_ char *temp_path = NULL; + _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -141,12 +142,10 @@ static int update_cursor_state(Uploader *u) { goto fail; } + temp_path = mfree(temp_path); return 0; fail: - if (temp_path) - (void) unlink(temp_path); - (void) unlink(u->state_file); return log_error_errno(r, "Failed to save state %s: %m", u->state_file); diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 182c4d66ff7..e9d54f514e6 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -794,7 +794,7 @@ int device_update_db(sd_device *device) { const char *id; char *path; _cleanup_fclose_ FILE *f = NULL; - _cleanup_free_ char *path_tmp = NULL; + _cleanup_(unlink_and_freep) char *path_tmp = NULL; bool has_info; int r; @@ -871,6 +871,8 @@ int device_update_db(sd_device *device) { goto fail; } + path_tmp = mfree(path_tmp); + log_device_debug(device, "sd-device: Created %s file '%s' for '%s'", has_info ? "db" : "empty", path, device->devpath); @@ -878,7 +880,6 @@ int device_update_db(sd_device *device) { fail: (void) unlink(path); - (void) unlink(path_tmp); return log_device_debug_errno(device, r, "sd-device: Failed to create %s file '%s' for '%s'", has_info ? "db" : "empty", path, device->devpath); } diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 7024bba82da..1c151021c79 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -2083,7 +2083,7 @@ void manager_load_scheduled_shutdown(Manager *m) { } static int update_schedule_file(Manager *m) { - _cleanup_free_ char *temp_path = NULL; + _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -2123,10 +2123,10 @@ static int update_schedule_file(Manager *m) { goto fail; } + temp_path = mfree(temp_path); return 0; fail: - (void) unlink(temp_path); (void) unlink(SHUTDOWN_SCHEDULE_FILE); return log_error_errno(r, "Failed to write information about scheduled shutdowns: %m"); diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 95b11ed9e73..8735538d209 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -14,6 +14,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "fs-util.h" #include "io-util.h" #include "logind-dbus.h" #include "logind-inhibit.h" @@ -83,7 +84,7 @@ Inhibitor* inhibitor_free(Inhibitor *i) { } static int inhibitor_save(Inhibitor *i) { - _cleanup_free_ char *temp_path = NULL; + _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -146,14 +147,12 @@ static int inhibitor_save(Inhibitor *i) { goto fail; } + temp_path = mfree(temp_path); return 0; 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); } diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 65323f6c923..c92e59ae512 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -13,6 +13,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "fs-util.h" #include "logind-seat-dbus.h" #include "logind-seat.h" #include "logind-session-dbus.h" @@ -81,7 +82,7 @@ Seat* seat_free(Seat *s) { } int seat_save(Seat *s) { - _cleanup_free_ char *temp_path = NULL; + _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -146,14 +147,11 @@ int seat_save(Seat *s) { goto fail; } + temp_path = mfree(temp_path); return 0; fail: (void) unlink(s->state_file); - - if (temp_path) - (void) unlink(temp_path); - return log_error_errno(r, "Failed to save seat data %s: %m", s->state_file); } diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 63b6d012ee5..1daa102071c 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -21,6 +21,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "fs-util.h" #include "io-util.h" #include "logind-dbus.h" #include "logind-seat-dbus.h" @@ -202,7 +203,7 @@ static void session_save_devices(Session *s, FILE *f) { } int session_save(Session *s) { - _cleanup_free_ char *temp_path = NULL; + _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -349,14 +350,12 @@ int session_save(Session *s) { goto fail; } + temp_path = mfree(temp_path); return 0; fail: (void) unlink(s->state_file); - if (temp_path) - (void) unlink(temp_path); - return log_error_errno(r, "Failed to save session data %s: %m", s->state_file); } diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 5680a300f3c..3920467f444 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -140,7 +140,7 @@ User *user_free(User *u) { } static int user_save_internal(User *u) { - _cleanup_free_ char *temp_path = NULL; + _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -282,14 +282,12 @@ static int user_save_internal(User *u) { goto fail; } + temp_path = mfree(temp_path); return 0; fail: (void) unlink(u->state_file); - if (temp_path) - (void) unlink(temp_path); - return log_error_errno(r, "Failed to save user data %s: %m", u->state_file); } diff --git a/src/machine/machine.c b/src/machine/machine.c index c08a645814d..acb86c1a83f 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -17,6 +17,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "fs-util.h" #include "hashmap.h" #include "machine-dbus.h" #include "machine.h" @@ -107,7 +108,7 @@ Machine* machine_free(Machine *m) { } int machine_save(Machine *m) { - _cleanup_free_ char *temp_path = NULL; + _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; int r; @@ -211,6 +212,8 @@ int machine_save(Machine *m) { goto fail; } + temp_path = mfree(temp_path); + if (m->unit) { char *sl; @@ -226,9 +229,6 @@ int machine_save(Machine *m) { fail: (void) unlink(m->state_file); - if (temp_path) - (void) unlink(temp_path); - return log_error_errno(r, "Failed to save machine data %s: %m", m->state_file); } diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c index d41f6f3e547..70e726e417a 100644 --- a/src/resolve/resolved-link.c +++ b/src/resolve/resolved-link.c @@ -9,6 +9,7 @@ #include "env-file.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "log-link.h" #include "mkdir.h" #include "netif-util.h" @@ -1175,7 +1176,7 @@ static bool link_needs_save(Link *l) { } int link_save_user(Link *l) { - _cleanup_free_ char *temp_path = NULL; + _cleanup_(unlink_and_freep) char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; const char *v; int r; @@ -1277,14 +1278,13 @@ int link_save_user(Link *l) { goto fail; } + temp_path = mfree(temp_path); + return 0; fail: (void) unlink(l->state_file); - if (temp_path) - (void) unlink(temp_path); - return log_link_error_errno(l, r, "Failed to save link data %s: %m", l->state_file); }