summaryrefslogtreecommitdiff
path: root/src/timedate/timedated.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-11-13 10:32:44 +0100
committerLennart Poettering <lennart@poettering.net>2019-11-13 10:39:14 +0100
commit9193af0f059538f4e5ca06502a998e9cc02819a1 (patch)
tree500759d8bebadc7ccdb441445777bdfe432e32d3 /src/timedate/timedated.c
parentbc9ecd484f1ebfe0de8b567c90f6cd867fbd5894 (diff)
downloadsystemd-9193af0f059538f4e5ca06502a998e9cc02819a1.tar.gz
timedated: handle UTC specially, when generating /etc/localtime
Diffstat (limited to 'src/timedate/timedated.c')
-rw-r--r--src/timedate/timedated.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 97a0868bc1..eb585b86c3 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -277,20 +277,35 @@ static int context_read_data(Context *c) {
static int context_write_data_timezone(Context *c) {
_cleanup_free_ char *p = NULL;
+ const char *source;
assert(c);
- if (isempty(c->zone)) {
- if (unlink("/etc/localtime") < 0 && errno != ENOENT)
- return -errno;
- return 0;
- }
+ /* No timezone is very similar to UTC. Hence in either of these cases link the UTC file in. Except if
+ * it isn't installed, in which case we remove the symlink altogether. Since glibc defaults to an
+ * internal version of UTC in that case behaviour is mostly equivalent. We still prefer creating the
+ * symlink though, since things are more self explanatory then. */
- p = path_join("../usr/share/zoneinfo", c->zone);
- if (!p)
- return log_oom();
+ if (isempty(c->zone) || streq(c->zone, "UTC")) {
+
+ if (access("/usr/share/zoneinfo/UTC", F_OK) < 0) {
+
+ if (unlink("/etc/localtime") < 0 && errno != ENOENT)
+ return -errno;
+
+ return 0;
+ }
+
+ source = "../usr/share/zoneinfo/UTC";
+ } else {
+ p = path_join("../usr/share/zoneinfo", c->zone);
+ if (!p)
+ return -ENOMEM;
+
+ source = p;
+ }
- return symlink_atomic(p, "/etc/localtime");
+ return symlink_atomic(source, "/etc/localtime");
}
static int context_write_data_local_rtc(Context *c) {