diff --git a/man/systemd.device.xml b/man/systemd.device.xml index effed098dd..d156095526 100644 --- a/man/systemd.device.xml +++ b/man/systemd.device.xml @@ -83,6 +83,12 @@ the escaping logic used to convert a file system path to a unit name see systemd.unit5. + + Device units will be reloaded by systemd whenever the + corresponding device generates a changed event. + Other units can use ReloadPropagatedFrom= to react + to that event + diff --git a/src/core/device.c b/src/core/device.c index 87186f135b..5366ba050f 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -766,7 +766,27 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents, return 0; } - if (streq(action, "remove")) { + if (streq(action, "change")) { + _cleanup_free_ char *e = NULL; + Unit *u; + + r = unit_name_from_path(sysfs, ".device", &e); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name from device path: %m"); + + u = manager_get_unit(m, e); + if (!u) { + log_error("Failed to get unit from sysfs name."); + return 0; + } + + r = manager_add_job(m, JOB_RELOAD, u, JOB_REPLACE, NULL, NULL); + if (r < 0) { + log_error_errno(r, "Failed to add job to manager : %m"); + return 0; + } + + } else if (streq(action, "remove")) { r = swap_process_device_remove(m, dev); if (r < 0) log_error_errno(r, "Failed to process swap device remove event: %m"); diff --git a/src/core/unit.c b/src/core/unit.c index 2037de6d33..9eda9643f6 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1759,19 +1759,25 @@ int unit_reload(Unit *u) { unit_add_to_dbus_queue(u); + if (!UNIT_VTABLE(u)->reload) { + /* Unit doesn't have a reload function, but we need to propagate the reload anyway */ + unit_notify(u, unit_active_state(u), unit_active_state(u), true); + return 0; + } + return UNIT_VTABLE(u)->reload(u); } bool unit_can_reload(Unit *u) { assert(u); - if (!UNIT_VTABLE(u)->reload) - return false; + if (UNIT_VTABLE(u)->can_reload) + return UNIT_VTABLE(u)->can_reload(u); - if (!UNIT_VTABLE(u)->can_reload) + if (!set_isempty(u->dependencies[UNIT_PROPAGATES_RELOAD_TO])) return true; - return UNIT_VTABLE(u)->can_reload(u); + return UNIT_VTABLE(u)->reload; } static void unit_check_unneeded(Unit *u) {