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.
This commit is contained in:
Lennart Poettering
2025-02-28 16:53:58 +01:00
parent c3f54fcd3b
commit c7a4216509
2 changed files with 34 additions and 0 deletions

View File

@@ -107,6 +107,22 @@
generated/signed before the key pair is copied in, lose their validity.</para>
</refsect1>
<refsect1>
<title>Signals</title>
<variablelist>
<varlistentry>
<term><constant>SIGUSR1</constant></term>
<listitem><para>Upon reception of the <constant>SIGUSR1</constant> process signal
<command>systemd-homed</command> will reestablish its file watches on <filename>/home/</filename> and
rescan the directory for home directories.</para>
<xi:include href="version-info.xml" xpointer="v258"/></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>See Also</title>
<para><simplelist type="inline">

View File

@@ -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);