1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-20 18:04:03 +03:00

tree-wide: use SYNTHETIC_ERRNO with log_device_* in more places

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-07-16 18:04:45 +02:00
parent 46d4149d0f
commit 9e79123884
4 changed files with 23 additions and 28 deletions

View File

@ -558,10 +558,9 @@ int device_monitor_send_device(
r = device_get_properties_nulstr(device, (const uint8_t **) &buf, &blen);
if (r < 0)
return log_device_debug_errno(device, r, "sd-device-monitor: Failed to get device properties: %m");
if (blen < 32) {
log_device_debug(device, "sd-device-monitor: Length of device property nulstr is too small to contain valid device information");
return -EINVAL;
}
if (blen < 32)
log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),
"sd-device-monitor: Length of device property nulstr is too small to contain valid device information");
/* fill in versioned header */
r = sd_device_get_subsystem(device, &val);

View File

@ -363,10 +363,9 @@ static int device_append(sd_device *device, char *key, const char **_major, cons
assert(_minor);
value = strchr(key, '=');
if (!value) {
log_device_debug(device, "sd-device: Not a key-value pair: '%s'", key);
return -EINVAL;
}
if (!value)
return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),
"sd-device: Not a key-value pair: '%s'", key);
*value = '\0';
@ -400,10 +399,9 @@ void device_seal(sd_device *device) {
static int device_verify(sd_device *device) {
assert(device);
if (!device->devpath || !device->subsystem || device->action < 0 || device->seqnum == 0) {
log_device_debug(device, "sd-device: Device created from strv or nulstr lacks devpath, subsystem, action or seqnum.");
return -EINVAL;
}
if (!device->devpath || !device->subsystem || device->action < 0 || device->seqnum == 0)
return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),
"sd-device: Device created from strv or nulstr lacks devpath, subsystem, action or seqnum.");
device->sealed = true;
@ -464,10 +462,10 @@ int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len) {
key = (char*)&nulstr[i];
end = memchr(key, '\0', len - i);
if (!end) {
log_device_debug(device, "sd-device: Failed to parse nulstr");
return -EINVAL;
}
if (!end)
return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),
"sd-device: Failed to parse nulstr");
i += end - key + 1;
r = device_append(device, key, &major, &minor);

View File

@ -936,10 +936,9 @@ static int umount_by_device(sd_bus *bus, const char *what) {
if (r < 0)
return log_device_error_errno(d, r, "Failed to get device property: %m");
if (!streq(v, "filesystem")) {
log_device_error(d, "%s does not contain a known file system.", what);
return -EINVAL;
}
if (!streq(v, "filesystem"))
return log_device_error_errno(d, SYNTHETIC_ERRNO(EINVAL),
"%s does not contain a known file system.", what);
if (sd_device_get_property_value(d, "SYSTEMD_MOUNT_WHERE", &v) >= 0)
r2 = stop_mounts(bus, v);
@ -1275,10 +1274,9 @@ static int discover_loop_backing_file(void) {
if (r < 0)
return log_error_errno(r, "Failed to get device from device number: %m");
if (sd_device_get_property_value(d, "ID_FS_USAGE", &v) < 0 || !streq(v, "filesystem")) {
log_device_error(d, "%s does not contain a known file system.", arg_mount_what);
return -EINVAL;
}
if (sd_device_get_property_value(d, "ID_FS_USAGE", &v) < 0 || !streq(v, "filesystem"))
return log_device_error_errno(d, SYNTHETIC_ERRNO(EINVAL),
"%s does not contain a known file system.", arg_mount_what);
r = acquire_mount_type(d);
if (r < 0)

View File

@ -47,10 +47,10 @@ static int node_symlink(sd_device *dev, const char *node, const char *slink) {
/* preserve link with correct target, do not replace node of other device */
if (lstat(slink, &stats) == 0) {
if (S_ISBLK(stats.st_mode) || S_ISCHR(stats.st_mode)) {
log_device_error(dev, "Conflicting device node '%s' found, link to '%s' will not be created.", slink, node);
return -EOPNOTSUPP;
} else if (S_ISLNK(stats.st_mode)) {
if (S_ISBLK(stats.st_mode) || S_ISCHR(stats.st_mode))
return log_device_error_errno(dev, SYNTHETIC_ERRNO(EOPNOTSUPP),
"Conflicting device node '%s' found, link to '%s' will not be created.", slink, node);
else if (S_ISLNK(stats.st_mode)) {
_cleanup_free_ char *buf = NULL;
if (readlink_malloc(slink, &buf) >= 0 &&