diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-05-13 11:26:55 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-05-19 14:24:03 -0400 |
commit | 25f027c5efb2a26b2c7cb9a9608eb2bd49cc5ffc (patch) | |
tree | a06ce3e12ccf6ada4027bd2f2994ad5727b3658f | |
parent | 35bca925f9bf78df3f64e321ab4830936fcef662 (diff) | |
download | systemd-25f027c5efb2a26b2c7cb9a9608eb2bd49cc5ffc.tar.gz |
tree-wide: when %m is used in log_*, always specify errno explicitly
All those uses were correct, but I think it's better to be explicit.
Using implicit errno is too error prone, and with this change we can require
(in the sense of a style guideline) that the code is always specified.
Helpful query: git grep -n -P 'log_[^s][a-z]+\(.*%m'
-rw-r--r-- | src/basic/selinux-util.c | 2 | ||||
-rw-r--r-- | src/core/cgroup.c | 3 | ||||
-rw-r--r-- | src/core/main.c | 2 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-client.c | 8 | ||||
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator.c | 12 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 3 | ||||
-rw-r--r-- | src/libudev/libudev-monitor.c | 2 | ||||
-rw-r--r-- | src/shared/install.c | 2 | ||||
-rw-r--r-- | src/stdio-bridge/stdio-bridge.c | 2 | ||||
-rw-r--r-- | src/test/test-nss.c | 2 | ||||
-rw-r--r-- | src/tmpfiles/tmpfiles.c | 7 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 18 |
12 files changed, 28 insertions, 35 deletions
diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c index bc07654668..bc53f812e3 100644 --- a/src/basic/selinux-util.c +++ b/src/basic/selinux-util.c @@ -50,7 +50,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free); static int cached_use = -1; static struct selabel_handle *label_hnd = NULL; -#define log_enforcing(...) log_full(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG, __VA_ARGS__) +#define log_enforcing(...) log_full_errno(security_getenforce() == 1 ? LOG_ERR : LOG_DEBUG, errno, __VA_ARGS__) #endif bool mac_selinux_have(void) { diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 774b832a63..71f307fb6c 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -398,8 +398,7 @@ static int whitelist_major(const char *path, const char *name, char type, const return 0; fail: - log_warning_errno(errno, "Failed to read /proc/devices: %m"); - return -errno; + return log_warning_errno(errno, "Failed to read /proc/devices: %m"); } static bool cgroup_context_has_cpu_weight(CGroupContext *c) { diff --git a/src/core/main.c b/src/core/main.c index e6ae0bee31..c2439ed185 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -536,7 +536,7 @@ static int config_parse_cpu_affinity2( return ncpus; if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0) - log_warning("Failed to set CPU affinity: %m"); + log_warning_errno(errno, "Failed to set CPU affinity: %m"); return 0; } diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 7c0317640f..e20d339bd5 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -1655,7 +1655,8 @@ static int client_receive_message_udp( if (errno == EAGAIN || errno == EINTR) return 0; - return log_dhcp_client_errno(client, errno, "Could not receive message from UDP socket: %m"); + return log_dhcp_client_errno(client, errno, + "Could not receive message from UDP socket: %m"); } if ((size_t) len < sizeof(DHCPMessage)) { log_dhcp_client(client, "Too small to be a DHCP message: ignoring"); @@ -1748,9 +1749,8 @@ static int client_receive_message_raw( if (errno == EAGAIN || errno == EINTR) return 0; - log_dhcp_client(client, "Could not receive message from raw socket: %m"); - - return -errno; + return log_dhcp_client_errno(client, errno, + "Could not receive message from raw socket: %m"); } else if ((size_t)len < sizeof(DHCPPacket)) return 0; diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index 86f8935a14..ebb8b2d160 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -631,10 +631,8 @@ static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const c if (!dir) { if (errno == ENOENT) return 0; - else { - log_error("sd-device-enumerator: could not open tags directory %s: %m", path); - return -errno; - } + else + return log_error_errno(errno, "sd-device-enumerator: could not open tags directory %s: %m", path); } /* TODO: filter away subsystems? */ @@ -758,10 +756,8 @@ static int parent_crawl_children(sd_device_enumerator *enumerator, const char *p int r = 0; dir = opendir(path); - if (!dir) { - log_debug("sd-device-enumerate: could not open parent directory %s: %m", path); - return -errno; - } + if (!dir) + return log_debug_errno(errno, "sd-device-enumerate: could not open parent directory %s: %m", path); FOREACH_DIRENT_ALL(dent, dir, return -errno) { _cleanup_free_ char *child = NULL; diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 04ead29338..c56ae39c9f 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -195,8 +195,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { /* this is not a valid device */ return -ENODEV; - log_debug("sd-device: %s does not have an uevent file: %m", syspath); - return -errno; + return log_debug_errno(errno, "sd-device: %s does not have an uevent file: %m", syspath); } } else { /* everything else just needs to be a directory */ diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c index a40329d732..8287694c49 100644 --- a/src/libudev/libudev-monitor.c +++ b/src/libudev/libudev-monitor.c @@ -681,7 +681,7 @@ retry: udev_device = udev_device_new_from_nulstr(udev_monitor->udev, &buf.raw[bufpos], buflen - bufpos); if (!udev_device) { - log_debug("could not create device: %m"); + log_debug_errno(errno, "could not create device: %m"); return NULL; } diff --git a/src/shared/install.c b/src/shared/install.c index 58c8e852b2..7f3bc0d813 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -3045,7 +3045,7 @@ int unit_file_get_list( if (errno == ENOENT) continue; if (IN_SET(errno, ENOTDIR, EACCES)) { - log_debug("Failed to open \"%s\": %m", *i); + log_debug_errno(errno, "Failed to open \"%s\": %m", *i); continue; } diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c index 02ba5269dd..097f8c1a4b 100644 --- a/src/stdio-bridge/stdio-bridge.c +++ b/src/stdio-bridge/stdio-bridge.c @@ -292,7 +292,7 @@ int main(int argc, char *argv[]) { r = ppoll(p, ELEMENTSOF(p), ts, NULL); } if (r < 0) { - log_error("ppoll() failed: %m"); + log_error_errno(errno, "ppoll() failed: %m"); goto finish; } } diff --git a/src/test/test-nss.c b/src/test/test-nss.c index b4cb3f0d37..57eeb8e40c 100644 --- a/src/test/test-nss.c +++ b/src/test/test-nss.c @@ -105,7 +105,7 @@ static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) { goto numerical_index; if (if_indextoname(it->scopeid, ifname) == NULL) { - log_warning("if_indextoname(%d) failed: %m", it->scopeid); + log_warning_errno(errno, "if_indextoname(%d) failed: %m", it->scopeid); numerical_index: xsprintf(ifname, "%i", it->scopeid); }; diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 36488c9a5c..9419c99e28 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -724,10 +724,9 @@ static int path_set_xattrs(Item *i, const char *path) { n = strlen(*value); log_debug("Setting extended attribute '%s=%s' on %s.", *name, *value, path); - if (lsetxattr(path, *name, *value, n, 0) < 0) { - log_error("Setting extended attribute %s=%s on %s failed: %m", *name, *value, path); - return -errno; - } + if (lsetxattr(path, *name, *value, n, 0) < 0) + return log_error_errno(errno, "Setting extended attribute %s=%s on %s failed: %m", + *name, *value, path); } return 0; } diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 4d07b8fce0..a1b2513794 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -814,7 +814,7 @@ static const char *get_key_attribute(struct udev *udev, char *str) { attr++; pos = strchr(attr, '}'); if (pos == NULL) { - log_error("missing closing brace for format"); + log_error("Missing closing brace for format"); return NULL; } pos[0] = '\0'; @@ -2536,19 +2536,19 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules) { } if (mode != (stats.st_mode & 01777)) { r = chmod(device_node, mode); - if (r < 0) { - log_error("failed to chmod '%s' %#o", device_node, mode); - return -errno; - } else + if (r < 0) + return log_error_errno(errno, "Failed to chmod '%s' %#o: %m", + device_node, mode); + else log_debug("chmod '%s' %#o", device_node, mode); } if ((uid != 0 && uid != stats.st_uid) || (gid != 0 && gid != stats.st_gid)) { r = chown(device_node, uid, gid); - if (r < 0) { - log_error("failed to chown '%s' %u %u ", device_node, uid, gid); - return -errno; - } else + if (r < 0) + return log_error_errno(errno, "Failed to chown '%s' %u %u: %m", + device_node, uid, gid); + else log_debug("chown '%s' %u %u", device_node, uid, gid); } |