chiark / gitweb /
sd-device: get_subsystem - don't complain if a device does not have a subsystem
[elogind.git] / src / libelogind / sd-device / sd-device.c
index 9ef851a6bbfcd6ed53839fbc3ecab28b548b3c17..af8137b1ae99c95c6430e6f228df25faf4db392f 100644 (file)
@@ -500,6 +500,8 @@ int device_read_uevent_file(sd_device *device) {
         if (device->uevent_loaded || device->sealed)
                 return 0;
 
+        device->uevent_loaded = true;
+
         r = sd_device_get_syspath(device, &syspath);
         if (r < 0)
                 return r;
@@ -570,8 +572,6 @@ int device_read_uevent_file(sd_device *device) {
                         log_debug("sd-device: could not set 'MAJOR=%s' or 'MINOR=%s' from '%s': %s", major, minor, path, strerror(-r));
         }
 
-        device->uevent_loaded = true;
-
         return 0;
 }
 
@@ -785,7 +785,7 @@ _public_ int sd_device_get_subsystem(sd_device *device, const char **ret) {
                          path_startswith(device->devpath, "/class/") ||
                          path_startswith(device->devpath, "/bus/"))
                         r = device_set_subsystem(device, "subsystem");
-                if (r < 0)
+                if (r < 0 && r != -ENOENT)
                         return log_debug_errno(r, "sd-device: could not set subsystem for %s: %m", device->devpath);
 
                 device->subsystem_set = true;
@@ -1188,17 +1188,19 @@ int device_get_id_filename(sd_device *device, const char **ret) {
                         return r;
 
                 if (major(devnum) > 0) {
+                        assert(subsystem);
+
                         /* use dev_t -- b259:131072, c254:0 */
                         r = asprintf(&id, "%c%u:%u",
                                      streq(subsystem, "block") ? 'b' : 'c',
                                      major(devnum), minor(devnum));
                         if (r < 0)
-                                return -errno;
+                                return -ENOMEM;
                 } else if (ifindex > 0) {
                         /* use netdev ifindex -- n3 */
                         r = asprintf(&id, "n%u", ifindex);
                         if (r < 0)
-                                return -errno;
+                                return -ENOMEM;
                 } else {
                         /* use $subsys:$sysname -- pci:0000:00:1f.2
                          * sysname() has '!' translated, get it from devpath
@@ -1209,9 +1211,12 @@ int device_get_id_filename(sd_device *device, const char **ret) {
                         if (!sysname)
                                 return -EINVAL;
 
+                        if (!subsystem)
+                                return -EINVAL;
+
                         r = asprintf(&id, "+%s:%s", subsystem, sysname);
                         if (r < 0)
-                                return -errno;
+                                return -ENOMEM;
                 }
 
                 device->id_filename = id;
@@ -1243,6 +1248,8 @@ int device_read_db_aux(sd_device *device, bool force) {
         if (device->db_loaded || (!force && device->sealed))
                 return 0;
 
+        device->db_loaded = true;
+
         r = device_get_id_filename(device, &id);
         if (r < 0)
                 return r;
@@ -1311,8 +1318,6 @@ int device_read_db_aux(sd_device *device, bool force) {
                 }
         }
 
-        device->db_loaded = true;
-
         return 0;
 }