diff options
author | Ian Stakenvicius <axs@gentoo.org> | 2013-01-25 10:47:52 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2013-01-28 17:42:47 -0500 |
commit | ab779c81460ce48e6b270977ef339b32d87c1f41 (patch) | |
tree | 06d1c74756194d17dbfd3eaa2a171a735230aa23 /src/libudev/libudev-device.c | |
parent | cc9cf4c078702fcb8e88fe6f00303d821aabffce (diff) |
Honor DEVUID, DEVGID in addition to DEVMODE
New behaviour in udev-197
systemd commit 1edefa4f1d7bae6cc19aa4a97238400c5a04f7a4
Author: Kay Sievers <kay@vrfy.org>
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/libudev/libudev-device.c')
-rw-r--r-- | src/libudev/libudev-device.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 6423651b35..e911b73b2b 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -60,6 +60,8 @@ struct udev_device { const char *sysnum; char *devnode; mode_t devnode_mode; + uid_t devnode_uid; + gid_t devnode_gid; char *subsystem; char *devtype; char *driver; @@ -323,6 +325,40 @@ static int udev_device_set_devnode_mode(struct udev_device *udev_device, mode_t return 0; } +uid_t udev_device_get_devnode_uid(struct udev_device *udev_device) +{ + if (!udev_device->info_loaded) + udev_device_read_uevent_file(udev_device); + return udev_device->devnode_uid; +} + +static int udev_device_set_devnode_uid(struct udev_device *udev_device, uid_t uid) +{ + char num[32]; + + udev_device->devnode_uid = uid; + snprintf(num, sizeof(num), "%u", uid); + udev_device_add_property(udev_device, "DEVUID", num); + return 0; +} + +gid_t udev_device_get_devnode_gid(struct udev_device *udev_device) +{ + if (!udev_device->info_loaded) + udev_device_read_uevent_file(udev_device); + return udev_device->devnode_gid; +} + +static int udev_device_set_devnode_gid(struct udev_device *udev_device, gid_t gid) +{ + char num[32]; + + udev_device->devnode_gid = gid; + snprintf(num, sizeof(num), "%u", gid); + udev_device_add_property(udev_device, "DEVGID", num); + return 0; +} + struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value) { udev_device->envp_uptodate = false; @@ -430,6 +466,10 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device, udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10)); } else if (startswith(property, "DEVMODE=")) { udev_device_set_devnode_mode(udev_device, strtoul(&property[8], NULL, 8)); + } else if (startswith(property, "DEVUID=")) { + udev_device_set_devnode_uid(udev_device, strtoul(&property[7], NULL, 10)); + } else if (startswith(property, "DEVGID=")) { + udev_device_set_devnode_gid(udev_device, strtoul(&property[7], NULL, 10)); } else { udev_device_add_property_from_string(udev_device, property); } |