]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
8ea48dfc LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2014 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
5a1d6763 | 21 | #include "alloc-util.h" |
872c4039 | 22 | #include "fileio-label.h" |
d7b8eec7 | 23 | #include "selinux-util.h" |
3ffd4af2 | 24 | #include "util.h" |
8ea48dfc | 25 | |
4aa4d2ae | 26 | #define MESSAGE \ |
fb8b0869 IS |
27 | "# This file was created by systemd-update-done. Its only \n" \ |
28 | "# purpose is to hold a timestamp of the time this directory\n" \ | |
cc7de2ba | 29 | "# was updated. See man:systemd-update-done.service(8).\n" |
4aa4d2ae | 30 | |
8ea48dfc | 31 | static int apply_timestamp(const char *path, struct timespec *ts) { |
872c4039 | 32 | _cleanup_free_ char *message = NULL; |
fb8b0869 | 33 | int r; |
8ea48dfc | 34 | |
fb8b0869 IS |
35 | /* |
36 | * We store the timestamp both as mtime of the file and in the file itself, | |
37 | * to support filesystems which cannot store nanosecond-precision timestamps. | |
fb8b0869 | 38 | */ |
8ea48dfc | 39 | |
872c4039 ZJS |
40 | if (asprintf(&message, |
41 | MESSAGE | |
42 | "TIMESTAMP_NSEC=" NSEC_FMT "\n", | |
43 | timespec_load_nsec(ts)) < 0) | |
44 | return log_oom(); | |
8ea48dfc | 45 | |
872c4039 ZJS |
46 | r = write_string_file_atomic_label_ts(path, message, ts); |
47 | if (r == -EROFS) | |
48 | return log_debug("Cannot create \"%s\", file system is read-only.", path); | |
ec2ebfd5 | 49 | if (r < 0) |
872c4039 | 50 | return log_error_errno(r, "Failed to write \"%s\": %m", path); |
8ea48dfc LP |
51 | return 0; |
52 | } | |
53 | ||
54 | int main(int argc, char *argv[]) { | |
55 | struct stat st; | |
7dbb1d08 | 56 | int r, q = 0; |
8ea48dfc LP |
57 | |
58 | log_set_target(LOG_TARGET_AUTO); | |
59 | log_parse_environment(); | |
60 | log_open(); | |
61 | ||
62 | if (stat("/usr", &st) < 0) { | |
755bde37 | 63 | log_error_errno(errno, "Failed to stat /usr: %m"); |
8ea48dfc LP |
64 | return EXIT_FAILURE; |
65 | } | |
66 | ||
c3dacc8b | 67 | r = mac_selinux_init(); |
7dbb1d08 | 68 | if (r < 0) { |
da927ba9 | 69 | log_error_errno(r, "SELinux setup failed: %m"); |
7dbb1d08 ZJS |
70 | goto finish; |
71 | } | |
8ea48dfc | 72 | |
7dbb1d08 | 73 | r = apply_timestamp("/etc/.updated", &st.st_mtim); |
8ea48dfc | 74 | q = apply_timestamp("/var/.updated", &st.st_mtim); |
8ea48dfc | 75 | |
7dbb1d08 ZJS |
76 | finish: |
77 | return r < 0 || q < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |
8ea48dfc | 78 | } |