summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2008-10-15 16:56:06 +0200
committerKay Sievers <kay.sievers@vrfy.org>2008-10-15 16:56:06 +0200
commitbd85566c16bd9ba32a44a1b2902127f459f4a63c (patch)
tree03aaf4ce538c1e080f2a71dc6675e9bd14d45a59
parent1e61ff54f52c89c1ec0cffd595dc9b1980df2be4 (diff)
libudev: update DEVLINKS property when properties are read
-rw-r--r--udev/lib/libudev-device.c34
-rw-r--r--udev/lib/libudev-private.h1
2 files changed, 23 insertions, 12 deletions
diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c
index c76be21e82..5b90af68b8 100644
--- a/udev/lib/libudev-device.c
+++ b/udev/lib/libudev-device.c
@@ -42,6 +42,7 @@ struct udev_device {
char *devnode;
char *subsystem;
struct udev_list_node devlinks_list;
+ int devlinks_uptodate;
struct udev_list_node properties_list;
char *envp[128];
int envp_uptodate;
@@ -176,7 +177,7 @@ static int device_read_db(struct udev_device *udev_device)
return 0;
}
-static int device_read_uevent_file(struct udev_device *udev_device)
+int udev_device_read_uevent_file(struct udev_device *udev_device)
{
char filename[UTIL_PATH_SIZE];
FILE *f;
@@ -215,7 +216,7 @@ static int device_read_uevent_file(struct udev_device *udev_device)
static void device_load_info(struct udev_device *device)
{
device->info_loaded = 1;
- device_read_uevent_file(device);
+ udev_device_read_uevent_file(device);
device_read_db(device);
}
@@ -737,6 +738,7 @@ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *
void udev_device_cleanup_devlinks_list(struct udev_device *udev_device)
{
+ udev_device->devlinks_uptodate = 0;
udev_list_cleanup(udev_device->udev, &udev_device->devlinks_list);
}
@@ -758,6 +760,21 @@ struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device
return NULL;
if (!udev_device->info_loaded)
device_load_info(udev_device);
+ if (!udev_device->devlinks_uptodate) {
+ char symlinks[UTIL_PATH_SIZE];
+ struct udev_list_entry *list_entry;
+
+ udev_device->devlinks_uptodate = 1;
+ list_entry = udev_device_get_devlinks_list_entry(udev_device);
+ if (list_entry != NULL) {
+ util_strlcpy(symlinks, udev_list_entry_get_name(list_entry), sizeof(symlinks));
+ udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) {
+ util_strlcat(symlinks, " ", sizeof(symlinks));
+ util_strlcat(symlinks, udev_list_entry_get_name(list_entry), sizeof(symlinks));
+ }
+ udev_device_add_property(udev_device, "DEVLINKS", symlinks);
+ }
+ }
return udev_list_get_entry(&udev_device->properties_list);
}
@@ -929,6 +946,8 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode
{
free(udev_device->devnode);
udev_device->devnode = strdup(devnode);
+ if (devnode == NULL)
+ return 0;
if (udev_device->devnode == NULL)
return -ENOMEM;
udev_device_add_property(udev_device, "DEVNAME", udev_device->devnode);
@@ -937,18 +956,9 @@ int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode
int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink)
{
- char symlinks[UTIL_PATH_SIZE];
- struct udev_list_entry *list_entry;
-
+ udev_device->devlinks_uptodate = 0;
if (udev_list_entry_add(udev_device->udev, &udev_device->devlinks_list, devlink, NULL, 1, 0) == NULL)
return -ENOMEM;
- list_entry = udev_device_get_devlinks_list_entry(udev_device);
- util_strlcpy(symlinks, udev_list_entry_get_name(list_entry), sizeof(symlinks));
- udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry)) {
- util_strlcat(symlinks, " ", sizeof(symlinks));
- util_strlcat(symlinks, udev_list_entry_get_name(list_entry), sizeof(symlinks));
- }
- udev_device_add_property(udev_device, "DEVLINKS", symlinks);
return 0;
}
diff --git a/udev/lib/libudev-private.h b/udev/lib/libudev-private.h
index 97b0de950d..e9f2c9893b 100644
--- a/udev/lib/libudev-private.h
+++ b/udev/lib/libudev-private.h
@@ -60,6 +60,7 @@ extern void udev_device_cleanup_devlinks_list(struct udev_device *udev_device);
extern struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value);
extern struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property);
extern char **udev_device_get_properties_envp(struct udev_device *udev_device);
+extern int udev_device_read_uevent_file(struct udev_device *udev_device);
extern int udev_device_set_action(struct udev_device *udev_device, const char *action);
extern int udev_device_set_driver(struct udev_device *udev_device, const char *driver);
extern const char *udev_device_get_devpath_old(struct udev_device *udev_device);