From: Zbigniew Jędrzejewski-Szmek Date: Thu, 16 Jul 2020 16:04:45 +0000 (+0200) Subject: tree-wide: use SYNTHETIC_ERRNO with log_device_* in more places X-Git-Tag: v246-rc2~53^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16491%2Fhead;p=thirdparty%2Fsystemd.git tree-wide: use SYNTHETIC_ERRNO with log_device_* in more places --- diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index ffec11bbd35..bed45da8e4e 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -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); diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 16f8627bdbc..1e61732dfe6 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -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); diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index 84d5288c75e..f5873d1c062 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -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) diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index a34b8d69452..31a34030935 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -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 &&