Exemplo n.º 1
0
static int vconsole_convert_to_x11(Context *c, sd_bus *bus) {
        bool modified = false;

        assert(bus);

        if (isempty(c->vc_keymap)) {

                modified =
                        !isempty(c->x11_layout) ||
                        !isempty(c->x11_model) ||
                        !isempty(c->x11_variant) ||
                        !isempty(c->x11_options);

                context_free_x11(c);
        } else {
                _cleanup_fclose_ FILE *f = NULL;
                unsigned n = 0;

                f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");
                if (!f)
                        return -errno;

                for (;;) {
                        _cleanup_strv_free_ char **a = NULL;
                        int r;

                        r = read_next_mapping(f, &n, &a);
                        if (r < 0)
                                return r;
                        if (r == 0)
                                break;

                        if (!streq(c->vc_keymap, a[0]))
                                continue;

                        if (!streq_ptr(c->x11_layout, strnulldash(a[1])) ||
                            !streq_ptr(c->x11_model, strnulldash(a[2])) ||
                            !streq_ptr(c->x11_variant, strnulldash(a[3])) ||
                            !streq_ptr(c->x11_options, strnulldash(a[4]))) {

                                if (free_and_copy(&c->x11_layout, strnulldash(a[1])) < 0 ||
                                    free_and_copy(&c->x11_model, strnulldash(a[2])) < 0 ||
                                    free_and_copy(&c->x11_variant, strnulldash(a[3])) < 0 ||
                                    free_and_copy(&c->x11_options, strnulldash(a[4])) < 0)
                                        return -ENOMEM;

                                modified = true;
                        }

                        break;
                }
        }

        if (modified) {
                int r;

                r = write_data_x11(c);
                if (r < 0)
                        log_error("Failed to set X11 keyboard layout: %s", strerror(-r));

                sd_bus_emit_properties_changed(bus,
                                "/org/freedesktop/locale1",
                                "org.freedesktop.locale1",
                                "X11Layout", "X11Model", "X11Variant", "X11Options", NULL);
        }

        return 0;
}
Exemplo n.º 2
0
static int convert_vconsole_to_x11(DBusConnection *connection) {
        bool modified = false;

        assert(connection);

        if (isempty(state.vc_keymap)) {

                modified =
                        !isempty(state.x11_layout) ||
                        !isempty(state.x11_model) ||
                        !isempty(state.x11_variant) ||
                        !isempty(state.x11_options);

                free_data_x11();
        } else {
                FILE *f;
                unsigned n = 0;

                f = fopen(SYSTEMD_KBD_MODEL_MAP, "re");
                if (!f)
                        return -errno;

                for (;;) {
                        char **a;
                        int r;

                        r = read_next_mapping(f, &n, &a);
                        if (r < 0) {
                                fclose(f);
                                return r;
                        }

                        if (r == 0)
                                break;

                        if (!streq(state.vc_keymap, a[0])) {
                                strv_free(a);
                                continue;
                        }

                        if (!streq_ptr(state.x11_layout, strnulldash(a[1])) ||
                            !streq_ptr(state.x11_model, strnulldash(a[2])) ||
                            !streq_ptr(state.x11_variant, strnulldash(a[3])) ||
                            !streq_ptr(state.x11_options, strnulldash(a[4]))) {

                                if (free_and_set(&state.x11_layout, strnulldash(a[1])) < 0 ||
                                    free_and_set(&state.x11_model, strnulldash(a[2])) < 0 ||
                                    free_and_set(&state.x11_variant, strnulldash(a[3])) < 0 ||
                                    free_and_set(&state.x11_options, strnulldash(a[4])) < 0) {
                                        strv_free(a);
                                        fclose(f);
                                        return -ENOMEM;
                                }

                                modified = true;
                        }

                        strv_free(a);
                        break;
                }

                fclose(f);
        }

        if (modified) {
                dbus_bool_t b;
                DBusMessage *changed;
                int r;

                r = write_data_x11();
                if (r < 0)
                        log_error("Failed to set X11 keyboard layout: %s", strerror(-r));

                changed = bus_properties_changed_new(
                                "/org/freedesktop/locale1",
                                "org.freedesktop.locale1",
                                "X11Layout\0"
                                "X11Model\0"
                                "X11Variant\0"
                                "X11Options\0");

                if (!changed)
                        return -ENOMEM;

                b = dbus_connection_send(connection, changed, NULL);
                dbus_message_unref(changed);

                if (!b)
                        return -ENOMEM;
        }

        return 0;
}