sd-device: make sd_device_get_*() return -ENOENT if the values are not set
This commit is contained in:
parent
feae122f3e
commit
dcfbde3a43
|
@ -478,18 +478,6 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
k = sd_device_get_devnum(device, &devnum);
|
|
||||||
if (k < 0) {
|
|
||||||
r = k;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
k = sd_device_get_ifindex(device, &ifindex);
|
|
||||||
if (k < 0) {
|
|
||||||
r = k;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
k = sd_device_get_is_initialized(device, &initialized);
|
k = sd_device_get_is_initialized(device, &initialized);
|
||||||
if (k < 0) {
|
if (k < 0) {
|
||||||
r = k;
|
r = k;
|
||||||
|
@ -508,7 +496,8 @@ static int enumerator_scan_dir_and_add_devices(sd_device_enumerator *enumerator,
|
||||||
*/
|
*/
|
||||||
if (!enumerator->match_allow_uninitialized &&
|
if (!enumerator->match_allow_uninitialized &&
|
||||||
!initialized &&
|
!initialized &&
|
||||||
(major(devnum) > 0 || ifindex > 0))
|
(sd_device_get_devnum(device, &devnum) >= 0 ||
|
||||||
|
(sd_device_get_ifindex(device, &ifindex) >= 0 && ifindex > 0)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!match_parent(enumerator, device))
|
if (!match_parent(enumerator, device))
|
||||||
|
|
|
@ -277,6 +277,9 @@ int device_get_devnode_mode(sd_device *device, mode_t *mode) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
if (device->devmode == (mode_t) -1)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
*mode = device->devmode;
|
*mode = device->devmode;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -292,6 +295,9 @@ int device_get_devnode_uid(sd_device *device, uid_t *uid) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
if (device->devuid == (uid_t) -1)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
*uid = device->devuid;
|
*uid = device->devuid;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -327,6 +333,9 @@ int device_get_devnode_gid(sd_device *device, gid_t *gid) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
if (device->devgid == (gid_t) -1)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
*gid = device->devgid;
|
*gid = device->devgid;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -723,6 +732,9 @@ int device_get_watch_handle(sd_device *device, int *handle) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
if (device->watch_handle < 0)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
*handle = device->watch_handle;
|
*handle = device->watch_handle;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -38,6 +38,10 @@ int device_new_aux(sd_device **ret) {
|
||||||
*device = (sd_device) {
|
*device = (sd_device) {
|
||||||
.n_ref = 1,
|
.n_ref = 1,
|
||||||
.watch_handle = -1,
|
.watch_handle = -1,
|
||||||
|
.ifindex = -1,
|
||||||
|
.devmode = (mode_t) -1,
|
||||||
|
.devuid = (uid_t) -1,
|
||||||
|
.devgid = (gid_t) -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
*ret = device;
|
*ret = device;
|
||||||
|
@ -575,6 +579,9 @@ _public_ int sd_device_get_ifindex(sd_device *device, int *ifindex) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
if (device->ifindex < 0)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
*ifindex = device->ifindex;
|
*ifindex = device->ifindex;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -839,6 +846,9 @@ _public_ int sd_device_get_devtype(sd_device *device, const char **devtype) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
if (!device->devtype)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
*devtype = device->devtype;
|
*devtype = device->devtype;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -886,6 +896,9 @@ _public_ int sd_device_get_devnum(sd_device *device, dev_t *devnum) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
if (major(device->devnum) <= 0)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
*devnum = device->devnum;
|
*devnum = device->devnum;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1053,6 +1066,9 @@ _public_ int sd_device_get_sysnum(sd_device *device, const char **ret) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!device->sysnum)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
*ret = device->sysnum;
|
*ret = device->sysnum;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1216,15 +1232,7 @@ int device_get_id_filename(sd_device *device, const char **ret) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = sd_device_get_devnum(device, &devnum);
|
if (sd_device_get_devnum(device, &devnum) >= 0) {
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
r = sd_device_get_ifindex(device, &ifindex);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
if (major(devnum) > 0) {
|
|
||||||
assert(subsystem);
|
assert(subsystem);
|
||||||
|
|
||||||
/* use dev_t — b259:131072, c254:0 */
|
/* use dev_t — b259:131072, c254:0 */
|
||||||
|
@ -1233,7 +1241,7 @@ int device_get_id_filename(sd_device *device, const char **ret) {
|
||||||
major(devnum), minor(devnum));
|
major(devnum), minor(devnum));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
} else if (ifindex > 0) {
|
} else if (sd_device_get_ifindex(device, &ifindex) >= 0 && ifindex > 0) {
|
||||||
/* use netdev ifindex — n3 */
|
/* use netdev ifindex — n3 */
|
||||||
r = asprintf(&id, "n%u", ifindex);
|
r = asprintf(&id, "n%u", ifindex);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
|
@ -85,6 +85,7 @@ _public_ dev_t udev_device_get_devnum(struct udev_device *udev_device) {
|
||||||
|
|
||||||
r = sd_device_get_devnum(udev_device->device, &devnum);
|
r = sd_device_get_devnum(udev_device->device, &devnum);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
|
if (r != -ENOENT)
|
||||||
errno = -r;
|
errno = -r;
|
||||||
return makedev(0, 0);
|
return makedev(0, 0);
|
||||||
}
|
}
|
||||||
|
@ -131,6 +132,7 @@ _public_ const char *udev_device_get_devtype(struct udev_device *udev_device) {
|
||||||
|
|
||||||
r = sd_device_get_devtype(udev_device->device, &devtype);
|
r = sd_device_get_devtype(udev_device->device, &devtype);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
|
if (r != -ENOENT)
|
||||||
errno = -r;
|
errno = -r;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -582,6 +584,7 @@ _public_ const char *udev_device_get_sysnum(struct udev_device *udev_device) {
|
||||||
|
|
||||||
r = sd_device_get_sysnum(udev_device->device, &sysnum);
|
r = sd_device_get_sysnum(udev_device->device, &sysnum);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
|
if (r != -ENOENT)
|
||||||
errno = -r;
|
errno = -r;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue