mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
use the event udev_device to disable the watch on "remove"
This commit is contained in:
parent
d5d04d4f9f
commit
3d3a0a709a
@ -15,7 +15,7 @@ test "$prefix" = NONE && test "$exec_prefix" = NONE && exec_prefix=
|
||||
|
||||
dnl /* libudev version */
|
||||
LIBUDEV_LT_CURRENT=0
|
||||
LIBUDEV_LT_REVISION=8
|
||||
LIBUDEV_LT_REVISION=9
|
||||
LIBUDEV_LT_AGE=0
|
||||
AC_SUBST(LIBUDEV_LT_CURRENT)
|
||||
AC_SUBST(LIBUDEV_LT_REVISION)
|
||||
|
@ -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];
|
||||
|
||||
|
@ -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)
|
||||
|
16
udev/udevd.c
16
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();
|
||||
|
Loading…
Reference in New Issue
Block a user