timedated: handle UTC specially, when generating /etc/localtime

This commit is contained in:
Lennart Poettering 2019-11-13 10:32:44 +01:00
parent bc9ecd484f
commit 9193af0f05

View file

@ -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. */
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;
}
p = path_join("../usr/share/zoneinfo", c->zone);
if (!p)
return log_oom();
return symlink_atomic(p, "/etc/localtime");
return symlink_atomic(source, "/etc/localtime");
}
static int context_write_data_local_rtc(Context *c) {