]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
8ea48dfc | 2 | |
ca78ad1d ZJS |
3 | #include <sys/stat.h> |
4 | #include <sys/types.h> | |
5 | #include <unistd.h> | |
6 | ||
5a1d6763 | 7 | #include "alloc-util.h" |
872c4039 | 8 | #include "fileio-label.h" |
d7b8eec7 | 9 | #include "selinux-util.h" |
ca78ad1d | 10 | #include "time-util.h" |
8ea48dfc | 11 | |
4aa4d2ae | 12 | #define MESSAGE \ |
fb8b0869 IS |
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" \ | |
cc7de2ba | 15 | "# was updated. See man:systemd-update-done.service(8).\n" |
4aa4d2ae | 16 | |
8ea48dfc | 17 | static int apply_timestamp(const char *path, struct timespec *ts) { |
872c4039 | 18 | _cleanup_free_ char *message = NULL; |
fb8b0869 | 19 | int r; |
8ea48dfc | 20 | |
fb8b0869 IS |
21 | /* |
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. | |
fb8b0869 | 24 | */ |
8ea48dfc | 25 | |
872c4039 ZJS |
26 | if (asprintf(&message, |
27 | MESSAGE | |
28 | "TIMESTAMP_NSEC=" NSEC_FMT "\n", | |
29 | timespec_load_nsec(ts)) < 0) | |
30 | return log_oom(); | |
8ea48dfc | 31 | |
872c4039 ZJS |
32 | r = write_string_file_atomic_label_ts(path, message, ts); |
33 | if (r == -EROFS) | |
34 | return log_debug("Cannot create \"%s\", file system is read-only.", path); | |
ec2ebfd5 | 35 | if (r < 0) |
872c4039 | 36 | return log_error_errno(r, "Failed to write \"%s\": %m", path); |
8ea48dfc LP |
37 | return 0; |
38 | } | |
39 | ||
40 | int main(int argc, char *argv[]) { | |
41 | struct stat st; | |
7dbb1d08 | 42 | int r, q = 0; |
8ea48dfc | 43 | |
6bf3c61c | 44 | log_setup_service(); |
8ea48dfc LP |
45 | |
46 | if (stat("/usr", &st) < 0) { | |
755bde37 | 47 | log_error_errno(errno, "Failed to stat /usr: %m"); |
8ea48dfc LP |
48 | return EXIT_FAILURE; |
49 | } | |
50 | ||
c3dacc8b | 51 | r = mac_selinux_init(); |
7dbb1d08 | 52 | if (r < 0) { |
da927ba9 | 53 | log_error_errno(r, "SELinux setup failed: %m"); |
fd1bff7d | 54 | return EXIT_FAILURE; |
7dbb1d08 | 55 | } |
8ea48dfc | 56 | |
7dbb1d08 | 57 | r = apply_timestamp("/etc/.updated", &st.st_mtim); |
8ea48dfc | 58 | q = apply_timestamp("/var/.updated", &st.st_mtim); |
8ea48dfc | 59 | |
7dbb1d08 | 60 | return r < 0 || q < 0 ? EXIT_FAILURE : EXIT_SUCCESS; |
8ea48dfc | 61 | } |