summaryrefslogtreecommitdiff
path: root/libudev
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2011-05-16 22:04:02 +0200
committerKay Sievers <kay.sievers@vrfy.org>2011-05-16 22:04:02 +0200
commit3cf1a8e36ed0d9bb9b000adf36dd347e8d988478 (patch)
tree132994a3ad9dac2975919b53d627aed798974cc9 /libudev
parent4b718be86db37a37c83793ca410e8d9968e615f2 (diff)
libudev: device - use DEVMODE from kernel as the default mode
Diffstat (limited to 'libudev')
-rw-r--r--libudev/libudev-device.c22
-rw-r--r--libudev/libudev-private.h2
-rw-r--r--libudev/test-libudev.c2
3 files changed, 25 insertions, 1 deletions
diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c
index ffde21ad57..d57a9eb597 100644
--- a/libudev/libudev-device.c
+++ b/libudev/libudev-device.c
@@ -51,6 +51,7 @@ struct udev_device {
char *sysname;
const char *sysnum;
char *devnode;
+ mode_t devnode_mode;
char *subsystem;
char *devtype;
char *driver;
@@ -199,6 +200,8 @@ void udev_device_add_property_from_string_parse(struct udev_device *udev_device,
udev_device_set_timeout(udev_device, strtoull(&property[8], NULL, 10));
} else if (strncmp(property, "IFINDEX=", 8) == 0) {
udev_device_set_ifindex(udev_device, strtoull(&property[8], NULL, 10));
+ } else if (strncmp(property, "DEVMODE=", 8) == 0) {
+ udev_device_set_devnode_mode(udev_device, strtoul(&property[8], NULL, 8));
} else {
udev_device_add_property_from_string(udev_device, property);
}
@@ -343,6 +346,8 @@ int udev_device_read_uevent_file(struct udev_device *udev_device)
udev_device_set_ifindex(udev_device, strtoull(&line[8], NULL, 10));
else if (strncmp(line, "DEVNAME=", 8) == 0)
udev_device_set_knodename(udev_device, &line[8]);
+ else if (strncmp(line, "DEVMODE=", 8) == 0)
+ udev_device->devnode_mode = strtoul(&line[8], NULL, 8);
udev_device_add_property_from_string(udev_device, line);
}
@@ -930,6 +935,13 @@ const char *udev_device_get_devnode(struct udev_device *udev_device)
return udev_device->devnode;
}
+mode_t udev_device_get_devnode_mode(struct udev_device *udev_device)
+{
+ if (!udev_device->info_loaded)
+ udev_device_read_uevent_file(udev_device);
+ return udev_device->devnode_mode;
+}
+
/**
* udev_device_get_subsystem:
* @udev_device: udev device
@@ -1414,6 +1426,16 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode
return 0;
}
+int udev_device_set_devnode_mode(struct udev_device *udev_device, mode_t mode)
+{
+ char num[32];
+
+ udev_device->devnode_mode = mode;
+ snprintf(num, sizeof(num), "%#o", mode);
+ udev_device_add_property(udev_device, "DEVMODE", num);
+ return 0;
+}
+
int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink, int unique)
{
struct udev_list_entry *list_entry;
diff --git a/libudev/libudev-private.h b/libudev/libudev-private.h
index 2fcfe4131c..39b46dde31 100644
--- a/libudev/libudev-private.h
+++ b/libudev/libudev-private.h
@@ -69,6 +69,8 @@ struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev);
/* libudev-device.c */
struct udev_device *udev_device_new(struct udev *udev);
struct udev_device *udev_device_new_from_id_filename(struct udev *udev, char *id);
+mode_t udev_device_get_devnode_mode(struct udev_device *udev_device);
+int udev_device_set_devnode_mode(struct udev_device *udev_device, mode_t mode);
int udev_device_set_syspath(struct udev_device *udev_device, const char *syspath);
int udev_device_set_subsystem(struct udev_device *udev_device, const char *subsystem);
int udev_device_set_devtype(struct udev_device *udev_device, const char *devtype);
diff --git a/libudev/test-libudev.c b/libudev/test-libudev.c
index 4192ba14b2..966a406507 100644
--- a/libudev/test-libudev.c
+++ b/libudev/test-libudev.c
@@ -221,7 +221,7 @@ static int test_enumerate_print_list(struct udev_enumerate *enumerate)
static int test_monitor(struct udev *udev)
{
- struct udev_monitor *udev_monitor;
+ struct udev_monitor *udev_monitor = NULL;
int fd_ep;
int fd_udev = -1;
struct epoll_event ep_udev, ep_stdin;