]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/update-done/update-done.c
Merge pull request #8417 from brauner/2018-03-09/add_bind_mount_fallback_to_private_d...
[thirdparty/systemd.git] / src / update-done / update-done.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
8ea48dfc
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2014 Lennart Poettering
8ea48dfc
LP
6***/
7
5a1d6763 8#include "alloc-util.h"
872c4039 9#include "fileio-label.h"
d7b8eec7 10#include "selinux-util.h"
3ffd4af2 11#include "util.h"
8ea48dfc 12
4aa4d2ae 13#define MESSAGE \
fb8b0869
IS
14 "# This file was created by systemd-update-done. Its only \n" \
15 "# purpose is to hold a timestamp of the time this directory\n" \
cc7de2ba 16 "# was updated. See man:systemd-update-done.service(8).\n"
4aa4d2ae 17
8ea48dfc 18static int apply_timestamp(const char *path, struct timespec *ts) {
872c4039 19 _cleanup_free_ char *message = NULL;
fb8b0869 20 int r;
8ea48dfc 21
fb8b0869
IS
22 /*
23 * We store the timestamp both as mtime of the file and in the file itself,
24 * to support filesystems which cannot store nanosecond-precision timestamps.
fb8b0869 25 */
8ea48dfc 26
872c4039
ZJS
27 if (asprintf(&message,
28 MESSAGE
29 "TIMESTAMP_NSEC=" NSEC_FMT "\n",
30 timespec_load_nsec(ts)) < 0)
31 return log_oom();
8ea48dfc 32
872c4039
ZJS
33 r = write_string_file_atomic_label_ts(path, message, ts);
34 if (r == -EROFS)
35 return log_debug("Cannot create \"%s\", file system is read-only.", path);
ec2ebfd5 36 if (r < 0)
872c4039 37 return log_error_errno(r, "Failed to write \"%s\": %m", path);
8ea48dfc
LP
38 return 0;
39}
40
41int main(int argc, char *argv[]) {
42 struct stat st;
7dbb1d08 43 int r, q = 0;
8ea48dfc
LP
44
45 log_set_target(LOG_TARGET_AUTO);
46 log_parse_environment();
47 log_open();
48
49 if (stat("/usr", &st) < 0) {
755bde37 50 log_error_errno(errno, "Failed to stat /usr: %m");
8ea48dfc
LP
51 return EXIT_FAILURE;
52 }
53
c3dacc8b 54 r = mac_selinux_init();
7dbb1d08 55 if (r < 0) {
da927ba9 56 log_error_errno(r, "SELinux setup failed: %m");
7dbb1d08
ZJS
57 goto finish;
58 }
8ea48dfc 59
7dbb1d08 60 r = apply_timestamp("/etc/.updated", &st.st_mtim);
8ea48dfc 61 q = apply_timestamp("/var/.updated", &st.st_mtim);
8ea48dfc 62
7dbb1d08
ZJS
63finish:
64 return r < 0 || q < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
8ea48dfc 65}