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
@@ -325,7 +325,7 @@ static int create_bridge(sd_netlink *rtnl, const char *bridge_name) {
|
||||
}
|
||||
|
||||
int setup_bridge(const char *veth_name, const char *bridge_name, bool create) {
|
||||
_cleanup_release_lock_file_ LockFile bridge_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile bridge_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
|
||||
int r, bridge_ifi;
|
||||
unsigned n = 0;
|
||||
@@ -366,7 +366,7 @@ int setup_bridge(const char *veth_name, const char *bridge_name, bool create) {
|
||||
}
|
||||
|
||||
int remove_bridge(const char *bridge_name) {
|
||||
_cleanup_release_lock_file_ LockFile bridge_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile bridge_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
|
||||
const char *path;
|
||||
int r;
|
||||
@@ -398,7 +398,7 @@ int remove_bridge(const char *bridge_name) {
|
||||
}
|
||||
|
||||
static int parse_interface(struct udev *udev, const char *name) {
|
||||
_cleanup_udev_device_unref_ struct udev_device *d = NULL;
|
||||
_cleanup_(udev_device_unrefp) struct udev_device *d = NULL;
|
||||
char ifi_str[2 + DECIMAL_STR_MAX(int)];
|
||||
int ifi;
|
||||
|
||||
@@ -420,7 +420,7 @@ static int parse_interface(struct udev *udev, const char *name) {
|
||||
}
|
||||
|
||||
int move_network_interfaces(pid_t pid, char **ifaces) {
|
||||
_cleanup_udev_unref_ struct udev *udev = NULL;
|
||||
_cleanup_(udev_unrefp) struct udev *udev = NULL;
|
||||
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
|
||||
char **i;
|
||||
int r;
|
||||
@@ -463,7 +463,7 @@ int move_network_interfaces(pid_t pid, char **ifaces) {
|
||||
}
|
||||
|
||||
int setup_macvlan(const char *machine_name, pid_t pid, char **ifaces) {
|
||||
_cleanup_udev_unref_ struct udev *udev = NULL;
|
||||
_cleanup_(udev_unrefp) struct udev *udev = NULL;
|
||||
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
|
||||
unsigned idx = 0;
|
||||
char **i;
|
||||
@@ -551,7 +551,7 @@ int setup_macvlan(const char *machine_name, pid_t pid, char **ifaces) {
|
||||
}
|
||||
|
||||
int setup_ipvlan(const char *machine_name, pid_t pid, char **ifaces) {
|
||||
_cleanup_udev_unref_ struct udev *udev = NULL;
|
||||
_cleanup_(udev_unrefp) struct udev *udev = NULL;
|
||||
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
|
||||
char **i;
|
||||
int r;
|
||||
|
||||
+3
-3
@@ -2878,7 +2878,7 @@ static int uid_shift_pick(uid_t *shift, LockFile *ret_lock_file) {
|
||||
|
||||
for (;;) {
|
||||
char lock_path[STRLEN("/run/systemd/nspawn-uid/") + DECIMAL_STR_MAX(uid_t) + 1];
|
||||
_cleanup_release_lock_file_ LockFile lf = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile lf = LOCK_FILE_INIT;
|
||||
|
||||
if (--n_tries <= 0)
|
||||
return -EBUSY;
|
||||
@@ -3286,7 +3286,7 @@ static int run(int master,
|
||||
.sa_flags = SA_NOCLDSTOP|SA_RESTART,
|
||||
};
|
||||
|
||||
_cleanup_release_lock_file_ LockFile uid_shift_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile uid_shift_lock = LOCK_FILE_INIT;
|
||||
_cleanup_close_ int etc_passwd_lock = -1;
|
||||
_cleanup_close_pair_ int
|
||||
kmsg_socket_pair[2] = { -1, -1 },
|
||||
@@ -3791,7 +3791,7 @@ int main(int argc, char *argv[]) {
|
||||
bool secondary = false, remove_directory = false, remove_image = false;
|
||||
pid_t pid = 0;
|
||||
union in_addr_union exposed = {};
|
||||
_cleanup_release_lock_file_ LockFile tree_global_lock = LOCK_FILE_INIT, tree_local_lock = LOCK_FILE_INIT;
|
||||
_cleanup_(release_lock_file) LockFile tree_global_lock = LOCK_FILE_INIT, tree_local_lock = LOCK_FILE_INIT;
|
||||
bool interactive, veth_created = false, remove_tmprootdir = false;
|
||||
char tmprootdir[] = "/tmp/nspawn-root-XXXXXX";
|
||||
_cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
|
||||
|
||||
Reference in New Issue
Block a user