summaryrefslogtreecommitdiff
path: root/src/timedate
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-11-13 16:38:41 +0100
committerGitHub <noreply@github.com>2019-11-13 16:38:41 +0100
commita650e19820b85e7b82a87508a7f80ce764f2f1a0 (patch)
tree7d0ebd39a79258a684418a689c28ac187161fbe7 /src/timedate
parentc214e210c934d331afb6dccdf478c5dd155501b5 (diff)
parent60c20e242ce9d30fd9acb3660c83068752ed876e (diff)
downloadsystemd-a650e19820b85e7b82a87508a7f80ce764f2f1a0.tar.gz
Merge pull request #14010 from poettering/localtime-symlink
tweaks to /etc/localtime management
Diffstat (limited to 'src/timedate')
-rw-r--r--src/timedate/timedated.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 97a0868bc1..4ec3b50359 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) {
@@ -638,7 +653,7 @@ static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error *
return r;
if (!timezone_is_valid(z, LOG_DEBUG))
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid time zone '%s'", z);
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid or not installed time zone '%s'", z);
if (streq_ptr(z, c->zone))
return sd_bus_reply_method_return(m, NULL);