diff options
-rw-r--r-- | udev/lib/libudev-device.c | 22 | ||||
-rw-r--r-- | udev/lib/libudev-private.h | 2 | ||||
-rw-r--r-- | udev/udev-event.c | 26 | ||||
-rw-r--r-- | udev/udev-node.c | 14 |
4 files changed, 31 insertions, 33 deletions
diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c index eda3f5d97e..38af0e7c94 100644 --- a/udev/lib/libudev-device.c +++ b/udev/lib/libudev-device.c @@ -77,7 +77,7 @@ static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *f return util_path_encode(&filename[start], len - start); } -int udev_device_read_db(struct udev_device *udev_device) +static int device_read_db(struct udev_device *udev_device) { struct stat stats; char filename[UTIL_PATH_SIZE]; @@ -218,11 +218,11 @@ int udev_device_read_uevent_file(struct udev_device *udev_device) return 0; } -static void device_load_info(struct udev_device *device) +void udev_device_load_info(struct udev_device *device) { device->info_loaded = 1; udev_device_read_uevent_file(device); - udev_device_read_db(device); + device_read_db(device); } void udev_device_set_info_loaded(struct udev_device *device) @@ -676,7 +676,7 @@ const char *udev_device_get_devnode(struct udev_device *udev_device) if (udev_device == NULL) return NULL; if (!udev_device->info_loaded) - device_load_info(udev_device); + udev_device_load_info(udev_device); return udev_device->devnode; } @@ -739,7 +739,7 @@ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device * if (udev_device == NULL) return NULL; if (!udev_device->info_loaded) - device_load_info(udev_device); + udev_device_load_info(udev_device); return udev_list_get_entry(&udev_device->devlinks_list); } @@ -766,7 +766,7 @@ struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device if (udev_device == NULL) return NULL; if (!udev_device->info_loaded) - device_load_info(udev_device); + udev_device_load_info(udev_device); if (!udev_device->devlinks_uptodate) { char symlinks[UTIL_PATH_SIZE]; struct udev_list_entry *list_entry; @@ -804,7 +804,7 @@ dev_t udev_device_get_devnum(struct udev_device *udev_device) if (udev_device == NULL) return makedev(0, 0); if (!udev_device->info_loaded) - device_load_info(udev_device); + udev_device_load_info(udev_device); return udev_device->devnum; } @@ -1154,7 +1154,7 @@ int udev_device_set_timeout(struct udev_device *udev_device, int timeout) int udev_device_get_event_timeout(struct udev_device *udev_device) { if (!udev_device->info_loaded) - device_load_info(udev_device); + udev_device_load_info(udev_device); return udev_device->event_timeout; } @@ -1190,7 +1190,7 @@ int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum) int udev_device_get_num_fake_partitions(struct udev_device *udev_device) { if (!udev_device->info_loaded) - device_load_info(udev_device); + udev_device_load_info(udev_device); return udev_device->num_fake_partitions; } @@ -1203,7 +1203,7 @@ int udev_device_set_num_fake_partitions(struct udev_device *udev_device, int num int udev_device_get_devlink_priority(struct udev_device *udev_device) { if (!udev_device->info_loaded) - device_load_info(udev_device); + udev_device_load_info(udev_device); return udev_device->devlink_priority; } @@ -1216,7 +1216,7 @@ int udev_device_set_devlink_priority(struct udev_device *udev_device, int prio) int udev_device_get_ignore_remove(struct udev_device *udev_device) { if (!udev_device->info_loaded) - device_load_info(udev_device); + udev_device_load_info(udev_device); return udev_device->ignore_remove; } diff --git a/udev/lib/libudev-private.h b/udev/lib/libudev-private.h index 2f8b8259b5..5d6b94bf5b 100644 --- a/udev/lib/libudev-private.h +++ b/udev/lib/libudev-private.h @@ -63,7 +63,7 @@ extern struct udev_list_entry *udev_device_add_property(struct udev_device *udev 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 ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf); -extern int udev_device_read_db(struct udev_device *udev_device); +extern void udev_device_load_info(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); diff --git a/udev/udev-event.c b/udev/udev-event.c index db61d58925..1c640cf37d 100644 --- a/udev/udev-event.c +++ b/udev/udev-event.c @@ -583,23 +583,20 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules) util_strlcat(filename, event->name, sizeof(filename)); udev_device_set_devnode(dev, filename); - /* read current database entry; cleanup, if it is known device */ + /* read current database entry */ dev_old = udev_device_new_from_syspath(event->udev, udev_device_get_syspath(dev)); - if (dev_old != NULL) { - if (udev_device_get_devnode(dev_old) != NULL) { - info(event->udev, "device node '%s' already in database, updating\n", - udev_device_get_devnode(dev_old)); - udev_node_update_old_links(dev, dev_old, event->test); - } - udev_device_unref(dev_old); - } + if (dev_old != NULL) + udev_device_load_info(dev_old); + /* update database, create node and symlinks */ udev_device_update_db(dev); - err = udev_node_add(dev, event->mode, event->uid, event->gid, event->test); - if (err != 0) - goto exit; + /* remove/update possible left-over symlinks from old database entry */ + if (dev_old != NULL) { + udev_node_update_old_links(dev, dev_old, event->test); + udev_device_unref(dev_old); + } goto exit; } @@ -645,9 +642,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules) /* remove device node */ if (major(udev_device_get_devnum(dev)) != 0 && strcmp(udev_device_get_action(dev), "remove") == 0) { /* import database entry and delete it */ - udev_device_read_db(dev); - if (!event->test) - udev_device_delete_db(dev); + udev_device_load_info(dev); + udev_device_delete_db(dev); if (udev_device_get_devnode(dev) == NULL) { char devnode[UTIL_PATH_SIZE]; diff --git a/udev/udev-node.c b/udev/udev-node.c index ae343eb2da..1a189c5aae 100644 --- a/udev/udev-node.c +++ b/udev/udev-node.c @@ -367,13 +367,15 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev /* update possible left-over symlinks */ udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev_old)) { + const char *name = udev_list_entry_get_name(list_entry); struct udev_list_entry *list_entry_current; int found; found = 0; udev_list_entry_foreach(list_entry_current, udev_device_get_devlinks_list_entry(dev)) { - if (strcmp(udev_list_entry_get_name(list_entry_current), - udev_list_entry_get_name(list_entry)) == 0) { + const char *name_current = udev_list_entry_get_name(list_entry_current); + + if (strcmp(name_current, name) == 0) { found = 1; break; } @@ -381,9 +383,9 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev if (found) continue; /* link does no longer belong to this device */ - info(udev, "update old symlink '%s' no longer belonging to '%s'\n", - udev_list_entry_get_name(list_entry), udev_device_get_devpath(dev)); - update_link(dev, udev_list_entry_get_name(list_entry), test); + info(udev, "update old symlink '%s' no longer belonging to '%s'\n", name, udev_device_get_devpath(dev)); + name_index(udev, udev_device_get_devpath(dev), name, 0, test); + update_link(dev, name, test); } /* @@ -438,7 +440,7 @@ int udev_node_add(struct udev_device *dev, mode_t mode, uid_t uid, gid_t gid, in } } - /* add node and to name index */ + /* add node to name index */ name_index(udev, udev_device_get_devpath(dev), udev_device_get_devnode(dev), 1, test); /* create/update symlinks, add symlinks to name index */ |