mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-06 13:17:44 +03:00
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.
This commit is contained in:
parent
618234a525
commit
e53fc357a9
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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];
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user