mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-10 13:57:25 +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:
parent
35bca925f9
commit
25f027c5ef
@ -50,7 +50,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(context_t, context_free);
|
|||||||
static int cached_use = -1;
|
static int cached_use = -1;
|
||||||
static struct selabel_handle *label_hnd = NULL;
|
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
|
#endif
|
||||||
|
|
||||||
bool mac_selinux_have(void) {
|
bool mac_selinux_have(void) {
|
||||||
|
@ -398,8 +398,7 @@ static int whitelist_major(const char *path, const char *name, char type, const
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
log_warning_errno(errno, "Failed to read /proc/devices: %m");
|
return log_warning_errno(errno, "Failed to read /proc/devices: %m");
|
||||||
return -errno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cgroup_context_has_cpu_weight(CGroupContext *c) {
|
static bool cgroup_context_has_cpu_weight(CGroupContext *c) {
|
||||||
|
@ -536,7 +536,7 @@ static int config_parse_cpu_affinity2(
|
|||||||
return ncpus;
|
return ncpus;
|
||||||
|
|
||||||
if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1655,7 +1655,8 @@ static int client_receive_message_udp(
|
|||||||
if (errno == EAGAIN || errno == EINTR)
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
return 0;
|
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)) {
|
if ((size_t) len < sizeof(DHCPMessage)) {
|
||||||
log_dhcp_client(client, "Too small to be a DHCP message: ignoring");
|
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)
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
log_dhcp_client(client, "Could not receive message from raw socket: %m");
|
return log_dhcp_client_errno(client, errno,
|
||||||
|
"Could not receive message from raw socket: %m");
|
||||||
return -errno;
|
|
||||||
} else if ((size_t)len < sizeof(DHCPPacket))
|
} else if ((size_t)len < sizeof(DHCPPacket))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -631,10 +631,8 @@ static int enumerator_scan_devices_tag(sd_device_enumerator *enumerator, const c
|
|||||||
if (!dir) {
|
if (!dir) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return 0;
|
return 0;
|
||||||
else {
|
else
|
||||||
log_error("sd-device-enumerator: could not open tags directory %s: %m", path);
|
return log_error_errno(errno, "sd-device-enumerator: could not open tags directory %s: %m", path);
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: filter away subsystems? */
|
/* TODO: filter away subsystems? */
|
||||||
@ -758,10 +756,8 @@ static int parent_crawl_children(sd_device_enumerator *enumerator, const char *p
|
|||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (!dir) {
|
if (!dir)
|
||||||
log_debug("sd-device-enumerate: could not open parent directory %s: %m", path);
|
return log_debug_errno(errno, "sd-device-enumerate: could not open parent directory %s: %m", path);
|
||||||
return -errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
|
FOREACH_DIRENT_ALL(dent, dir, return -errno) {
|
||||||
_cleanup_free_ char *child = NULL;
|
_cleanup_free_ char *child = NULL;
|
||||||
|
@ -195,8 +195,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
|
|||||||
/* this is not a valid device */
|
/* this is not a valid device */
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
log_debug("sd-device: %s does not have an uevent file: %m", syspath);
|
return log_debug_errno(errno, "sd-device: %s does not have an uevent file: %m", syspath);
|
||||||
return -errno;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* everything else just needs to be a directory */
|
/* everything else just needs to be a directory */
|
||||||
|
@ -681,7 +681,7 @@ retry:
|
|||||||
|
|
||||||
udev_device = udev_device_new_from_nulstr(udev_monitor->udev, &buf.raw[bufpos], buflen - bufpos);
|
udev_device = udev_device_new_from_nulstr(udev_monitor->udev, &buf.raw[bufpos], buflen - bufpos);
|
||||||
if (!udev_device) {
|
if (!udev_device) {
|
||||||
log_debug("could not create device: %m");
|
log_debug_errno(errno, "could not create device: %m");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3045,7 +3045,7 @@ int unit_file_get_list(
|
|||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
continue;
|
continue;
|
||||||
if (IN_SET(errno, ENOTDIR, EACCES)) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ int main(int argc, char *argv[]) {
|
|||||||
r = ppoll(p, ELEMENTSOF(p), ts, NULL);
|
r = ppoll(p, ELEMENTSOF(p), ts, NULL);
|
||||||
}
|
}
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_error("ppoll() failed: %m");
|
log_error_errno(errno, "ppoll() failed: %m");
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) {
|
|||||||
goto numerical_index;
|
goto numerical_index;
|
||||||
|
|
||||||
if (if_indextoname(it->scopeid, ifname) == NULL) {
|
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:
|
numerical_index:
|
||||||
xsprintf(ifname, "%i", it->scopeid);
|
xsprintf(ifname, "%i", it->scopeid);
|
||||||
};
|
};
|
||||||
|
@ -724,10 +724,9 @@ static int path_set_xattrs(Item *i, const char *path) {
|
|||||||
|
|
||||||
n = strlen(*value);
|
n = strlen(*value);
|
||||||
log_debug("Setting extended attribute '%s=%s' on %s.", *name, *value, path);
|
log_debug("Setting extended attribute '%s=%s' on %s.", *name, *value, path);
|
||||||
if (lsetxattr(path, *name, *value, n, 0) < 0) {
|
if (lsetxattr(path, *name, *value, n, 0) < 0)
|
||||||
log_error("Setting extended attribute %s=%s on %s failed: %m", *name, *value, path);
|
return log_error_errno(errno, "Setting extended attribute %s=%s on %s failed: %m",
|
||||||
return -errno;
|
*name, *value, path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -814,7 +814,7 @@ static const char *get_key_attribute(struct udev *udev, char *str) {
|
|||||||
attr++;
|
attr++;
|
||||||
pos = strchr(attr, '}');
|
pos = strchr(attr, '}');
|
||||||
if (pos == NULL) {
|
if (pos == NULL) {
|
||||||
log_error("missing closing brace for format");
|
log_error("Missing closing brace for format");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pos[0] = '\0';
|
pos[0] = '\0';
|
||||||
@ -2536,19 +2536,19 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules) {
|
|||||||
}
|
}
|
||||||
if (mode != (stats.st_mode & 01777)) {
|
if (mode != (stats.st_mode & 01777)) {
|
||||||
r = chmod(device_node, mode);
|
r = chmod(device_node, mode);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error("failed to chmod '%s' %#o", device_node, mode);
|
return log_error_errno(errno, "Failed to chmod '%s' %#o: %m",
|
||||||
return -errno;
|
device_node, mode);
|
||||||
} else
|
else
|
||||||
log_debug("chmod '%s' %#o", device_node, mode);
|
log_debug("chmod '%s' %#o", device_node, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((uid != 0 && uid != stats.st_uid) || (gid != 0 && gid != stats.st_gid)) {
|
if ((uid != 0 && uid != stats.st_uid) || (gid != 0 && gid != stats.st_gid)) {
|
||||||
r = chown(device_node, uid, gid);
|
r = chown(device_node, uid, gid);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error("failed to chown '%s' %u %u ", device_node, uid, gid);
|
return log_error_errno(errno, "Failed to chown '%s' %u %u: %m",
|
||||||
return -errno;
|
device_node, uid, gid);
|
||||||
} else
|
else
|
||||||
log_debug("chown '%s' %u %u", device_node, uid, gid);
|
log_debug("chown '%s' %u %u", device_node, uid, gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user