summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-10-25 09:56:15 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-10-27 07:03:38 +0900
commit1dfa960786d147d181c583b76847135ebe512d43 (patch)
treef5832d5a4ab35dc4b54d0a491834f371ef2595f5
parent9bf7dba739379e6644a6950834f271f028a2e73f (diff)
downloadsystemd-1dfa960786d147d181c583b76847135ebe512d43.tar.gz
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.
-rw-r--r--src/libsystemd/sd-device/device-enumerator.c2
-rw-r--r--src/libsystemd/sd-device/sd-device.c7
2 files changed, 4 insertions, 5 deletions
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c
index 3ae283e93c..187ea703c9 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 1eb71e17db..b97c1b9719 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 {