tree-wide: use unlink_and_freep() moreover
This commit is contained in:
committed by
Yu Watanabe
parent
a90d9ee162
commit
70f1280c83
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user