]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use unlink_and_freep() moreover
authorLennart Poettering <lennart@poettering.net>
Wed, 22 Feb 2023 22:13:31 +0000 (23:13 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Feb 2023 01:10:48 +0000 (10:10 +0900)
src/journal-remote/journal-upload.c
src/libsystemd/sd-device/device-private.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-seat.c
src/login/logind-session.c
src/login/logind-user.c
src/machine/machine.c
src/resolve/resolved-link.c

index 5a34b73f7614d66b81cc1ec535e9608c530c37ff..fc55f13bab956337095619280759c2a4405b9e12 100644 (file)
@@ -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);
index 182c4d66ff75835bbe505787fe65084c3ae10788..e9d54f514e65d837d4fcc814c99a73460c7c5fcf 100644 (file)
@@ -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);
 }
index 7024bba82daddce1d364f2f34a42a41174e4215c..1c151021c7904f8a0f71e87bdd26241e379d100f 100644 (file)
@@ -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");
index 95b11ed9e731796dc5c792be18762f59f6546b4a..8735538d209ce4f0747327bb86e8f7a26e58700d 100644 (file)
@@ -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);
 }
 
index 65323f6c9235c0b337bf629387b137b9741edae0..c92e59ae51261d83be486ac5d81d26fa294f2b96 100644 (file)
@@ -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);
 }
 
index 63b6d012ee590443da2811de8aec94d9f470bcd0..1daa102071c458c8cf1970d7dae8e162eee962dc 100644 (file)
@@ -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);
 }
 
index 5680a300f3c933f04863ac5f19d7b9e335113d6c..3920467f444d997eca0f5a23b14e9e7c7d88d4da 100644 (file)
@@ -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);
 }
 
index c08a645814d00f53cd91c0f0f4252c40cb773a26..acb86c1a83f9dfe6e734dea5f465675ca30f1862 100644 (file)
@@ -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);
 }
 
index d41f6f3e5477585982540441dd46d0bb50fd4160..70e726e417a9cde74e51e972f767508015cda4eb 100644 (file)
@@ -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);
 }