treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'
Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
This commit is contained in:
@@ -191,7 +191,7 @@ static int list_links(char **args, unsigned n) {
|
||||
|
||||
r = sd_rtnl_open(&rtnl, 0);
|
||||
if (r < 0) {
|
||||
log_error("Failed to connect to netlink: %s", strerror(-r));
|
||||
log_error_errno(-r, "Failed to connect to netlink: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ static int list_links(char **args, unsigned n) {
|
||||
|
||||
r = sd_rtnl_call(rtnl, req, 0, &reply);
|
||||
if (r < 0) {
|
||||
log_error("Failed to enumerate links: %s", strerror(-r));
|
||||
log_error_errno(-r, "Failed to enumerate links: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
|
||||
|
||||
r = sd_rtnl_call(rtnl, req, 0, &reply);
|
||||
if (r < 0) {
|
||||
log_error("Failed to query link: %s", strerror(-r));
|
||||
log_error_errno(-r, "Failed to query link: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ static int link_status(char **args, unsigned n) {
|
||||
|
||||
r = sd_rtnl_open(&rtnl, 0);
|
||||
if (r < 0) {
|
||||
log_error("Failed to connect to netlink: %s", strerror(-r));
|
||||
log_error_errno(-r, "Failed to connect to netlink: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -514,7 +514,7 @@ static int link_status(char **args, unsigned n) {
|
||||
|
||||
r = sd_rtnl_call(rtnl, req, 0, &reply);
|
||||
if (r < 0) {
|
||||
log_error("Failed to enumerate links: %s", strerror(-r));
|
||||
log_error_errno(-r, "Failed to enumerate links: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ int address_drop(Address *address, Link *link,
|
||||
|
||||
r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
|
||||
if (r < 0) {
|
||||
log_error("Could not set prefixlen: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set prefixlen: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ int address_drop(Address *address, Link *link,
|
||||
|
||||
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
|
||||
if (r < 0) {
|
||||
log_error("Could not send rtnetlink message: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not send rtnetlink message: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -171,19 +171,19 @@ int address_update(Address *address, Link *link,
|
||||
|
||||
r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
|
||||
if (r < 0) {
|
||||
log_error("Could not set prefixlen: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set prefixlen: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_addr_set_flags(req, IFA_F_PERMANENT);
|
||||
if (r < 0) {
|
||||
log_error("Could not set flags: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set flags: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_addr_set_scope(req, address->scope);
|
||||
if (r < 0) {
|
||||
log_error("Could not set scope: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set scope: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ int address_update(Address *address, Link *link,
|
||||
|
||||
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
|
||||
if (r < 0) {
|
||||
log_error("Could not send rtnetlink message: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not send rtnetlink message: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -320,19 +320,19 @@ int address_configure(Address *address, Link *link,
|
||||
|
||||
r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
|
||||
if (r < 0) {
|
||||
log_error("Could not set prefixlen: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set prefixlen: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_addr_set_flags(req, IFA_F_PERMANENT);
|
||||
if (r < 0) {
|
||||
log_error("Could not set flags: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set flags: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_addr_set_scope(req, address->scope);
|
||||
if (r < 0) {
|
||||
log_error("Could not set scope: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set scope: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ int address_configure(Address *address, Link *link,
|
||||
|
||||
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
|
||||
if (r < 0) {
|
||||
log_error("Could not send rtnetlink message: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not send rtnetlink message: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ int manager_udev_listen(Manager *m) {
|
||||
|
||||
r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_monitor, "net", NULL);
|
||||
if (r < 0) {
|
||||
log_error("Could not add udev monitor filter: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not add udev monitor filter: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -597,7 +597,7 @@ int manager_save(Manager *m) {
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
log_error("Failed to save network state to %s: %s", m->state_file, strerror(-r));
|
||||
log_error_errno(-r, "Failed to save network state to %s: %m", m->state_file);
|
||||
unlink(m->state_file);
|
||||
unlink(temp_path);
|
||||
return r;
|
||||
|
||||
@@ -47,7 +47,7 @@ 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("Failed to add netlink interface name: %s", strerror(-r));
|
||||
log_error_errno(-r, "Failed to add netlink interface name: %m");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,7 +744,7 @@ int netdev_load(Manager *manager) {
|
||||
|
||||
r = conf_files_list_strv(&files, ".netdev", NULL, network_dirs);
|
||||
if (r < 0) {
|
||||
log_error("Failed to enumerate netdev files: %s", strerror(-r));
|
||||
log_error_errno(-r, "Failed to enumerate netdev files: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ int network_load(Manager *manager) {
|
||||
|
||||
r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
|
||||
if (r < 0) {
|
||||
log_error("Failed to enumerate network files: %s", strerror(-r));
|
||||
log_error_errno(-r, "Failed to enumerate network files: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ int route_drop(Route *route, Link *link,
|
||||
RTM_DELROUTE, route->family,
|
||||
route->protocol);
|
||||
if (r < 0) {
|
||||
log_error("Could not create RTM_DELROUTE message: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not create RTM_DELROUTE message: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ int route_drop(Route *route, Link *link,
|
||||
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("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -135,13 +135,13 @@ int route_drop(Route *route, Link *link,
|
||||
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("Could not append RTA_DST attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_DST attribute: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
|
||||
if (r < 0) {
|
||||
log_error("Could not set destination prefix length: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set destination prefix length: %m");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -152,32 +152,32 @@ int route_drop(Route *route, Link *link,
|
||||
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("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_PREFSRC attribute: %m");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_route_set_scope(req, route->scope);
|
||||
if (r < 0) {
|
||||
log_error("Could not set scope: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set scope: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_append_u32(req, RTA_PRIORITY, route->metrics);
|
||||
if (r < 0) {
|
||||
log_error("Could not append RTA_PRIORITY attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_PRIORITY attribute: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_append_u32(req, RTA_OIF, link->ifindex);
|
||||
if (r < 0) {
|
||||
log_error("Could not append RTA_OIF attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_OIF attribute: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
|
||||
if (r < 0) {
|
||||
log_error("Could not send rtnetlink message: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not send rtnetlink message: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ int route_configure(Route *route, Link *link,
|
||||
RTM_NEWROUTE, route->family,
|
||||
route->protocol);
|
||||
if (r < 0) {
|
||||
log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not create RTM_NEWROUTE message: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ int route_configure(Route *route, Link *link,
|
||||
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("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -222,13 +222,13 @@ int route_configure(Route *route, Link *link,
|
||||
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("Could not append RTA_DST attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_DST attribute: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
|
||||
if (r < 0) {
|
||||
log_error("Could not set destination prefix length: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set destination prefix length: %m");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -239,32 +239,32 @@ int route_configure(Route *route, Link *link,
|
||||
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("Could not append RTA_PREFSRC attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_PREFSRC attribute: %m");
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_route_set_scope(req, route->scope);
|
||||
if (r < 0) {
|
||||
log_error("Could not set scope: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not set scope: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_append_u32(req, RTA_PRIORITY, route->metrics);
|
||||
if (r < 0) {
|
||||
log_error("Could not append RTA_PRIORITY attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_PRIORITY attribute: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_append_u32(req, RTA_OIF, link->ifindex);
|
||||
if (r < 0) {
|
||||
log_error("Could not append RTA_OIF attribute: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not append RTA_OIF attribute: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
|
||||
if (r < 0) {
|
||||
log_error("Could not send rtnetlink message: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not send rtnetlink message: %m");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ static int manager_process_link(sd_rtnl *rtnl, sd_rtnl_message *mm, void *userda
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
log_warning("Failed to process RTNL link message: %s", strerror(-r));
|
||||
log_warning_errno(-r, "Failed to process RTNL link message: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ static int on_network_event(sd_event_source *s, int fd, uint32_t revents, void *
|
||||
HASHMAP_FOREACH(l, m->links, i) {
|
||||
r = link_update_monitor(l);
|
||||
if (r < 0)
|
||||
log_warning("Failed to update monitor information for %i: %s", l->ifindex, strerror(-r));
|
||||
log_warning_errno(-r, "Failed to update monitor information for %i: %m", l->ifindex);
|
||||
}
|
||||
|
||||
if (manager_all_configured(m))
|
||||
|
||||
@@ -113,7 +113,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
r = manager_new(&m, arg_interfaces);
|
||||
if (r < 0) {
|
||||
log_error("Could not create manager: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not create manager: %m");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
r = sd_event_loop(m->event);
|
||||
if (r < 0) {
|
||||
log_error("Event loop failed: %s", strerror(-r));
|
||||
log_error_errno(-r, "Event loop failed: %m");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
r = get_user_creds(&user, &uid, &gid, NULL, NULL);
|
||||
if (r < 0) {
|
||||
log_error("Cannot resolve user name %s: %s", user, strerror(-r));
|
||||
log_error_errno(-r, "Cannot resolve user name %s: %m", user);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -79,37 +79,37 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
r = manager_new(&m);
|
||||
if (r < 0) {
|
||||
log_error("Could not create manager: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not create manager: %m");
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = manager_udev_listen(m);
|
||||
if (r < 0) {
|
||||
log_error("Could not connect to udev: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not connect to udev: %m");
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = manager_rtnl_listen(m);
|
||||
if (r < 0) {
|
||||
log_error("Could not connect to rtnl: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not connect to rtnl: %m");
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = manager_bus_listen(m);
|
||||
if (r < 0) {
|
||||
log_error("Could not connect to system bus: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not connect to system bus: %m");
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = manager_load_config(m);
|
||||
if (r < 0) {
|
||||
log_error("Could not load configuration files: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not load configuration files: %m");
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = manager_rtnl_enumerate_links(m);
|
||||
if (r < 0) {
|
||||
log_error("Could not enumerate links: %s", strerror(-r));
|
||||
log_error_errno(-r, "Could not enumerate links: %m");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
r = sd_event_loop(m->event);
|
||||
if (r < 0) {
|
||||
log_error("Event loop failed: %s", strerror(-r));
|
||||
log_error_errno(-r, "Event loop failed: %m");
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user