From c7a4216509e34be5169d45e6c047ee1c42fc8758 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 28 Feb 2025 16:53:58 +0100 Subject: [PATCH] homed: re-establish inotify watches on SIGUSR1 Let's define a clean way how we can reestablish file watches in homed. This is a relevant in case we overmount /home/ as a whole. It's very useful for our testcase in particular. --- man/systemd-homed.service.xml | 16 ++++++++++++++++ src/home/homed-manager.c | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/man/systemd-homed.service.xml b/man/systemd-homed.service.xml index 42e5780cccc..ca96e5d1962 100644 --- a/man/systemd-homed.service.xml +++ b/man/systemd-homed.service.xml @@ -107,6 +107,22 @@ generated/signed before the key pair is copied in, lose their validity. + + Signals + + + + SIGUSR1 + + Upon reception of the SIGUSR1 process signal + systemd-homed will reestablish its file watches on /home/ and + rescan the directory for home directories. + + + + + + See Also diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index f5868a2d6fe..5ce0fc33007 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -201,6 +201,20 @@ static int on_home_inotify(sd_event_source *s, const struct inotify_event *event return 0; } +static int sigusr1_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) { + Manager *m = ASSERT_PTR(userdata); + assert(s); + + /* If clients send use SIGUSR1 we'll explicitly rescan for home directories. This is useful in some + * cases where inotify isn't good enough, for example if /home/ is overmunted. */ + manager_watch_home(m); + (void) manager_gc_images(m); + (void) manager_enumerate_images(m); + (void) bus_manager_emit_auto_login_changed(m); + + return 0; +} + int manager_new(Manager **ret) { _cleanup_(manager_freep) Manager *m = NULL; int r; @@ -237,6 +251,10 @@ int manager_new(Manager **ret) { if (r < 0) return r; + r = sd_event_add_signal(m->event, /* ret_event_source= */ NULL, SIGUSR1|SD_EVENT_SIGNAL_PROCMASK, sigusr1_handler, m); + if (r < 0) + return r; + (void) sd_event_set_watchdog(m->event, true); m->homes_by_uid = hashmap_new(&homes_by_uid_hash_ops); -- 2.47.3