]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
update-done: adjust comments
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Mar 2025 15:18:27 +0000 (16:18 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Mar 2025 13:36:20 +0000 (14:36 +0100)
The man page was right, but the comment in the generated file was wrong. The
timestamp is *not* the timestamp when the update is being done. While at it,
say to what directory the message applies. This makes it easier for a casual
reader to figure out what is happening.

Also rename the function to better reflect what it does.

Inspired by https://github.com/systemd/systemd/issues/36045.

man/systemd-update-done.service.xml
src/update-done/update-done.c

index 6b863ecff3a871722ec0b6aa9cec5f4f12d6acc3..fb228796885cfec0f63421abefe9896bfe4ab032 100644 (file)
     <filename>/etc/</filename> or <filename>/var/</filename> on the
     following boot.</para>
 
-    <para><filename>systemd-update-done.service</filename> updates the
-    file modification time (mtime) of the stamp files
-    <filename>/etc/.updated</filename> and
-    <filename>/var/.updated</filename> to the modification time of the
-    <filename>/usr/</filename> directory, unless the stamp files are
-    already newer.</para>
+    <para><filename>systemd-update-done.service</filename> updates the file modification time (mtime) stored
+    in and "on" the files <filename>/etc/.updated</filename> and <filename>/var/.updated</filename> to the
+    modification time of the <filename>/usr/</filename> directory, unless the stamp files are already newer.
+    (The timestamp is stored as the mtime field on the file, but also <emphasis>in</emphasis> the file
+    to support filesystems that do not store full timestamp precision.)</para>
 
     <para>Services that shall run after offline upgrades of
     <filename>/usr/</filename> should order themselves before
index 9eb58311e922f0b2d28d06eae29e3551f18a404e..15836971dfe96c329724a57fe8c86acf7c42a80b 100644 (file)
@@ -6,16 +6,12 @@
 
 #include "alloc-util.h"
 #include "fileio.h"
+#include "path-util.h"
 #include "selinux-util.h"
 #include "time-util.h"
 
-#define MESSAGE                                                         \
-        "# This file was created by systemd-update-done. Its only\n"    \
-        "# purpose is to hold a timestamp of the time this directory\n" \
-        "# was updated. See man:systemd-update-done.service(8).\n"
-
-static int apply_timestamp(const char *path, struct timespec *ts) {
-        _cleanup_free_ char *message = NULL;
+static int save_timestamp(const char *dir, struct timespec *ts) {
+        _cleanup_free_ char *message = NULL, *path = NULL;
         int r;
 
         /*
@@ -23,9 +19,16 @@ static int apply_timestamp(const char *path, struct timespec *ts) {
          * to support filesystems which cannot store nanosecond-precision timestamps.
          */
 
+        path = path_join(dir, ".updated");
+        if (!path)
+                return log_oom();
+
         if (asprintf(&message,
-                     MESSAGE
+                     "# This file was created by systemd-update-done. The timestamp below is the\n"
+                     "# modification time of /usr/ for which the most recent updates of %s have\n"
+                     "# been applied. See man:systemd-update-done.service(8) for details.\n"
                      "TIMESTAMP_NSEC=" NSEC_FMT "\n",
+                     dir,
                      timespec_load_nsec(ts)) < 0)
                 return log_oom();
 
@@ -52,8 +55,8 @@ int main(int argc, char *argv[]) {
         if (r < 0)
                 return EXIT_FAILURE;
 
-        r = apply_timestamp("/etc/.updated", &st.st_mtim);
-        q = apply_timestamp("/var/.updated", &st.st_mtim);
+        r = save_timestamp("/etc/", &st.st_mtim);
+        q = save_timestamp("/var/", &st.st_mtim);
 
         return r < 0 || q < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }