Read/write /etc/timezone if /etc/localtime does not exist.
---
src/basic/time-util.c | 34 +++++++--
- src/firstboot/firstboot.c | 12 ++--
- src/locale/localed-util.c | 175 ++++++++++++++++++++--------------------------
- src/shared/locale-setup.c | 24 +++++--
+ src/firstboot/firstboot.c | 12 ++-
+ src/locale/localed-util.c | 189 ++++++++++++++++++++--------------------------
+ src/shared/locale-setup.c | 24 ++++--
src/timedate/timedated.c | 21 +++++-
- 5 files changed, 148 insertions(+), 118 deletions(-)
+ 5 files changed, 155 insertions(+), 125 deletions(-)
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 71b2f67..fa00d9d 100644
- for (;;) {
- _cleanup_free_ char *line = NULL;
- char *l;
-+ r = parse_env_file(NULL, "/etc/default/keyboard",
-+ "XKBMODEL", &c->x11_model,
-+ "XKBLAYOUT", &c->x11_layout,
-+ "XKBVARIANT", &c->x11_variant,
-+ "XKBOPTIONS", &c->x11_options);
-
+-
- r = read_line(f, LONG_LINE_MAX, &line);
- if (r < 0)
- return r;
- } else if (in_section && first_word(l, "EndSection"))
- in_section = false;
- }
++ r = parse_env_file(NULL, "/etc/default/keyboard",
++ "XKBMODEL", &c->x11_model,
++ "XKBLAYOUT", &c->x11_layout,
++ "XKBVARIANT", &c->x11_variant,
++ "XKBOPTIONS", &c->x11_options);
++
+ if (r < 0)
+ return r;
return 0;
}
-@@ -253,68 +206,92 @@ int vconsole_write_data(Context *c) {
+@@ -253,69 +206,93 @@ int vconsole_write_data(Context *c) {
}
int x11_write_data(Context *c) {
+ return r;
- if (unlink("/etc/X11/xorg.conf.d/00-keyboard.conf") < 0)
-- return errno == ENOENT ? 0 : -errno;
+ /* This could perhaps be done more elegantly using an array
+ * like we do for the locale, instead of struct
+ */
+ strv_free(l);
+ return -ENOMEM;
+ }
-
-- c->vc_mtime = USEC_INFINITY;
-- return 0;
++
+ r = strv_env_replace_consume(&l, t);
+ if (r < 0) {
+ strv_free(l);
+ return r;
+ }
- }
-
-- (void) mkdir_p_label("/etc/X11/xorg.conf.d", 0755);
-- r = fopen_temporary("/etc/X11/xorg.conf.d/00-keyboard.conf", &f, &temp_path);
-- if (r < 0)
-- return r;
--
-- (void) fchmod(fileno(f), 0644);
++ }
++
+ if (isempty(c->x11_model)) {
+ l = strv_env_unset(l, "XKBMODEL");
+ } else {
+ strv_free(l);
+ return -ENOMEM;
+ }
-
-- fputs("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n"
-- "# probably wise not to edit this file manually. Use localectl(1) to\n"
-- "# instruct systemd-localed to update it.\n"
-- "Section \"InputClass\"\n"
-- " Identifier \"system-keyboard\"\n"
-- " MatchIsKeyboard \"on\"\n", f);
++
+ r = strv_env_replace_consume(&l, t);
+ if (r < 0) {
+ strv_free(l);
+ return r;
+ }
+ }
-
-- if (!isempty(c->x11_layout))
-- fprintf(f, " Option \"XkbLayout\" \"%s\"\n", c->x11_layout);
++
+ if (isempty(c->x11_variant)) {
+ l = strv_env_unset(l, "XKBVARIANT");
+ } else {
+ strv_free(l);
+ return -ENOMEM;
+ }
-
-- if (!isempty(c->x11_model))
-- fprintf(f, " Option \"XkbModel\" \"%s\"\n", c->x11_model);
++
+ r = strv_env_replace_consume(&l, t);
+ if (r < 0) {
+ strv_free(l);
+ return r;
+ }
+ }
-
-- if (!isempty(c->x11_variant))
-- fprintf(f, " Option \"XkbVariant\" \"%s\"\n", c->x11_variant);
++
+ if (isempty(c->x11_options)) {
+ l = strv_env_unset(l, "XKBOPTIONS");
+ } else {
+ strv_free(l);
+ return -ENOMEM;
+ }
-
-- if (!isempty(c->x11_options))
-- fprintf(f, " Option \"XkbOptions\" \"%s\"\n", c->x11_options);
++
+ r = strv_env_replace_consume(&l, t);
+ if (r < 0) {
+ strv_free(l);
+ return r;
+ }
+ }
-
-- fputs("EndSection\n", f);
++
+ if (strv_isempty(l)) {
+ strv_free(l);
++
++ if (unlink("/etc/default/keyboard") < 0)
+ return errno == ENOENT ? 0 : -errno;
+
+ c->vc_mtime = USEC_INFINITY;
+ return 0;
+ }
+
+- (void) mkdir_p_label("/etc/X11/xorg.conf.d", 0755);
+- r = fopen_temporary("/etc/X11/xorg.conf.d/00-keyboard.conf", &f, &temp_path);
+- if (r < 0)
+- return r;
++ r = write_env_file("/etc/default/keyboard", l);
++ strv_free(l);
+- (void) fchmod(fileno(f), 0644);
+-
+- fputs("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n"
+- "# probably wise not to edit this file manually. Use localectl(1) to\n"
+- "# instruct systemd-localed to update it.\n"
+- "Section \"InputClass\"\n"
+- " Identifier \"system-keyboard\"\n"
+- " MatchIsKeyboard \"on\"\n", f);
+-
+- if (!isempty(c->x11_layout))
+- fprintf(f, " Option \"XkbLayout\" \"%s\"\n", c->x11_layout);
+-
+- if (!isempty(c->x11_model))
+- fprintf(f, " Option \"XkbModel\" \"%s\"\n", c->x11_model);
+-
+- if (!isempty(c->x11_variant))
+- fprintf(f, " Option \"XkbVariant\" \"%s\"\n", c->x11_variant);
+-
+- if (!isempty(c->x11_options))
+- fprintf(f, " Option \"XkbOptions\" \"%s\"\n", c->x11_options);
+-
+- fputs("EndSection\n", f);
+-
- r = fflush_sync_and_check(f);
- if (r < 0)
- goto fail;
-+ if (unlink("/etc/default/keyboard") < 0)
-+ return errno == ENOENT ? 0 : -errno;
-
+-
- if (rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) {
- r = -errno;
- goto fail;
-+ c->vc_mtime = USEC_INFINITY;
-+ return 0;
- }
-
-- if (stat("/etc/X11/xorg.conf.d/00-keyboard.conf", &st) >= 0)
-- c->x11_mtime = timespec_load(&st.st_mtim);
+- }
-
-- return 0;
-+ r = write_env_file("/etc/default/keyboard", l);
-+ strv_free(l);
+- if (stat("/etc/X11/xorg.conf.d/00-keyboard.conf", &st) >= 0)
++ if (r >= 0 && stat("/etc/default/keyboard", &st) >= 0)
+ c->x11_mtime = timespec_load(&st.st_mtim);
+- return 0;
+-
-fail:
- if (temp_path)
- (void) unlink(temp_path);
-+ if (r >= 0 && stat("/etc/default/keyboard", &st) >= 0)
-+ c->x11_mtime = timespec_load(&st.st_mtim);
-
+-
return r;
}
+
diff --git a/src/shared/locale-setup.c b/src/shared/locale-setup.c
index b8c6647..be7efcb 100644
--- a/src/shared/locale-setup.c