1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-09 09:57:26 +03:00

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'
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-05-13 11:26:55 -04:00
parent 35bca925f9
commit 25f027c5ef
12 changed files with 28 additions and 35 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
};

View File

@ -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;
}

View File

@ -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);
}