From: Michael Biebl Date: Thu, 18 Jul 2013 20:11:02 +0200 Subject: Use Debian specific config files Use /etc/default/locale instead of /etc/locale.conf for locale settings. Use /etc/default/keyboard instead of /etc/X11/xorg.conf.d/00-keyboard.conf for keyboard configuration. --- src/firstboot/firstboot.c | 12 ++- src/locale/localed-util.c | 189 ++++++++++++++++++++-------------------------- src/shared/locale-setup.c | 24 ++++-- 3 files changed, 108 insertions(+), 117 deletions(-) diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index dee2742..d66cf87 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -311,12 +311,16 @@ static int prompt_locale(void) { } static int process_locale(void) { - const char *etc_localeconf; + const char *etc_localeconf, *path = "/etc/locale.conf"; char* locales[3]; unsigned i = 0; - int r; + int r = 0; + + if (laccess(path, F_OK) < 0 && errno == ENOENT) + path = "/etc/default/locale"; + + etc_localeconf = prefix_roota(arg_root, path); - etc_localeconf = prefix_roota(arg_root, "/etc/locale.conf"); if (laccess(etc_localeconf, F_OK) >= 0 && !arg_force) { log_debug("Found %s, assuming locale information has been configured.", etc_localeconf); @@ -326,7 +330,7 @@ static int process_locale(void) { if (arg_copy_locale && arg_root) { (void) mkdir_parents(etc_localeconf, 0755); - r = copy_file("/etc/locale.conf", etc_localeconf, 0, 0644, 0, 0, COPY_REFLINK); + r = copy_file(path, etc_localeconf, 0, 0644, 0, 0, COPY_REFLINK); if (r != -ENOENT) { if (r < 0) return log_error_errno(r, "Failed to copy %s: %m", etc_localeconf); diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c index 4d021fb..d9050c0 100644 --- a/src/locale/localed-util.c +++ b/src/locale/localed-util.c @@ -128,7 +128,6 @@ int vconsole_read_data(Context *c, sd_bus_message *m) { int x11_read_data(Context *c, sd_bus_message *m) { _cleanup_fclose_ FILE *f = NULL; - bool in_section = false; struct stat st; usec_t t; int r; @@ -142,7 +141,7 @@ int x11_read_data(Context *c, sd_bus_message *m) { c->x11_cache = sd_bus_message_ref(m); } - if (stat("/etc/X11/xorg.conf.d/00-keyboard.conf", &st) < 0) { + if (stat("/etc/default/keyboard", &st) < 0) { if (errno != ENOENT) return -errno; @@ -159,60 +158,14 @@ int x11_read_data(Context *c, sd_bus_message *m) { c->x11_mtime = t; context_free_x11(c); - f = fopen("/etc/X11/xorg.conf.d/00-keyboard.conf", "re"); - if (!f) - return -errno; - - for (;;) { - _cleanup_free_ char *line = NULL; - char *l; - - r = read_line(f, LONG_LINE_MAX, &line); - if (r < 0) - return r; - if (r == 0) - break; - - l = strstrip(line); - if (IN_SET(l[0], 0, '#')) - continue; - - if (in_section && first_word(l, "Option")) { - _cleanup_strv_free_ char **a = NULL; - - r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE); - if (r < 0) - return r; - - if (strv_length(a) == 3) { - char **p = NULL; - - if (streq(a[1], "XkbLayout")) - p = &c->x11_layout; - else if (streq(a[1], "XkbModel")) - p = &c->x11_model; - else if (streq(a[1], "XkbVariant")) - p = &c->x11_variant; - else if (streq(a[1], "XkbOptions")) - p = &c->x11_options; - - if (p) - free_and_replace(*p, a[2]); - } - - } else if (!in_section && first_word(l, "Section")) { - _cleanup_strv_free_ char **a = NULL; - - r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE); - if (r < 0) - return -ENOMEM; - - if (strv_length(a) == 2 && streq(a[1], "InputClass")) - in_section = true; - - } 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,69 +206,93 @@ int vconsole_write_data(Context *c) { } int x11_write_data(Context *c) { - _cleanup_fclose_ FILE *f = NULL; - _cleanup_free_ char *temp_path = NULL; struct stat st; int r; + char *t, **l = NULL; - if (isempty(c->x11_layout) && - isempty(c->x11_model) && - isempty(c->x11_variant) && - isempty(c->x11_options)) { + r = load_env_file(NULL, "/etc/default/keyboard", &l); + if (r < 0 && r != -ENOENT) + return r; - if (unlink("/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) + /* This could perhaps be done more elegantly using an array + * like we do for the locale, instead of struct + */ + if (isempty(c->x11_layout)) { + l = strv_env_unset(l, "XKBLAYOUT"); + } else { + if (asprintf(&t, "XKBLAYOUT=%s", c->x11_layout) < 0) { + strv_free(l); + return -ENOMEM; + } + + r = strv_env_replace_consume(&l, t); + if (r < 0) { + strv_free(l); + return r; + } + } + + if (isempty(c->x11_model)) { + l = strv_env_unset(l, "XKBMODEL"); + } else { + if (asprintf(&t, "XKBMODEL=%s", c->x11_model) < 0) { + strv_free(l); + return -ENOMEM; + } + + r = strv_env_replace_consume(&l, t); + if (r < 0) { + strv_free(l); + return r; + } + } + + if (isempty(c->x11_variant)) { + l = strv_env_unset(l, "XKBVARIANT"); + } else { + if (asprintf(&t, "XKBVARIANT=%s", c->x11_variant) < 0) { + strv_free(l); + return -ENOMEM; + } + + r = strv_env_replace_consume(&l, t); + if (r < 0) { + strv_free(l); + return r; + } + } + + if (isempty(c->x11_options)) { + l = strv_env_unset(l, "XKBOPTIONS"); + } else { + if (asprintf(&t, "XKBOPTIONS=%s", c->x11_options) < 0) { + strv_free(l); + return -ENOMEM; + } + + r = strv_env_replace_consume(&l, t); + if (r < 0) { + strv_free(l); + return r; + } + } + + 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 (rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) { - r = -errno; - goto fail; - } - - 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); - 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 +++ b/src/shared/locale-setup.c @@ -49,14 +49,20 @@ int locale_context_load(LocaleContext *c, LocaleLoadFlag flag) { } if (FLAGS_SET(flag, LOCALE_LOAD_LOCALE_CONF)) { + const char *path = "/etc/locale.conf"; struct stat st; usec_t t; - r = stat("/etc/locale.conf", &st); + r = stat(path, &st); + if (r < 0 && errno == ENOENT) { + path = "/etc/default/locale"; + r = stat(path, &st); + } if (r < 0 && errno != ENOENT) - return log_debug_errno(errno, "Failed to stat /etc/locale.conf: %m"); + return log_debug_errno(errno, "Failed to stat %s: %m", path); if (r >= 0) { + /* If mtime is not changed, then we do not need to re-read the file. */ t = timespec_load(&st.st_mtim); if (c->mtime != USEC_INFINITY && t == c->mtime) @@ -65,7 +71,7 @@ int locale_context_load(LocaleContext *c, LocaleLoadFlag flag) { locale_context_clear(c); c->mtime = t; - r = parse_env_file(NULL, "/etc/locale.conf", + r = parse_env_file(NULL, path, "LANG", &c->locale[VARIABLE_LANG], "LANGUAGE", &c->locale[VARIABLE_LANGUAGE], "LC_CTYPE", &c->locale[VARIABLE_LC_CTYPE], @@ -81,7 +87,7 @@ int locale_context_load(LocaleContext *c, LocaleLoadFlag flag) { "LC_MEASUREMENT", &c->locale[VARIABLE_LC_MEASUREMENT], "LC_IDENTIFICATION", &c->locale[VARIABLE_LC_IDENTIFICATION]); if (r < 0) - return log_debug_errno(r, "Failed to read /etc/locale.conf: %m"); + return log_debug_errno(r, "Failed to read %s: %m", path); goto finalize; } @@ -149,17 +155,21 @@ int locale_context_save(LocaleContext *c, char ***ret_set, char ***ret_unset) { _cleanup_strv_free_ char **set = NULL, **unset = NULL; struct stat st; int r; + const char *path = "/etc/locale.conf"; assert(c); /* Set values will be returned as strv in *ret on success. */ + if (access(path, F_OK) < 0 && errno == ENOENT) + path = "/etc/default/locale"; + r = locale_context_build_env(c, &set, ret_unset ? &unset : NULL); if (r < 0) return r; if (strv_isempty(set)) { - if (unlink("/etc/locale.conf") < 0) + if (unlink(path) < 0) return errno == ENOENT ? 0 : -errno; c->mtime = USEC_INFINITY; @@ -170,11 +180,11 @@ int locale_context_save(LocaleContext *c, char ***ret_set, char ***ret_unset) { return 0; } - r = write_env_file_label("/etc/locale.conf", set); + r = write_env_file_label(path, set); if (r < 0) return r; - if (stat("/etc/locale.conf", &st) >= 0) + if (stat(path, &st) >= 0) c->mtime = timespec_load(&st.st_mtim); if (ret_set)