sd-device: use specific setters for read entries from uevent file
Previously, if e.g. DRIVER=foo is specified in uevent file, the value is only saved as property, but was not set to sd_device.driver. That was inconsistent to the case when a device is created through netlink uevent. Let's always set when we get e.g. sd_device.driver when DRIVER=foo from both uevent file and netlink uevent.
This commit is contained in:
@@ -106,6 +106,8 @@ static inline int device_add_property_internal(sd_device *device, const char *ke
|
||||
|
||||
int device_set_syspath(sd_device *device, const char *_syspath, bool verify);
|
||||
int device_set_ifindex(sd_device *device, const char *ifindex);
|
||||
int device_set_devuid(sd_device *device, const char *uid);
|
||||
int device_set_devgid(sd_device *device, const char *gid);
|
||||
int device_set_devmode(sd_device *device, const char *devmode);
|
||||
int device_set_devname(sd_device *device, const char *devname);
|
||||
int device_set_devtype(sd_device *device, const char *devtype);
|
||||
|
||||
@@ -116,6 +116,10 @@ int device_get_devnode_mode(sd_device *device, mode_t *ret) {
|
||||
|
||||
assert(device);
|
||||
|
||||
r = device_read_uevent_file(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = device_read_db(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -134,6 +138,10 @@ int device_get_devnode_uid(sd_device *device, uid_t *ret) {
|
||||
|
||||
assert(device);
|
||||
|
||||
r = device_read_uevent_file(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = device_read_db(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -147,7 +155,7 @@ int device_get_devnode_uid(sd_device *device, uid_t *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int device_set_devuid(sd_device *device, const char *uid) {
|
||||
int device_set_devuid(sd_device *device, const char *uid) {
|
||||
uid_t u;
|
||||
int r;
|
||||
|
||||
@@ -172,6 +180,10 @@ int device_get_devnode_gid(sd_device *device, gid_t *ret) {
|
||||
|
||||
assert(device);
|
||||
|
||||
r = device_read_uevent_file(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = device_read_db(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -185,7 +197,7 @@ int device_get_devnode_gid(sd_device *device, gid_t *ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int device_set_devgid(sd_device *device, const char *gid) {
|
||||
int device_set_devgid(sd_device *device, const char *gid) {
|
||||
gid_t g;
|
||||
int r;
|
||||
|
||||
|
||||
@@ -766,16 +766,24 @@ static int handle_uevent_line(
|
||||
assert(major);
|
||||
assert(minor);
|
||||
|
||||
if (streq(key, "SUBSYSTEM"))
|
||||
return device_set_subsystem(device, value);
|
||||
if (streq(key, "DEVTYPE"))
|
||||
return device_set_devtype(device, value);
|
||||
if (streq(key, "IFINDEX"))
|
||||
return device_set_ifindex(device, value);
|
||||
if (streq(key, "DEVNAME"))
|
||||
return device_set_devname(device, value);
|
||||
if (streq(key, "DEVUID"))
|
||||
return device_set_devuid(device, value);
|
||||
if (streq(key, "DEVGID"))
|
||||
return device_set_devgid(device, value);
|
||||
if (streq(key, "DEVMODE"))
|
||||
return device_set_devmode(device, value);
|
||||
if (streq(key, "DISKSEQ"))
|
||||
return device_set_diskseq(device, value);
|
||||
if (streq(key, "DRIVER"))
|
||||
return device_set_driver(device, value);
|
||||
if (streq(key, "MAJOR"))
|
||||
*major = value;
|
||||
else if (streq(key, "MINOR"))
|
||||
@@ -835,6 +843,13 @@ int device_read_uevent_file(sd_device *device) {
|
||||
major, strna(minor));
|
||||
}
|
||||
|
||||
if (device_in_subsystem(device, "drivers")) {
|
||||
r = device_set_drivers_subsystem(device);
|
||||
if (r < 0)
|
||||
log_device_debug_errno(device, r,
|
||||
"sd-device: Failed to set driver subsystem, ignoring: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1177,6 +1192,10 @@ _public_ int sd_device_get_subsystem(sd_device *device, const char **ret) {
|
||||
|
||||
assert_return(device, -EINVAL);
|
||||
|
||||
r = device_read_uevent_file(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!device->subsystem_set) {
|
||||
const char *subsystem;
|
||||
|
||||
@@ -1308,6 +1327,10 @@ _public_ int sd_device_get_driver(sd_device *device, const char **ret) {
|
||||
|
||||
assert_return(device, -EINVAL);
|
||||
|
||||
r = device_read_uevent_file(device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!device->driver_set) {
|
||||
const char *driver = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user