diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-09-30 22:16:17 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-09-30 22:26:16 +0200 |
commit | e53fc357a9bb9d0a5362ccc4246d598cb0febd5e (patch) | |
tree | 3bb6c3be9ba053e4a280b6c2ae8cd03be8f1ac6d /src | |
parent | 618234a5258768359cb1086b152c5f08aaf89754 (diff) |
tree-wide: remove a number of invocations of strerror() and replace by %m
Let's clean up our tree a bit, and reduce invocations of the
thread-unsafe strerror() by replacing it with printf()'s %m specifier.
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/socket-label.c | 7 | ||||
-rw-r--r-- | src/basic/util.c | 8 | ||||
-rw-r--r-- | src/core/smack-setup.c | 9 | ||||
-rw-r--r-- | src/core/socket.c | 3 | ||||
-rw-r--r-- | src/journal/catalog.c | 11 | ||||
-rw-r--r-- | src/journal/journalctl.c | 2 | ||||
-rw-r--r-- | src/journal/journald-server.c | 3 | ||||
-rw-r--r-- | src/libsystemd-network/lldp-port.c | 8 | ||||
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator.c | 6 | ||||
-rw-r--r-- | src/libsystemd/sd-device/device-private.c | 8 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 19 | ||||
-rw-r--r-- | src/network/networkd-dhcp6.c | 30 | ||||
-rw-r--r-- | src/network/networkd-ipv4ll.c | 9 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 2 | ||||
-rw-r--r-- | src/udev/udevadm-settle.c | 7 |
15 files changed, 51 insertions, 81 deletions
diff --git a/src/basic/socket-label.c b/src/basic/socket-label.c index 144e6fd86e..937124cc02 100644 --- a/src/basic/socket-label.c +++ b/src/basic/socket-label.c @@ -146,11 +146,8 @@ int make_socket_fd(int log_level, const char* address, int flags) { int fd, r; r = socket_address_parse(&a, address); - if (r < 0) { - log_error("Failed to parse socket address \"%s\": %s", - address, strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to parse socket address \"%s\": %m", address); fd = socket_address_listen(&a, flags, SOMAXCONN, SOCKET_ADDRESS_DEFAULT, NULL, false, false, false, 0755, 0644, NULL); diff --git a/src/basic/util.c b/src/basic/util.c index 33dc410c78..c63ec0ceb0 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -5344,15 +5344,13 @@ int update_reboot_param_file(const char *param) { int r = 0; if (param) { - r = write_string_file(REBOOT_PARAM_FILE, param, WRITE_STRING_FILE_CREATE); if (r < 0) - log_error("Failed to write reboot param to " - REBOOT_PARAM_FILE": %s", strerror(-r)); + return log_error_errno(r, "Failed to write reboot param to "REBOOT_PARAM_FILE": %m"); } else - unlink(REBOOT_PARAM_FILE); + (void) unlink(REBOOT_PARAM_FILE); - return r; + return 0; } int umount_recursive(const char *prefix, int flags) { diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index cbe7d0b4a9..6618aa501d 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -215,16 +215,14 @@ int mac_smack_setup(bool *loaded_policy) { log_info("Successfully loaded Smack policies."); break; default: - log_warning("Failed to load Smack access rules: %s, ignoring.", - strerror(abs(r))); + log_warning_errno(r, "Failed to load Smack access rules, ignoring: %m"); return 0; } #ifdef SMACK_RUN_LABEL r = write_string_file("/proc/self/attr/current", SMACK_RUN_LABEL, 0); if (r) - log_warning("Failed to set SMACK label \"%s\" on self: %s", - SMACK_RUN_LABEL, strerror(-r)); + log_warning_errno("Failed to set SMACK label \"%s\" on self: %m", SMACK_RUN_LABEL); #endif r = write_cipso2_rules("/etc/smack/cipso.d/"); @@ -239,8 +237,7 @@ int mac_smack_setup(bool *loaded_policy) { log_info("Successfully loaded Smack/CIPSO policies."); break; default: - log_warning("Failed to load Smack/CIPSO access rules: %s, ignoring.", - strerror(abs(r))); + log_warning_errno(r, "Failed to load Smack/CIPSO access rules, ignoring: %m"); return 0; } diff --git a/src/core/socket.c b/src/core/socket.c index 0025054122..a46c422a78 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -643,7 +643,8 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) { int r; char *k = NULL; - if ((r = socket_address_print(&p->address, &k)) < 0) + r = socket_address_print(&p->address, &k); + if (r < 0) t = strerror(-r); else t = k; diff --git a/src/journal/catalog.c b/src/journal/catalog.c index a3e51e2f52..78ca4b02e8 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -419,8 +419,7 @@ int catalog_update(const char* database, const char* root, const char* const* di log_debug("Reading file '%s'", *f); r = catalog_import_file(h, sb, *f); if (r < 0) { - log_error("Failed to import file '%s': %s.", - *f, strerror(-r)); + log_error_errno(r, "Failed to import file '%s': %m", *f); goto finish; } } @@ -676,8 +675,7 @@ int catalog_list_items(FILE *f, const char *database, bool oneline, char **items k = sd_id128_from_string(*item, &id); if (k < 0) { - log_error_errno(k, "Failed to parse id128 '%s': %m", - *item); + log_error_errno(k, "Failed to parse id128 '%s': %m", *item); if (r == 0) r = k; continue; @@ -685,9 +683,8 @@ int catalog_list_items(FILE *f, const char *database, bool oneline, char **items k = catalog_get(database, id, &msg); if (k < 0) { - log_full(k == -ENOENT ? LOG_NOTICE : LOG_ERR, - "Failed to retrieve catalog entry for '%s': %s", - *item, strerror(-k)); + log_full_errno(k == -ENOENT ? LOG_NOTICE : LOG_ERR, k, + "Failed to retrieve catalog entry for '%s': %m", *item); if (r == 0) r = k; continue; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 75e59dbd42..ecec854559 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1577,7 +1577,7 @@ static int verify(sd_journal *j) { /* If the key was invalid give up right-away. */ return k; } else if (k < 0) { - log_warning("FAIL: %s (%s)", f->path, strerror(-k)); + log_warning_errno(k, "FAIL: %s (%m)", f->path); r = k; } else { char a[FORMAT_TIMESTAMP_MAX], b[FORMAT_TIMESTAMP_MAX], c[FORMAT_TIMESPAN_MAX]; diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index fa2e9b9825..564a1ae73d 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -1434,8 +1434,7 @@ static int server_open_hostname(Server *s) { /* kernels prior to 3.2 don't support polling this file. Ignore * the failure. */ if (r == -EPERM) { - log_warning("Failed to register hostname fd in event loop: %s. Ignoring.", - strerror(-r)); + log_warning_errno(r, "Failed to register hostname fd in event loop, ignoring: %m"); s->hostname_fd = safe_close(s->hostname_fd); return 0; } diff --git a/src/libsystemd-network/lldp-port.c b/src/libsystemd-network/lldp-port.c index aa6a3b9224..97fe7c1dd3 100644 --- a/src/libsystemd-network/lldp-port.c +++ b/src/libsystemd-network/lldp-port.c @@ -38,19 +38,19 @@ int lldp_port_start(lldp_port *p) { r = sd_event_add_io(p->event, &p->lldp_port_rx, p->rawfd, EPOLLIN, lldp_receive_packet, p); if (r < 0) { - log_debug("Failed to allocate event source: %s", strerror(-r)); - return r; + log_debug_errno(r, "Failed to allocate event source: %m"); + goto fail; } r = sd_event_source_set_priority(p->lldp_port_rx, p->event_priority); if (r < 0) { - log_debug("Failed to set event priority: %s", strerror(-r)); + log_debug_errno(r, "Failed to set event priority: %m"); goto fail; } r = sd_event_source_set_description(p->lldp_port_rx, "lldp-port-rx"); if (r < 0) { - log_debug("Failed to set event name: %s", strerror(-r)); + log_debug_errno(r, "Failed to set event name: %m"); goto fail; } diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index 5eb37e16cb..45a4d12eb7 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -812,10 +812,8 @@ static int enumerator_scan_devices_all(sd_device_enumerator *enumerator) { if (access("/sys/subsystem", F_OK) >= 0) { /* we have /subsystem/, forget all the old stuff */ r = enumerator_scan_dir(enumerator, "subsystem", "devices", NULL); - if (r < 0) { - log_debug("device-enumerator: failed to scan /sys/subsystem: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_debug_errno(r, "device-enumerator: failed to scan /sys/subsystem: %m"); } else { int k; diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 0ec9667744..b5215cb9b5 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -200,10 +200,8 @@ static int device_read_db(sd_device *device) { if (r < 0) { if (r == -ENOENT) return 0; - else { - log_debug("sd-device: failed to read db '%s': %s", path, strerror(-r)); - return r; - } + else + return log_debug_errno(r, "sd-device: failed to read db '%s': %m", path); } /* devices with a database entry are initialized */ @@ -247,7 +245,7 @@ static int device_read_db(sd_device *device) { db[i] = '\0'; r = handle_db_line(device, key, value); if (r < 0) - log_debug("sd-device: failed to handle db entry '%c:%s': %s", key, value, strerror(-r)); + log_debug_errno(r, "sd-device: failed to handle db entry '%c:%s': %m", key, value); state = PRE_KEY; } diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 7cea5a0746..8ffe994d80 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -169,11 +169,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { /* the device does not exist (any more?) */ return -ENODEV; - log_debug("sd-device: could not canonicalize '%s': %m", _syspath); - return -errno; + return log_debug_errno(errno, "sd-device: could not canonicalize '%s': %m", _syspath); } } else if (r < 0) { - log_debug("sd-device: could not get target of '%s': %s", _syspath, strerror(-r)); + log_debug_errno("sd-device: could not get target of '%s': %m", _syspath); return r; } @@ -516,7 +515,7 @@ int device_read_uevent_file(sd_device *device) { /* some devices may not have uevent files, see set_syspath() */ return 0; else if (r < 0) { - log_debug("sd-device: failed to read uevent file '%s': %s", path, strerror(-r)); + log_debug_errno(r, "sd-device: failed to read uevent file '%s': %m", path); return r; } @@ -555,7 +554,7 @@ int device_read_uevent_file(sd_device *device) { r = handle_uevent_line(device, key, value, &major, &minor); if (r < 0) - log_debug("sd-device: failed to handle uevent entry '%s=%s': %s", key, value, strerror(-r)); + log_debug_errno(r, "sd-device: failed to handle uevent entry '%s=%s': %s", key, value); state = PRE_KEY; } @@ -569,7 +568,7 @@ int device_read_uevent_file(sd_device *device) { if (major) { r = device_set_devnum(device, major, minor); if (r < 0) - log_debug("sd-device: could not set 'MAJOR=%s' or 'MINOR=%s' from '%s': %s", major, minor, path, strerror(-r)); + log_debug_errno("sd-device: could not set 'MAJOR=%s' or 'MINOR=%s' from '%s': %m", major, minor, path); } return 0; @@ -1271,10 +1270,8 @@ int device_read_db_aux(sd_device *device, bool force) { if (r < 0) { if (r == -ENOENT) return 0; - else { - log_debug("sd-device: failed to read db '%s': %s", path, strerror(-r)); - return r; - } + else + return log_debug_errno(r, "sd-device: failed to read db '%s': %m", path); } /* devices with a database entry are initialized */ @@ -1318,7 +1315,7 @@ int device_read_db_aux(sd_device *device, bool force) { db[i] = '\0'; r = handle_db_line(device, key, value); if (r < 0) - log_debug("sd-device: failed to handle db entry '%c:%s': %s", key, value, strerror(-r)); + log_debug_errno(r, "sd-device: failed to handle db entry '%c:%s': %s", key, value); state = PRE_KEY; } diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 13105c7865..3cb7b8d9ca 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -53,8 +53,7 @@ static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, return 1; } - log_link_error(link, "Could not set DHCPv6 address: %s", - strerror(-r)); + log_link_error_errno(link, r, "Could not set DHCPv6 address: %m"); link_enter_failed(link); @@ -115,8 +114,7 @@ static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link) { r = sd_icmp6_ra_get_prefixlen(link->icmp6_router_discovery, &ip6_addr, &prefixlen); if (r < 0 && r != -EADDRNOTAVAIL) { - log_link_warning(link, "Could not get prefix information: %s", - strerror(-r)); + log_link_warning_errno(link, r, "Could not get prefix information: %m"); return r; } @@ -172,11 +170,9 @@ static void dhcp6_handler(sd_dhcp6_client *client, int event, void *userdata) { default: if (event < 0) - log_link_warning(link, "DHCPv6 error: %s", - strerror(-event)); + log_link_warning_errno(link, event, "DHCPv6 error: %m"); else - log_link_warning(link, "DHCPv6 unknown event: %d", - event); + log_link_warning(link, "DHCPv6 unknown event: %d", event); return; } @@ -198,24 +194,21 @@ static int dhcp6_configure(Link *link, int event) { r = sd_dhcp6_client_get_information_request(link->dhcp6_client, &information_request); if (r < 0) { - log_link_warning(link, "Could not get DHCPv6 Information request setting: %s", - strerror(-r)); + log_link_warning_errno(link, r, "Could not get DHCPv6 Information request setting: %m"); goto error; } if (information_request && event != SD_ICMP6_ND_EVENT_ROUTER_ADVERTISMENT_OTHER) { r = sd_dhcp6_client_stop(link->dhcp6_client); if (r < 0) { - log_link_warning(link, "Could not stop DHCPv6 while setting Managed mode %s", - strerror(-r)); + log_link_warning_errno(link, r, "Could not stop DHCPv6 while setting Managed mode: %m"); goto error; } r = sd_dhcp6_client_set_information_request(link->dhcp6_client, false); if (r < 0) { - log_link_warning(link, "Could not unset DHCPv6 Information request: %s", - strerror(-r)); + log_link_warning_errno(link, r, "Could not unset DHCPv6 Information request: %m"); goto error; } @@ -223,8 +216,7 @@ static int dhcp6_configure(Link *link, int event) { r = sd_dhcp6_client_start(link->dhcp6_client); if (r < 0 && r != -EALREADY) { - log_link_warning(link, "Could not restart DHCPv6: %s", - strerror(-r)); + log_link_warning_errno(link, r, "Could not restart DHCPv6: %m"); goto error; } @@ -343,11 +335,9 @@ static void icmp6_router_handler(sd_icmp6_nd *nd, int event, void *userdata) { default: if (event < 0) - log_link_warning(link, "ICMPv6 error: %s", - strerror(-event)); + log_link_warning_errno(link, event, "ICMPv6 error: %m"); else - log_link_warning(link, "ICMPv6 unknown event: %d", - event); + log_link_warning(link, "ICMPv6 unknown event: %d", event); break; } diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c index af3e3884e6..1902b3d23a 100644 --- a/src/network/networkd-ipv4ll.c +++ b/src/network/networkd-ipv4ll.c @@ -44,7 +44,7 @@ static int ipv4ll_address_lost(Link *link) { r = address_new_dynamic(&address); if (r < 0) { - log_link_error(link, "Could not allocate address: %s", strerror(-r)); + log_link_error_errno(link, r, "Could not allocate address: %m"); return r; } @@ -57,8 +57,7 @@ static int ipv4ll_address_lost(Link *link) { r = route_new_dynamic(&route, RTPROT_UNSPEC); if (r < 0) { - log_link_error(link, "Could not allocate route: %s", - strerror(-r)); + log_link_error_errno(link, r, "Could not allocate route: %m"); return r; } @@ -82,7 +81,7 @@ static int ipv4ll_route_handler(sd_netlink *rtnl, sd_netlink_message *m, void *u r = sd_netlink_message_get_errno(m); if (r < 0 && r != -EEXIST) { - log_link_error(link, "could not set ipv4ll route: %s", strerror(-r)); + log_link_error_errno(link, r, "could not set ipv4ll route: %m"); link_enter_failed(link); } @@ -103,7 +102,7 @@ static int ipv4ll_address_handler(sd_netlink *rtnl, sd_netlink_message *m, void r = sd_netlink_message_get_errno(m); if (r < 0 && r != -EEXIST) { - log_link_error(link, "could not set ipv4ll address: %s", strerror(-r)); + log_link_error_errno(link, r, "could not set ipv4ll address: %m"); link_enter_failed(link); } else if (r >= 0) link_rtnl_process_address(rtnl, m, link->manager); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 98c33171d4..e5a066aa1e 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -2514,7 +2514,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, rules_str(rules, rule->rule.filename_off), rule->rule.filename_line); r = sysctl_write(filename, value); if (r < 0) - log_error("error writing SYSCTL{%s}='%s': %s", filename, value, strerror(-r)); + log_error_errno(r, "error writing SYSCTL{%s}='%s': %s", filename, value); break; } case TK_A_RUN_BUILTIN: diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 79f45610db..3d6ca7a985 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -65,10 +65,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) { r = safe_atou(optarg, &timeout); if (r < 0) { - fprintf(stderr, "Invalid timeout value '%s': %s\n", - optarg, strerror(-r)); - exit(EXIT_FAILURE); - }; + log_error_errno(r, "Invalid timeout value '%s': %m", optarg); + return EXIT_FAILURE; + } break; } |