]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
homed: re-establish inotify watches on SIGUSR1
authorLennart Poettering <lennart@poettering.net>
Fri, 28 Feb 2025 15:53:58 +0000 (16:53 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 Mar 2025 17:15:01 +0000 (18:15 +0100)
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
src/home/homed-manager.c

index 42e5780cccc4f478d6dc520f6a4f72cc4e60277a..ca96e5d1962993418e78777ad13f12b91914fa4d 100644 (file)
     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">
index f5868a2d6feb44adc1e95cfe2058ebd175f3ed80..5ce0fc330077c2970cd04aaa8819fc220274191c 100644 (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);