From: Yu Watanabe Date: Thu, 25 Oct 2018 00:56:15 +0000 (+0900) Subject: sd-device: return positive ifindex when sd_device_get_ifindex() succeeds X-Git-Tag: v240~453^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1dfa960786d147d181c583b76847135ebe512d43;p=thirdparty%2Fsystemd.git sd-device: return positive ifindex when sd_device_get_ifindex() succeeds As valid ifindex is positive value, not non-negative value. Follow-up for dcfbde3a43d632ff6e286c77e1081087eca59d8e. --- diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index 3ae283e93ca..187ea703c97 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -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)) diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 1eb71e17dbf..b97c1b97198 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -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 {