summaryrefslogtreecommitdiff
path: root/udev
diff options
context:
space:
mode:
Diffstat (limited to 'udev')
-rw-r--r--udev/udev-event.c32
-rw-r--r--udev/udev-watch.c6
-rw-r--r--udev/udevd.c16
3 files changed, 24 insertions, 30 deletions
diff --git a/udev/udev-event.c b/udev/udev-event.c
index e34f09cfe3..f4d7121793 100644
--- a/udev/udev-event.c
+++ b/udev/udev-event.c
@@ -550,6 +550,16 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
dbg(event->udev, "device node add '%s'\n", udev_device_get_devpath(dev));
+ /* read old database entry */
+ dev_old = udev_device_new_from_syspath(event->udev, udev_device_get_syspath(dev));
+ if (dev_old != NULL) {
+ udev_device_read_db(dev_old);
+ udev_device_set_info_loaded(dev_old);
+
+ /* disable watch during event processing */
+ udev_watch_end(event->udev, dev_old);
+ }
+
udev_rules_apply_to_event(rules, event);
if (event->tmp_node != NULL) {
dbg(event->udev, "removing temporary device node\n");
@@ -560,12 +570,12 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
if (event->ignore_device) {
info(event->udev, "device event will be ignored\n");
- goto exit;
+ goto exit_add;
}
if (event->name != NULL && event->name[0] == '\0') {
info(event->udev, "device node creation supressed\n");
- goto exit;
+ goto exit_add;
}
if (event->name == NULL) {
@@ -573,7 +583,7 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
udev_device_get_sysname(event->dev));
event->name = strdup(udev_device_get_sysname(event->dev));
if (event->name == NULL)
- goto exit;
+ goto exit_add;
}
/* set device node name */
@@ -582,24 +592,17 @@ 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 old database entry */
- dev_old = udev_device_new_from_syspath(event->udev, udev_device_get_syspath(dev));
- if (dev_old != NULL) {
- udev_device_read_db(dev_old);
- udev_device_set_info_loaded(dev_old);
- }
-
/* write current database entry */
udev_device_update_db(dev);
/* remove/update possible left-over symlinks from old database entry */
- if (dev_old != NULL) {
+ if (dev_old != NULL)
udev_node_update_old_links(dev, dev_old);
- udev_device_unref(dev_old);
- }
/* create new node and symlinks */
err = udev_node_add(dev, event->mode, event->uid, event->gid);
+exit_add:
+ udev_device_unref(dev_old);
goto exit;
}
@@ -651,6 +654,9 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules)
udev_device_set_info_loaded(dev);
udev_device_delete_db(dev);
+ /* remove watch */
+ udev_watch_end(event->udev, dev);
+
if (udev_device_get_devnode(dev) == NULL) {
char devnode[UTIL_PATH_SIZE];
diff --git a/udev/udev-watch.c b/udev/udev-watch.c
index a581f02cb5..dff3de1cb4 100644
--- a/udev/udev-watch.c
+++ b/udev/udev-watch.c
@@ -129,7 +129,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev)
char filename[UTIL_PATH_SIZE];
int wd;
- if (inotify_fd < 0 || major(udev_device_get_devnum(dev)) == 0)
+ if (inotify_fd < 0)
return;
info(udev, "adding watch on '%s'\n", udev_device_get_devnode(dev));
@@ -145,7 +145,6 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev)
symlink(udev_device_get_syspath(dev), filename);
udev_device_set_watch_handle(dev, wd);
- udev_device_update_db(dev);
}
void udev_watch_end(struct udev *udev, struct udev_device *dev)
@@ -153,7 +152,7 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev)
int wd;
char filename[UTIL_PATH_SIZE];
- if (inotify_fd < 0 || major(udev_device_get_devnum(dev)) == 0)
+ if (inotify_fd < 0)
return;
wd = udev_device_get_watch_handle(dev);
@@ -167,7 +166,6 @@ void udev_watch_end(struct udev *udev, struct udev_device *dev)
unlink(filename);
udev_device_set_watch_handle(dev, -1);
- udev_device_update_db(dev);
}
struct udev_device *udev_watch_lookup(struct udev *udev, int wd)
diff --git a/udev/udevd.c b/udev/udevd.c
index cfc091b699..ee3d6f5033 100644
--- a/udev/udevd.c
+++ b/udev/udevd.c
@@ -215,17 +215,6 @@ static void event_fork(struct udev_event *event)
/* set timeout to prevent hanging processes */
alarm(UDEV_EVENT_TIMEOUT);
- /* clear any existing udev watch on the node */
- if (inotify_fd != -1) {
- struct udev_device *dev_old;
-
- dev_old = udev_device_new_from_syspath(event->udev, udev_device_get_syspath(event->dev));
- if (dev_old != NULL) {
- udev_watch_end(event->udev, dev_old);
- udev_device_unref(dev_old);
- }
- }
-
/* apply rules, create node, symlinks */
err = udev_event_execute_rules(event, rules);
@@ -238,9 +227,10 @@ static void event_fork(struct udev_event *event)
udev_event_execute_run(event);
/* apply/restore inotify watch */
- if (err == 0 && event->inotify_watch &&
- strcmp(udev_device_get_action(event->dev), "remove") != 0)
+ if (err == 0 && event->inotify_watch) {
udev_watch_begin(event->udev, event->dev);
+ udev_device_update_db(event->dev);
+ }
info(event->udev, "seq %llu exit with %i\n", udev_device_get_seqnum(event->dev), err);
logging_close();