]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use SYNTHETIC_ERRNO with log_device_* in more places 16491/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 16 Jul 2020 16:04:45 +0000 (18:04 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 16 Jul 2020 20:08:12 +0000 (22:08 +0200)
src/libsystemd/sd-device/device-monitor.c
src/libsystemd/sd-device/device-private.c
src/mount/mount-tool.c
src/udev/udev-node.c

index ffec11bbd35c981b1109ed391b772609f52297e0..bed45da8e4e1d6ecaa7ad7e2aeea3d91c8f3a7fa 100644 (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);
index 16f8627bdbc147a511f58d38b980f8180d0d442d..1e61732dfe6d15caf9c5be196d21518153b8f1f3 100644 (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);
index 84d5288c75e14c33a94adc2532fe5f5cdcf5760a..f5873d1c06218dcacab53810ce7534603727796e 100644 (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)
index a34b8d694521ba1ef4a500d444a5a1397089806d..31a34030935829a4f6b97382fdfd9dc556dd84c4 100644 (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 &&