]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: return positive ifindex when sd_device_get_ifindex() succeeds
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 25 Oct 2018 00:56:15 +0000 (09:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 26 Oct 2018 22:03:38 +0000 (07:03 +0900)
As valid ifindex is positive value, not non-negative value.

Follow-up for dcfbde3a43d632ff6e286c77e1081087eca59d8e.

src/libsystemd/sd-device/device-enumerator.c
src/libsystemd/sd-device/sd-device.c

index 3ae283e93cab49b8b489112fd3ac7871a600c98b..187ea703c97c536e97566bcb73a219aa925886f0 100644 (file)
@@ -497,7 +497,7 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
                 if (!enumerator->match_allow_uninitialized &&
                     !initialized &&
                     (sd_device_get_devnum(device, &devnum) >= 0 ||
-                     (sd_device_get_ifindex(device, &ifindex) >= 0 && ifindex > 0)))
+                     sd_device_get_ifindex(device, &ifindex) >= 0))
                         continue;
 
                 if (!match_parent(enumerator, device))
index 1eb71e17dbfd8bf00d86ab13a484c91d2a131943..b97c1b97198becdfba426d29b9b081bb221361fd 100644 (file)
@@ -38,7 +38,6 @@ int device_new_aux(sd_device **ret) {
         *device = (sd_device) {
                 .n_ref = 1,
                 .watch_handle = -1,
-                .ifindex = -1,
                 .devmode = (mode_t) -1,
                 .devuid = (uid_t) -1,
                 .devgid = (gid_t) -1,
@@ -579,7 +578,7 @@ _public_ int sd_device_get_ifindex(sd_device *device, int *ifindex) {
         if (r < 0)
                 return r;
 
-        if (device->ifindex < 0)
+        if (device->ifindex <= 0)
                 return -ENOENT;
 
         *ifindex = device->ifindex;
@@ -1241,9 +1240,9 @@ int device_get_id_filename(sd_device *device, const char **ret) {
                                      major(devnum), minor(devnum));
                         if (r < 0)
                                 return -ENOMEM;
-                } else if (sd_device_get_ifindex(device, &ifindex) >= 0 && ifindex > 0) {
+                } else if (sd_device_get_ifindex(device, &ifindex) >= 0) {
                         /* use netdev ifindex — n3 */
-                        r = asprintf(&id, "n%u", ifindex);
+                        r = asprintf(&id, "n%u", (unsigned) ifindex);
                         if (r < 0)
                                 return -ENOMEM;
                 } else {