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");
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) {
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 */
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;
}
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];
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));
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)
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);
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)
/* 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);
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();