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'
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) {
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) {
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;
}
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");
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;
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? */
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;
/* 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 */
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;
}
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;
}
r = ppoll(p, ELEMENTSOF(p), ts, NULL);
}
if (r < 0) {
- log_error("ppoll() failed: %m");
+ log_error_errno(errno, "ppoll() failed: %m");
goto finish;
}
}
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);
};
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;
}
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';
}
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);
}