]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/update-done/update-done.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "alloc-util.h"
8 #include "fileio-label.h"
9 #include "selinux-util.h"
10 #include "time-util.h"
13 "# This file was created by systemd-update-done. Its only \n" \
14 "# purpose is to hold a timestamp of the time this directory\n" \
15 "# was updated. See man:systemd-update-done.service(8).\n"
17 static int apply_timestamp(const char *path
, struct timespec
*ts
) {
18 _cleanup_free_
char *message
= NULL
;
22 * We store the timestamp both as mtime of the file and in the file itself,
23 * to support filesystems which cannot store nanosecond-precision timestamps.
26 if (asprintf(&message
,
28 "TIMESTAMP_NSEC=" NSEC_FMT
"\n",
29 timespec_load_nsec(ts
)) < 0)
32 r
= write_string_file_atomic_label_ts(path
, message
, ts
);
34 return log_debug("Cannot create \"%s\", file system is read-only.", path
);
36 return log_error_errno(r
, "Failed to write \"%s\": %m", path
);
40 int main(int argc
, char *argv
[]) {
46 if (stat("/usr", &st
) < 0) {
47 log_error_errno(errno
, "Failed to stat /usr: %m");
51 r
= mac_selinux_init();
55 r
= apply_timestamp("/etc/.updated", &st
.st_mtim
);
56 q
= apply_timestamp("/var/.updated", &st
.st_mtim
);
58 return r
< 0 || q
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;