From 38b9b72ec10fa8875b1b7c93bc7ca6b8a2d5486e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 26 Oct 2017 16:41:06 +0200 Subject: [PATCH] core: remove SYSTEMD_WANTS udev property configured dependencies at the right moment Previously dependencies configured with SYSTEMD_WANTS would be collected on a device unit as long as it was loaded. let's fix that, and remove dependencies again when SYTEMD_WANTS changes. --- src/core/device.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/core/device.c b/src/core/device.c index 5652926..bfab494 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -349,23 +349,26 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa return log_error_errno(r, "Failed to generate unit name from device path: %m"); u = manager_get_unit(m, e); - - /* The device unit can still be present even if the device was - * unplugged: a mount unit can reference it hence preventing - * the GC to have garbaged it. That's desired since the device - * unit may have a dependency on the mount unit which was - * added during the loading of the later. */ - if (dev && u && DEVICE(u)->state == DEVICE_PLUGGED) { - /* This unit is in plugged state: we're sure it's - * attached to a device. */ - if (!path_equal(DEVICE(u)->sysfs, sysfs)) { - log_unit_debug(u, "Dev %s appeared twice with different sysfs paths %s and %s", - e, DEVICE(u)->sysfs, sysfs); - return -EEXIST; + if (u) { + /* The device unit can still be present even if the device was unplugged: a mount unit can reference it hence + * preventing the GC to have garbaged it. That's desired since the device unit may have a dependency on the + * mount unit which was added during the loading of the later. */ + if (dev && DEVICE(u)->state == DEVICE_PLUGGED) { + + /* This unit is in plugged state: we're sure it's attached to a device. */ + if (!path_equal(DEVICE(u)->sysfs, sysfs)) { + log_unit_debug(u, "Dev %s appeared twice with different sysfs paths %s and %s", + e, DEVICE(u)->sysfs, sysfs); + return -EEXIST; + } } - } - if (!u) { + delete = false; + + /* Let's remove all dependencies generated due to udev properties. We'll readd whatever is configured + * now below. */ + unit_remove_dependencies(u, UNIT_DEPENDENCY_UDEV); + } else { delete = true; r = unit_new_for_name(m, sizeof(Device), e, &u); @@ -373,8 +376,7 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa goto fail; unit_add_to_load_queue(u); - } else - delete = false; + } /* If this was created via some dependency and has not * actually been seen yet ->sysfs will not be @@ -398,8 +400,7 @@ static int device_setup_unit(Manager *m, struct udev_device *dev, const char *pa if (dev && device_is_bound_by_mounts(DEVICE(u), dev)) device_upgrade_mount_deps(u); - /* Note that this won't dispatch the load queue, the caller - * has to do that if needed and appropriate */ + /* Note that this won't dispatch the load queue, the caller has to do that if needed and appropriate */ unit_add_to_dbus_queue(u); return 0; -- 2.7.4