localed.c revision 0b507b17a760b21e33fc52ff377db6aa5086c680
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek This file is part of systemd.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek Copyright 2011 Lennart Poettering
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek (at your option) any later version.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek " <interface name=\"org.freedesktop.locale1\">\n" \
799a8f39d8eb9ea725e85a598c0f5dbd658c8ba7Zbigniew Jędrzejewski-Szmek " <property name=\"Locale\" type=\"as\" access=\"read\"/>\n" \
799a8f39d8eb9ea725e85a598c0f5dbd658c8ba7Zbigniew Jędrzejewski-Szmek " <property name=\"VConsoleKeymap\" type=\"s\" access=\"read\"/>\n" \
799a8f39d8eb9ea725e85a598c0f5dbd658c8ba7Zbigniew Jędrzejewski-Szmek " <property name=\"VConsoleKeymapToggle\" type=\"s\" access=\"read\"/>\n" \
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek " <property name=\"X11Layout\" type=\"s\" access=\"read\"/>\n" \
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek " <property name=\"X11Model\" type=\"s\" access=\"read\"/>\n" \
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek " <property name=\"X11Variant\" type=\"s\" access=\"read\"/>\n" \
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek " <property name=\"X11Options\" type=\"s\" access=\"read\"/>\n" \
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek " <method name=\"SetLocale\">\n" \
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek " <arg name=\"locale\" type=\"as\" direction=\"in\"/>\n" \
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek " <arg name=\"user_interaction\" type=\"b\" direction=\"in\"/>\n" \
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek " </method>\n" \
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek " <method name=\"SetVConsoleKeyboard\">\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"keymap\" type=\"s\" direction=\"in\"/>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"keymap_toggle\" type=\"s\" direction=\"in\"/>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"convert\" type=\"b\" direction=\"in\"/>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"user_interaction\" type=\"b\" direction=\"in\"/>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " </method>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <method name=\"SetX11Keyboard\">\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"layout\" type=\"s\" direction=\"in\"/>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"model\" type=\"s\" direction=\"in\"/>\n" \
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek " <arg name=\"variant\" type=\"s\" direction=\"in\"/>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"options\" type=\"s\" direction=\"in\"/>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"convert\" type=\"b\" direction=\"in\"/>\n" \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek " <arg name=\"user_interaction\" type=\"b\" direction=\"in\"/>\n" \
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek " </method>\n" \
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek " </interface>\n"
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "org.freedesktop.locale1\0"
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekconst char locale_interface[] _introspect_("locale1") = INTERFACE;
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek /* We don't list LC_ALL here on purpose. People should be
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek * using LANG instead. */
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmekstatic const char * const names[_PROP_MAX] = {
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek [PROP_LC_NUMERIC] = "LC_NUMERIC",
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek [PROP_LC_COLLATE] = "LC_COLLATE",
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek [PROP_LC_MONETARY] = "LC_MONETARY",
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek [PROP_LC_MESSAGES] = "LC_MESSAGES",
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek [PROP_LC_ADDRESS] = "LC_ADDRESS",
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek [PROP_LC_TELEPHONE] = "LC_TELEPHONE",
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek [PROP_LC_MEASUREMENT] = "LC_MEASUREMENT",
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek [PROP_LC_IDENTIFICATION] = "LC_IDENTIFICATION"
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek char *x11_layout, *x11_model, *x11_variant, *x11_options;
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek char *vc_keymap, *vc_keymap_toggle;
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmekstatic int free_and_set(char **s, const char *v) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = strdup_or_null(isempty(v) ? NULL : v, &t);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic void free_data_locale(void) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek for (p = 0; p < _PROP_MAX; p++) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic void free_data_x11(void) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek state.x11_layout = state.x11_model = state.x11_variant = state.x11_options = NULL;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic void free_data_vconsole(void) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek state.vc_keymap = state.vc_keymap_toggle = NULL;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic void simplify(void) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (isempty(data[p]) || streq_ptr(data[PROP_LANG], data[p])) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic int read_data_locale(void) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = parse_env_file("/etc/locale.conf", NEWLINE,
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "LANGUAGE", &data[PROP_LANGUAGE],
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "LC_CTYPE", &data[PROP_LC_CTYPE],
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "LC_NUMERIC", &data[PROP_LC_NUMERIC],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "LC_COLLATE", &data[PROP_LC_COLLATE],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "LC_MONETARY", &data[PROP_LC_MONETARY],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "LC_MESSAGES", &data[PROP_LC_MESSAGES],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "LC_PAPER", &data[PROP_LC_PAPER],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "LC_ADDRESS", &data[PROP_LC_ADDRESS],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "LC_TELEPHONE", &data[PROP_LC_TELEPHONE],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "LC_MEASUREMENT", &data[PROP_LC_MEASUREMENT],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "LC_IDENTIFICATION", &data[PROP_LC_IDENTIFICATION],
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek /* Fill in what we got passed from systemd. */
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek for (p = 0; p < _PROP_MAX; p++) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic void free_data(void) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic int read_data_vconsole(void) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = parse_env_file("/etc/vconsole.conf", NEWLINE,
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "KEYMAP_TOGGLE", &state.vc_keymap_toggle,
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (r < 0 && r != -ENOENT)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek f = fopen("/etc/X11/xorg.conf.d/00-keyboard.conf", "re");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek return errno == ENOENT ? 0 : -errno;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek while (fgets(line, sizeof(line), f)) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (l[0] == 0 || l[0] == '#')
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (in_section && first_word(l, "Option")) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek } else if (streq(a[1], "XkbModel")) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek } else if (streq(a[1], "XkbVariant")) {
8201af08fa09c2bd0f005fbe262f27e2c5bd2d86Zbigniew Jędrzejewski-Szmek } else if (streq(a[1], "XkbOptions")) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek } else if (!in_section && first_word(l, "Section")) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (strv_length(a) == 2 && streq(a[1], "InputClass"))
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek } else if (in_section && first_word(l, "EndSection"))
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic int read_data(void) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek return r < 0 ? r : q < 0 ? q : p;
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic int write_data_locale(void) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek r = load_env_file("/etc/locale.conf", &l);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (r < 0 && r != -ENOENT)
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek for (p = 0; p < _PROP_MAX; p++) {
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek l = strv_env_unset(l, names[p]);
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek if (asprintf(&t, "%s=%s", names[p], data[p]) < 0) {
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek if (unlink("/etc/locale.conf") < 0)
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek return errno == ENOENT ? 0 : -errno;
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek r = write_env_file("/etc/locale.conf", l);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic void push_data(DBusConnection *bus) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek char **l_set = NULL, **l_unset = NULL, **t;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek DBusMessage *m = NULL, *reply = NULL;
5bc891206dd8eb4e4df58f502b0184b8426caf22Zbigniew Jędrzejewski-Szmek l_unset = new0(char*, _PROP_MAX);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek for (p = 0; p < _PROP_MAX; p++) {
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek l_unset[c_set++] = (char*) names[p];
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek if (asprintf(&s, "%s=%s", names[p], data[p]) < 0) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek assert(c_set + c_unset == _PROP_MAX);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnsetAndSetEnvironment");
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek log_error("Could not allocate message.");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek dbus_message_iter_init_append(m, &iter);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_close_container(&iter, &sub) ||
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub)) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t)) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_close_container(&iter, &sub)) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_error("Failed to set locale information: %s", bus_error_message(&error));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic int write_data_vconsole(void) {
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek r = load_env_file("/etc/vconsole.conf", &l);
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek if (r < 0 && r != -ENOENT)
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek l = strv_env_unset(l, "KEYMAP");
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek s = strappend("KEYMAP=", state.vc_keymap);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (isempty(state.vc_keymap_toggle))
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek l = strv_env_unset(l, "KEYMAP_TOGGLE");
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek s = strappend("KEYMAP_TOGGLE=", state.vc_keymap_toggle);
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek if (unlink("/etc/vconsole.conf") < 0)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek return errno == ENOENT ? 0 : -errno;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = write_env_file("/etc/vconsole.conf", l);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic int write_data_x11(void) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (isempty(state.x11_layout) &&
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (unlink("/etc/X11/xorg.conf.d/00-keyboard.conf") < 0)
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek return errno == ENOENT ? 0 : -errno;
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek mkdir_parents_label("/etc/X11/xorg.conf.d", 0755);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = fopen_temporary("/etc/X11/xorg.conf.d/00-keyboard.conf", &f, &temp_path);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek fputs("# Read and parsed by systemd-localed. It's probably wise not to edit this file\n"
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "# manually too freely.\n"
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "Section \"InputClass\"\n"
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek " Identifier \"system-keyboard\"\n"
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek " MatchIsKeyboard \"on\"\n", f);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek fprintf(f, " Option \"XkbLayout\" \"%s\"\n", state.x11_layout);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek fprintf(f, " Option \"XkbModel\" \"%s\"\n", state.x11_model);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (!isempty(state.x11_variant))
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek fprintf(f, " Option \"XkbVariant\" \"%s\"\n", state.x11_variant);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek if (!isempty(state.x11_options))
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek fprintf(f, " Option \"XkbOptions\" \"%s\"\n", state.x11_options);
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek if (ferror(f) || rename(temp_path, "/etc/X11/xorg.conf.d/00-keyboard.conf") < 0) {
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek unlink("/etc/X11/xorg.conf.d/00-keyboard.conf");
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmekstatic int load_vconsole_keymap(DBusConnection *bus, DBusError *error) {
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek DBusMessage *m = NULL, *reply = NULL;
7449bc1f34c206e3ff8e274cd74e2db950d492a1Zbigniew Jędrzejewski-Szmek const char *name = "systemd-vconsole-setup.service", *mode = "replace";
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek m = dbus_message_new_method_call(
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "org.freedesktop.systemd1.Manager",
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_error("Could not allocate message.");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (!dbus_message_append_args(m,
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_error("Could not append arguments to message.");
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek reply = dbus_connection_send_with_reply_and_block(bus, m, -1, error);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_error("Failed to issue method call: %s", bus_error_message(error));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic char *strnulldash(const char *s) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek return s == NULL || *s == 0 || (s[0] == '-' && s[1] == 0) ? NULL : (char*) s;
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic int read_next_mapping(FILE *f, unsigned *n, char ***a) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek if (!fgets(line, sizeof(line), f)) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (l[0] == 0 || l[0] == '#')
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek log_error("Invalid line "SYSTEMD_KBD_MODEL_MAP":%u, ignoring.", *n);
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmekstatic int convert_vconsole_to_x11(DBusConnection *connection) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek r = read_next_mapping(f, &n, &a);
29fc0ddcd737af906986d4029579d4dfe838ba02Zbigniew Jędrzejewski-Szmek if (!streq(state.vc_keymap, a[0])) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (!streq_ptr(state.x11_layout, strnulldash(a[1])) ||
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek !streq_ptr(state.x11_model, strnulldash(a[2])) ||
722b6795655149a68277b3cffeba711e1d440e5aZbigniew Jędrzejewski-Szmek !streq_ptr(state.x11_variant, strnulldash(a[3])) ||
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek !streq_ptr(state.x11_options, strnulldash(a[4]))) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (free_and_set(&state.x11_layout, strnulldash(a[1])) < 0 ||
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek free_and_set(&state.x11_model, strnulldash(a[2])) < 0 ||
a3152e7655231b94fa7b9582906fb86ab00b9c99Zbigniew Jędrzejewski-Szmek free_and_set(&state.x11_variant, strnulldash(a[3])) < 0 ||
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek free_and_set(&state.x11_options, strnulldash(a[4])) < 0) {
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek log_error("Failed to set X11 keyboard layout: %s", strerror(-r));
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek changed = bus_properties_changed_new(
eacbb4d33e2bb5c54311544851140efe3dd0f774Zbigniew Jędrzejewski-Szmek "org.freedesktop.locale1",
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek "X11Options\0");
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek b = dbus_connection_send(connection, changed, NULL);
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmekstatic int convert_x11_to_vconsole(DBusConnection *connection) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek if (isempty(state.x11_layout)) {
3d090cc6f34e5970765dd1e7ee5e648a056d180dZbigniew Jędrzejewski-Szmek !isempty(state.vc_keymap_toggle);
return -errno;
unsigned matching = 0;
r = read_next_mapping(f, &n, &a);
fclose(f);
size_t x;
size_t w;
if (matching > 0 &&
matching++;
matching++;
matching++;
if (!new_keymap) {
strv_free(a);
fclose(f);
return -ENOMEM;
strv_free(a);
fclose(f);
modified = true;
if (modified) {
dbus_bool_t b;
r = write_data_vconsole();
"/org/freedesktop/locale1",
if (!changed)
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
for (p = 0; p < _PROP_MAX; p++) {
strv_free(l);
return -ENOMEM;
strv_free(l);
{ "VConsoleKeymapToggle", bus_property_append_string, "s", offsetof(State, vc_keymap_toggle), true },
{ NULL, }
{ NULL, }
void *userdata) {
char **l = NULL, **i;
bool modified = false;
if (r == -ENOMEM)
goto oom;
strv_free(l);
STRV_FOREACH(i, l) {
bool valid = false;
for (p = 0; p < _PROP_MAX; p++) {
size_t k;
valid = true;
passed[p] = true;
modified = true;
if (!valid) {
strv_free(l);
if (!modified) {
for (p = 0; p < _PROP_MAX; p++)
modified = true;
if (modified) {
r = verify_polkit(connection, message, "org.freedesktop.locale1.set-locale", interactive, NULL, &error);
strv_free(l);
STRV_FOREACH(i, l) {
for (p = 0; p < _PROP_MAX; p++) {
size_t k;
strv_free(l);
goto oom;
data[p] = t;
strv_free(l);
for (p = 0; p < _PROP_MAX; p++) {
if (passed[p])
simplify();
r = write_data_locale();
"/org/freedesktop/locale1",
if (!changed)
goto oom;
strv_free(l);
} else if (dbus_message_is_method_call(message, "org.freedesktop.locale1", "SetVConsoleKeyboard")) {
if (!dbus_message_get_args(
&error,
r = verify_polkit(connection, message, "org.freedesktop.locale1.set-keyboard", interactive, NULL, &error);
goto oom;
r = write_data_vconsole();
"/org/freedesktop/locale1",
if (!changed)
goto oom;
if (convert) {
if (!dbus_message_get_args(
&error,
r = verify_polkit(connection, message, "org.freedesktop.locale1.set-keyboard", interactive, NULL, &error);
goto oom;
r = write_data_x11();
"/org/freedesktop/locale1",
if (!changed)
goto oom;
if (convert) {
goto oom;
goto oom;
if (changed) {
goto oom;
return DBUS_HANDLER_RESULT_HANDLED;
oom:
if (reply)
if (changed)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (!bus) {
r = -ECONNREFUSED;
goto fail;
r = log_oom();
goto fail;
r = -EEXIST;
goto fail;
if (r != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
r = -EEXIST;
goto fail;
if (_bus)
fail:
bool exiting = false;
log_open();
r = -EINVAL;
goto finish;
r = read_data();
goto finish;
goto finish;
if (!dbus_connection_read_write_dispatch(bus, exiting ? -1 : (int) (DEFAULT_EXIT_USEC/USEC_PER_MSEC)))
exiting = true;
free_data();
if (bus) {