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