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