From 04db1a6aecb55f34fb0558264baf0051eabbc7ac Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 19 Mar 2025 16:18:27 +0100 Subject: [PATCH] update-done: adjust comments 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 | 11 +++++------ src/update-done/update-done.c | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/man/systemd-update-done.service.xml b/man/systemd-update-done.service.xml index 6b863ecff3a..fb228796885 100644 --- a/man/systemd-update-done.service.xml +++ b/man/systemd-update-done.service.xml @@ -37,12 +37,11 @@ /etc/ or /var/ on the following boot. - systemd-update-done.service updates the - file modification time (mtime) of the stamp files - /etc/.updated and - /var/.updated to the modification time of the - /usr/ directory, unless the stamp files are - already newer. + systemd-update-done.service updates the file modification time (mtime) stored + in and "on" the files /etc/.updated and /var/.updated to the + modification time of the /usr/ directory, unless the stamp files are already newer. + (The timestamp is stored as the mtime field on the file, but also in the file + to support filesystems that do not store full timestamp precision.) Services that shall run after offline upgrades of /usr/ should order themselves before diff --git a/src/update-done/update-done.c b/src/update-done/update-done.c index 9eb58311e92..15836971dfe 100644 --- a/src/update-done/update-done.c +++ b/src/update-done/update-done.c @@ -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; } -- 2.47.3