tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches all users to just use the generic ones. In most recent code we abstained from defining type-specific macros, and this basically removes all those added already, with the exception of the really low-level ones. Having explicit macros for this is not too useful, as the expression without the extra macro is generally just 2ch wider. We should generally emphesize generic code, unless there are really good reasons for specific code, hence let's follow this in this case too. Note that _cleanup_free_ and similar really low-level, libc'ish, Linux API'ish macros continue to be defined, only the really high-level OO ones are dropped. From now on this should really be the rule: for really low-level stuff, such as memory allocation, fd handling and so one, go ahead and define explicit per-type macros, but for high-level, specific program code, just use the generic _cleanup_() macro directly, in order to keep things simple and as readable as possible for the uninitiated. Note that before this patch some of the APIs (notable libudev ones) were already used with the high-level macros at some places and with the generic _cleanup_ macro at others. With this patch we hence unify on the latter.
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
0d6f0ea6c1
commit
8e766630f0
@@ -397,7 +397,7 @@ static int verify_esp(
|
||||
uint64_t *ret_psize,
|
||||
sd_id128_t *ret_uuid) {
|
||||
#if HAVE_BLKID
|
||||
_cleanup_blkid_free_probe_ blkid_probe b = NULL;
|
||||
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
|
||||
char t[DEV_NUM_PATH_MAX];
|
||||
const char *v;
|
||||
#endif
|
||||
|
||||
@@ -49,7 +49,7 @@ int probe_filesystem(const char *node, char **ret_fstype) {
|
||||
* different error otherwise. */
|
||||
|
||||
#if HAVE_BLKID
|
||||
_cleanup_blkid_free_probe_ blkid_probe b = NULL;
|
||||
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
|
||||
const char *fstype;
|
||||
int r;
|
||||
|
||||
@@ -124,12 +124,12 @@ int dissect_image(
|
||||
|
||||
#if HAVE_BLKID
|
||||
sd_id128_t root_uuid = SD_ID128_NULL, verity_uuid = SD_ID128_NULL;
|
||||
_cleanup_udev_enumerate_unref_ struct udev_enumerate *e = NULL;
|
||||
_cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL;
|
||||
bool is_gpt, is_mbr, generic_rw, multiple_generic = false;
|
||||
_cleanup_udev_device_unref_ struct udev_device *d = NULL;
|
||||
_cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
|
||||
_cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
|
||||
_cleanup_blkid_free_probe_ blkid_probe b = NULL;
|
||||
_cleanup_udev_unref_ struct udev *udev = NULL;
|
||||
_cleanup_(blkid_free_probep) blkid_probe b = NULL;
|
||||
_cleanup_(udev_unrefp) struct udev *udev = NULL;
|
||||
_cleanup_free_ char *generic_node = NULL;
|
||||
sd_id128_t generic_uuid = SD_ID128_NULL;
|
||||
const char *pttype = NULL;
|
||||
@@ -287,7 +287,7 @@ int dissect_image(
|
||||
n = 0;
|
||||
first = udev_enumerate_get_list_entry(e);
|
||||
udev_list_entry_foreach(item, first) {
|
||||
_cleanup_udev_device_unref_ struct udev_device *q;
|
||||
_cleanup_(udev_device_unrefp) struct udev_device *q;
|
||||
dev_t qn;
|
||||
|
||||
q = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item));
|
||||
@@ -360,7 +360,7 @@ int dissect_image(
|
||||
|
||||
first = udev_enumerate_get_list_entry(e);
|
||||
udev_list_entry_foreach(item, first) {
|
||||
_cleanup_udev_device_unref_ struct udev_device *q;
|
||||
_cleanup_(udev_device_unrefp) struct udev_device *q;
|
||||
unsigned long long pflags;
|
||||
blkid_partition pp;
|
||||
const char *node;
|
||||
|
||||
+13
-13
@@ -1992,7 +1992,7 @@ int unit_file_mask(
|
||||
UnitFileChange **changes,
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
const char *config_path;
|
||||
char **i;
|
||||
int r;
|
||||
@@ -2038,7 +2038,7 @@ int unit_file_unmask(
|
||||
UnitFileChange **changes,
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
|
||||
_cleanup_strv_free_ char **todo = NULL;
|
||||
size_t n_todo = 0, n_allocated = 0;
|
||||
@@ -2132,7 +2132,7 @@ int unit_file_link(
|
||||
UnitFileChange **changes,
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_strv_free_ char **todo = NULL;
|
||||
size_t n_todo = 0, n_allocated = 0;
|
||||
const char *config_path;
|
||||
@@ -2233,7 +2233,7 @@ int unit_file_revert(
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_strv_free_ char **todo = NULL;
|
||||
size_t n_todo = 0, n_allocated = 0;
|
||||
char **i;
|
||||
@@ -2389,7 +2389,7 @@ int unit_file_add_dependency(
|
||||
UnitFileChange **changes,
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_(install_context_done) InstallContext c = {};
|
||||
UnitFileInstallInfo *i, *target_info;
|
||||
const char *config_path;
|
||||
@@ -2463,7 +2463,7 @@ int unit_file_enable(
|
||||
UnitFileChange **changes,
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_(install_context_done) InstallContext c = {};
|
||||
const char *config_path;
|
||||
UnitFileInstallInfo *i;
|
||||
@@ -2509,7 +2509,7 @@ int unit_file_disable(
|
||||
UnitFileChange **changes,
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_(install_context_done) InstallContext c = {};
|
||||
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
|
||||
const char *config_path;
|
||||
@@ -2578,7 +2578,7 @@ int unit_file_set_default(
|
||||
UnitFileChange **changes,
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_(install_context_done) InstallContext c = {};
|
||||
UnitFileInstallInfo *i;
|
||||
const char *new_path;
|
||||
@@ -2613,7 +2613,7 @@ int unit_file_get_default(
|
||||
const char *root_dir,
|
||||
char **name) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_(install_context_done) InstallContext c = {};
|
||||
UnitFileInstallInfo *i;
|
||||
char *n;
|
||||
@@ -2737,7 +2737,7 @@ int unit_file_get_state(
|
||||
const char *name,
|
||||
UnitFileState *ret) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
int r;
|
||||
|
||||
assert(scope >= 0);
|
||||
@@ -3020,7 +3020,7 @@ int unit_file_preset(
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_(install_context_done) InstallContext plus = {}, minus = {};
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_(presets_freep) Presets presets = {};
|
||||
const char *config_path;
|
||||
char **i;
|
||||
@@ -3060,7 +3060,7 @@ int unit_file_preset_all(
|
||||
unsigned *n_changes) {
|
||||
|
||||
_cleanup_(install_context_done) InstallContext plus = {}, minus = {};
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
_cleanup_(presets_freep) Presets presets = {};
|
||||
const char *config_path = NULL;
|
||||
char **i;
|
||||
@@ -3143,7 +3143,7 @@ int unit_file_get_list(
|
||||
char **states,
|
||||
char **patterns) {
|
||||
|
||||
_cleanup_lookup_paths_free_ LookupPaths paths = {};
|
||||
_cleanup_(lookup_paths_free) LookupPaths paths = {};
|
||||
char **i;
|
||||
int r;
|
||||
|
||||
|
||||
@@ -440,7 +440,7 @@ int image_discover(Hashmap *h) {
|
||||
}
|
||||
|
||||
int image_remove(Image *i) {
|
||||
_cleanup_release_lock_file_ LockFile global_lock = LOCK_FILE_INIT, local_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile global_lock = LOCK_FILE_INIT, local_lock = LOCK_FILE_INIT;
|
||||
_cleanup_strv_free_ char **settings = NULL;
|
||||
_cleanup_free_ char *roothash = NULL;
|
||||
char **j;
|
||||
@@ -531,7 +531,7 @@ static int rename_auxiliary_file(const char *path, const char *new_name, const c
|
||||
}
|
||||
|
||||
int image_rename(Image *i, const char *new_name) {
|
||||
_cleanup_release_lock_file_ LockFile global_lock = LOCK_FILE_INIT, local_lock = LOCK_FILE_INIT, name_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile global_lock = LOCK_FILE_INIT, local_lock = LOCK_FILE_INIT, name_lock = LOCK_FILE_INIT;
|
||||
_cleanup_free_ char *new_path = NULL, *nn = NULL, *roothash = NULL;
|
||||
_cleanup_strv_free_ char **settings = NULL;
|
||||
unsigned file_attr = 0;
|
||||
@@ -652,7 +652,7 @@ static int clone_auxiliary_file(const char *path, const char *new_name, const ch
|
||||
}
|
||||
|
||||
int image_clone(Image *i, const char *new_name, bool read_only) {
|
||||
_cleanup_release_lock_file_ LockFile name_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile name_lock = LOCK_FILE_INIT;
|
||||
_cleanup_strv_free_ char **settings = NULL;
|
||||
_cleanup_free_ char *roothash = NULL;
|
||||
const char *new_path;
|
||||
@@ -735,7 +735,7 @@ int image_clone(Image *i, const char *new_name, bool read_only) {
|
||||
}
|
||||
|
||||
int image_read_only(Image *i, bool b) {
|
||||
_cleanup_release_lock_file_ LockFile global_lock = LOCK_FILE_INIT, local_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile global_lock = LOCK_FILE_INIT, local_lock = LOCK_FILE_INIT;
|
||||
int r;
|
||||
|
||||
assert(i);
|
||||
@@ -906,7 +906,7 @@ int image_set_limit(Image *i, uint64_t referenced_max) {
|
||||
}
|
||||
|
||||
int image_read_metadata(Image *i) {
|
||||
_cleanup_release_lock_file_ LockFile global_lock = LOCK_FILE_INIT, local_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile global_lock = LOCK_FILE_INIT, local_lock = LOCK_FILE_INIT;
|
||||
int r;
|
||||
|
||||
assert(i);
|
||||
|
||||
@@ -158,7 +158,7 @@ fail:
|
||||
}
|
||||
|
||||
int setup_machine_directory(uint64_t size, sd_bus_error *error) {
|
||||
_cleanup_release_lock_file_ LockFile lock_file = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile lock_file = LOCK_FILE_INIT;
|
||||
struct loop_info64 info = {
|
||||
.lo_flags = LO_FLAGS_AUTOCLEAR,
|
||||
};
|
||||
|
||||
@@ -69,6 +69,5 @@ void lookup_paths_trim_generator(LookupPaths *p);
|
||||
void lookup_paths_flush_generator(LookupPaths *p);
|
||||
|
||||
void lookup_paths_free(LookupPaths *p);
|
||||
#define _cleanup_lookup_paths_free_ _cleanup_(lookup_paths_free)
|
||||
|
||||
char **generator_binary_paths(UnitFileScope scope);
|
||||
|
||||
@@ -20,15 +20,4 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_connection*, udev_ctrl_connection_u
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_ctrl_msg*, udev_ctrl_msg_unref);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_monitor*, udev_monitor_unref);
|
||||
|
||||
#define _cleanup_udev_unref_ _cleanup_(udev_unrefp)
|
||||
#define _cleanup_udev_device_unref_ _cleanup_(udev_device_unrefp)
|
||||
#define _cleanup_udev_enumerate_unref_ _cleanup_(udev_enumerate_unrefp)
|
||||
#define _cleanup_udev_event_unref_ _cleanup_(udev_event_unrefp)
|
||||
#define _cleanup_udev_rules_unref_ _cleanup_(udev_rules_unrefp)
|
||||
#define _cleanup_udev_ctrl_unref_ _cleanup_(udev_ctrl_unrefp)
|
||||
#define _cleanup_udev_ctrl_connection_unref_ _cleanup_(udev_ctrl_connection_unrefp)
|
||||
#define _cleanup_udev_ctrl_msg_unref_ _cleanup_(udev_ctrl_msg_unrefp)
|
||||
#define _cleanup_udev_monitor_unref_ _cleanup_(udev_monitor_unrefp)
|
||||
#define _cleanup_udev_list_cleanup_ _cleanup_(udev_list_cleanup)
|
||||
|
||||
int udev_parse_config(void);
|
||||
|
||||
Reference in New Issue
Block a user