From f647962d64e844689f3e2acfce6102fc47e76df2 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Fri, 28 Nov 2014 18:50:43 +0100 Subject: treewide: yet more log_*_errno + return simplifications Using: find . -name '*.[ch]' | while read f; do perl -i.mmm -e \ 'local $/; local $_=<>; s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg; print;' $f done And a couple of manual whitespace fixups. --- src/network/networkctl.c | 30 ++++------- src/network/networkd-manager.c | 6 +-- src/network/networkd-netdev-veth.c | 6 +-- src/network/networkd-netdev.c | 6 +-- src/network/networkd-network.c | 6 +-- src/network/networkd-route.c | 108 +++++++++++++------------------------ 6 files changed, 54 insertions(+), 108 deletions(-) (limited to 'src/network') diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 2754ed8d3e..035dce162b 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -190,10 +190,8 @@ static int list_links(char **args, unsigned n) { pager_open_if_enabled(); r = sd_rtnl_open(&rtnl, 0); - if (r < 0) { - log_error_errno(r, "Failed to connect to netlink: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to connect to netlink: %m"); udev = udev_new(); if (!udev) { @@ -210,10 +208,8 @@ static int list_links(char **args, unsigned n) { return rtnl_log_create_error(r); r = sd_rtnl_call(rtnl, req, 0, &reply); - if (r < 0) { - log_error_errno(r, "Failed to enumerate links: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to enumerate links: %m"); if (arg_legend) printf("%3s %-16s %-18s %-11s %-10s\n", "IDX", "LINK", "TYPE", "OPERATIONAL", "SETUP"); @@ -322,10 +318,8 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) { return rtnl_log_create_error(r); r = sd_rtnl_call(rtnl, req, 0, &reply); - if (r < 0) { - log_error_errno(r, "Failed to query link: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to query link: %m"); r = sd_rtnl_message_link_get_ifindex(reply, &ifindex); if (r < 0) @@ -447,10 +441,8 @@ static int link_status(char **args, unsigned n) { int r; r = sd_rtnl_open(&rtnl, 0); - if (r < 0) { - log_error_errno(r, "Failed to connect to netlink: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to connect to netlink: %m"); udev = udev_new(); if (!udev) { @@ -513,10 +505,8 @@ static int link_status(char **args, unsigned n) { return rtnl_log_create_error(r); r = sd_rtnl_call(rtnl, req, 0, &reply); - if (r < 0) { - log_error_errno(r, "Failed to enumerate links: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to enumerate links: %m"); c = decode_and_sort_links(reply, &links); if (c < 0) diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 3a1d565e7b..a708e905f4 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -355,10 +355,8 @@ int manager_udev_listen(Manager *m) { assert(m->udev_monitor); r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_monitor, "net", NULL); - if (r < 0) { - log_error_errno(r, "Could not add udev monitor filter: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not add udev monitor filter: %m"); r = udev_monitor_enable_receiving(m->udev_monitor); if (r < 0) { diff --git a/src/network/networkd-netdev-veth.c b/src/network/networkd-netdev-veth.c index 46f98e0925..251cf92aec 100644 --- a/src/network/networkd-netdev-veth.c +++ b/src/network/networkd-netdev-veth.c @@ -46,10 +46,8 @@ static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_m if (v->ifname_peer) { r = sd_rtnl_message_append_string(m, IFLA_IFNAME, v->ifname_peer); - if (r < 0) { - log_error_errno(r, "Failed to add netlink interface name: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add netlink interface name: %m"); } if (v->mac_peer) { diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index 7f717171ca..a08236e7c3 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -743,10 +743,8 @@ int netdev_load(Manager *manager) { netdev_unref(netdev); r = conf_files_list_strv(&files, ".netdev", NULL, network_dirs); - if (r < 0) { - log_error_errno(r, "Failed to enumerate netdev files: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to enumerate netdev files: %m"); STRV_FOREACH_BACKWARDS(f, files) { r = netdev_load_one(manager, *f); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 151aa12cb7..e4bb1b03f0 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -131,10 +131,8 @@ int network_load(Manager *manager) { network_free(network); r = conf_files_list_strv(&files, ".network", NULL, network_dirs); - if (r < 0) { - log_error_errno(r, "Failed to enumerate network files: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to enumerate network files: %m"); STRV_FOREACH_BACKWARDS(f, files) { r = network_load_one(manager, *f); diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 058f887ebf..25db676f05 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -113,20 +113,16 @@ int route_drop(Route *route, Link *link, r = sd_rtnl_message_new_route(link->manager->rtnl, &req, RTM_DELROUTE, route->family, route->protocol); - if (r < 0) { - log_error_errno(r, "Could not create RTM_DELROUTE message: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not create RTM_DELROUTE message: %m"); if (!in_addr_is_null(route->family, &route->in_addr)) { if (route->family == AF_INET) r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &route->in_addr.in); else if (route->family == AF_INET6) r = sd_rtnl_message_append_in6_addr(req, RTA_GATEWAY, &route->in_addr.in6); - if (r < 0) { - log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m"); } if (route->dst_prefixlen) { @@ -134,16 +130,12 @@ int route_drop(Route *route, Link *link, r = sd_rtnl_message_append_in_addr(req, RTA_DST, &route->dst_addr.in); else if (route->family == AF_INET6) r = sd_rtnl_message_append_in6_addr(req, RTA_DST, &route->dst_addr.in6); - if (r < 0) { - log_error_errno(r, "Could not append RTA_DST attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_DST attribute: %m"); r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen); - if (r < 0) { - log_error_errno(r, "Could not set destination prefix length: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not set destination prefix length: %m"); } if (!in_addr_is_null(route->family, &route->prefsrc_addr)) { @@ -151,35 +143,25 @@ int route_drop(Route *route, Link *link, r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in); else if (route->family == AF_INET6) r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6); - if (r < 0) { - log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m"); } r = sd_rtnl_message_route_set_scope(req, route->scope); - if (r < 0) { - log_error_errno(r, "Could not set scope: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not set scope: %m"); r = sd_rtnl_message_append_u32(req, RTA_PRIORITY, route->metrics); - if (r < 0) { - log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m"); r = sd_rtnl_message_append_u32(req, RTA_OIF, link->ifindex); - if (r < 0) { - log_error_errno(r, "Could not append RTA_OIF attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_OIF attribute: %m"); r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL); - if (r < 0) { - log_error_errno(r, "Could not send rtnetlink message: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not send rtnetlink message: %m"); link_ref(link); @@ -200,20 +182,16 @@ int route_configure(Route *route, Link *link, r = sd_rtnl_message_new_route(link->manager->rtnl, &req, RTM_NEWROUTE, route->family, route->protocol); - if (r < 0) { - log_error_errno(r, "Could not create RTM_NEWROUTE message: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not create RTM_NEWROUTE message: %m"); if (!in_addr_is_null(route->family, &route->in_addr)) { if (route->family == AF_INET) r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &route->in_addr.in); else if (route->family == AF_INET6) r = sd_rtnl_message_append_in6_addr(req, RTA_GATEWAY, &route->in_addr.in6); - if (r < 0) { - log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m"); } if (route->dst_prefixlen) { @@ -221,16 +199,12 @@ int route_configure(Route *route, Link *link, r = sd_rtnl_message_append_in_addr(req, RTA_DST, &route->dst_addr.in); else if (route->family == AF_INET6) r = sd_rtnl_message_append_in6_addr(req, RTA_DST, &route->dst_addr.in6); - if (r < 0) { - log_error_errno(r, "Could not append RTA_DST attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_DST attribute: %m"); r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen); - if (r < 0) { - log_error_errno(r, "Could not set destination prefix length: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not set destination prefix length: %m"); } if (!in_addr_is_null(route->family, &route->prefsrc_addr)) { @@ -238,35 +212,25 @@ int route_configure(Route *route, Link *link, r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in); else if (route->family == AF_INET6) r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6); - if (r < 0) { - log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m"); } r = sd_rtnl_message_route_set_scope(req, route->scope); - if (r < 0) { - log_error_errno(r, "Could not set scope: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not set scope: %m"); r = sd_rtnl_message_append_u32(req, RTA_PRIORITY, route->metrics); - if (r < 0) { - log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m"); r = sd_rtnl_message_append_u32(req, RTA_OIF, link->ifindex); - if (r < 0) { - log_error_errno(r, "Could not append RTA_OIF attribute: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not append RTA_OIF attribute: %m"); r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL); - if (r < 0) { - log_error_errno(r, "Could not send rtnetlink message: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not send rtnetlink message: %m"); link_ref(link); -- cgit v1.2.3-54-g00ecf