chiark / gitweb /
sd-device: enumerator - match only on initialized devices by default
authorTom Gundersen <teg@jklm.no>
Fri, 17 Apr 2015 12:11:00 +0000 (14:11 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 07:06:45 +0000 (08:06 +0100)
It is still possible to include uninitialized ones, but now that is opt-in. In most
cases people only want initialized devices. Exception is if you want to work without
udev running.

Suggested by David Herrmann.

src/libsystemd/sd-device/device-enumerator-private.h
src/libsystemd/sd-device/device-enumerator.c
src/systemd/sd-device.h

index 4bcb13d..543aed4 100644 (file)
@@ -27,6 +27,7 @@
 int device_enumerator_scan_devices(sd_device_enumerator *enumeartor);
 int device_enumerator_scan_subsystems(sd_device_enumerator *enumeartor);
 int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device);
+int device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator);
 sd_device *device_enumerator_get_first(sd_device_enumerator *enumerator);
 sd_device *device_enumerator_get_next(sd_device_enumerator *enumerator);
 
index eb637f5..49c44bc 100644 (file)
@@ -52,7 +52,7 @@ struct sd_device_enumerator {
         Set *match_sysname;
         Set *match_tag;
         sd_device *match_parent;
-        bool match_is_initialized;
+        bool match_allow_uninitialized;
 };
 
 _public_ int sd_device_enumerator_new(sd_device_enumerator **ret) {
@@ -250,10 +250,20 @@ _public_ int sd_device_enumerator_add_match_parent(sd_device_enumerator *enumera
         return 0;
 }
 
-_public_ int sd_device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator) {
+_public_ int sd_device_enumerator_allow_uninitialized(sd_device_enumerator *enumerator) {
         assert_return(enumerator, -EINVAL);
 
-        enumerator->match_is_initialized = true;
+        enumerator->match_allow_uninitialized = true;
+
+        enumerator->scan_uptodate = false;
+
+        return 0;
+}
+
+int device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator) {
+        assert_return(enumerator, -EINVAL);
+
+        enumerator->match_allow_uninitialized = false;
 
         enumerator->scan_uptodate = false;
 
@@ -527,7 +537,7 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
                  * might not store a database, and have no way to find out
                  * for all other types of devices.
                  */
-                if (enumerator->match_is_initialized &&
+                if (!enumerator->match_allow_uninitialized &&
                     !initialized &&
                     (major(devnum) > 0 || ifindex > 0))
                         continue;
index 86f7670..38cb2a1 100644 (file)
@@ -92,7 +92,7 @@ int sd_device_enumerator_add_match_property(sd_device_enumerator *enumerator, co
 int sd_device_enumerator_add_match_sysname(sd_device_enumerator *enumerator, const char *sysname);
 int sd_device_enumerator_add_match_tag(sd_device_enumerator *enumerator, const char *tag);
 int sd_device_enumerator_add_match_parent(sd_device_enumerator *enumerator, sd_device *parent);
-int sd_device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator);
+int sd_device_enumerator_allow_uninitialized(sd_device_enumerator *enumerator);
 
 _SD_END_DECLARATIONS;