localectl.c revision 7ca7021a9e0c443d40d0af5e9a7e1962d8032229
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering/***
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering This file is part of systemd.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering Copyright 2012 Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering systemd is free software; you can redistribute it and/or modify it
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering under the terms of the GNU Lesser General Public License as published by
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering (at your option) any later version.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering systemd is distributed in the hope that it will be useful, but
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering Lesser General Public License for more details.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering You should have received a copy of the GNU Lesser General Public License
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering***/
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <stdlib.h>
4871690d9e32608bbd9b18505b5326c2079c9690Allin Cottrell#include <stdbool.h>
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <unistd.h>
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <getopt.h>
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <string.h>
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <ftw.h>
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include <sys/mman.h>
13790add4bf648fed816361794d8277a75253410Lennart Poettering#include <fcntl.h>
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering#include "dbus-common.h"
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering#include "util.h"
13790add4bf648fed816361794d8277a75253410Lennart Poettering#include "spawn-polkit-agent.h"
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering#include "build.h"
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering#include "strv.h"
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek#include "pager.h"
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering#include "set.h"
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen#include "path-util.h"
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poetteringstatic bool arg_no_pager = false;
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poetteringstatic enum transport {
4f5dd3943bef8a04be7e3b838b822bb9a7ad6cb3Lennart Poettering TRANSPORT_NORMAL,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering TRANSPORT_SSH,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering TRANSPORT_POLKIT
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering} arg_transport = TRANSPORT_NORMAL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic bool arg_ask_password = true;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic const char *arg_host = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic bool arg_convert = true;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic void pager_open_if_enabled(void) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (arg_no_pager)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering pager_open();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering}
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic void polkit_agent_open_if_enabled(void) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* Open the polkit agent as a child process if necessary */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!arg_ask_password)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return;
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering polkit_agent_open();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering}
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringtypedef struct StatusInfo {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering char **locale;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const char *vconsole_keymap;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const char *vconsole_keymap_toggle;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const char *x11_layout;
13790add4bf648fed816361794d8277a75253410Lennart Poettering const char *x11_model;
13790add4bf648fed816361794d8277a75253410Lennart Poettering const char *x11_variant;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const char *x11_options;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering} StatusInfo;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poetteringstatic void print_status_info(StatusInfo *i) {
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering assert(i);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (strv_isempty(i->locale))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering puts(" System Locale: n/a\n");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering else {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering char **j;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering printf(" System Locale: %s\n", i->locale[0]);
13790add4bf648fed816361794d8277a75253410Lennart Poettering STRV_FOREACH(j, i->locale + 1)
13790add4bf648fed816361794d8277a75253410Lennart Poettering printf(" %s\n", *j);
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering printf(" VC Keymap: %s\n", strna(i->vconsole_keymap));
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!isempty(i->vconsole_keymap_toggle))
13790add4bf648fed816361794d8277a75253410Lennart Poettering printf("VC Toggle Keymap: %s\n", i->vconsole_keymap_toggle);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering printf(" X11 Layout: %s\n", strna(i->x11_layout));
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!isempty(i->x11_model))
13790add4bf648fed816361794d8277a75253410Lennart Poettering printf(" X11 Model: %s\n", i->x11_model);
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!isempty(i->x11_variant))
13790add4bf648fed816361794d8277a75253410Lennart Poettering printf(" X11 Variant: %s\n", i->x11_variant);
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!isempty(i->x11_options))
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek printf(" X11 Options: %s\n", i->x11_options);
13790add4bf648fed816361794d8277a75253410Lennart Poettering}
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int status_property(const char *name, DBusMessageIter *iter, StatusInfo *i) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering int r;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering assert(name);
13790add4bf648fed816361794d8277a75253410Lennart Poettering assert(iter);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering switch (dbus_message_iter_get_arg_type(iter)) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case DBUS_TYPE_STRING: {
13790add4bf648fed816361794d8277a75253410Lennart Poettering const char *s;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering dbus_message_iter_get_basic(iter, &s);
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!isempty(s)) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (streq(name, "VConsoleKeymap"))
13790add4bf648fed816361794d8277a75253410Lennart Poettering i->vconsole_keymap = s;
13790add4bf648fed816361794d8277a75253410Lennart Poettering else if (streq(name, "VConsoleKeymapToggle"))
13790add4bf648fed816361794d8277a75253410Lennart Poettering i->vconsole_keymap_toggle = s;
13790add4bf648fed816361794d8277a75253410Lennart Poettering else if (streq(name, "X11Layout"))
13790add4bf648fed816361794d8277a75253410Lennart Poettering i->x11_layout = s;
13790add4bf648fed816361794d8277a75253410Lennart Poettering else if (streq(name, "X11Model"))
13790add4bf648fed816361794d8277a75253410Lennart Poettering i->x11_model = s;
13790add4bf648fed816361794d8277a75253410Lennart Poettering else if (streq(name, "X11Variant"))
13790add4bf648fed816361794d8277a75253410Lennart Poettering i->x11_variant = s;
13790add4bf648fed816361794d8277a75253410Lennart Poettering else if (streq(name, "X11Options"))
13790add4bf648fed816361794d8277a75253410Lennart Poettering i->x11_options = s;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering break;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case DBUS_TYPE_ARRAY:
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRING) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering char **l;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering r = bus_parse_strv_iter(iter, &l);
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (r < 0)
13790add4bf648fed816361794d8277a75253410Lennart Poettering return r;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (streq(name, "Locale")) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering strv_free(i->locale);
13790add4bf648fed816361794d8277a75253410Lennart Poettering i->locale = l;
13790add4bf648fed816361794d8277a75253410Lennart Poettering l = NULL;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering strv_free(l);
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering return 0;
13790add4bf648fed816361794d8277a75253410Lennart Poettering}
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int show_status(DBusConnection *bus, char **args, unsigned n) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
13790add4bf648fed816361794d8277a75253410Lennart Poettering const char *interface = "";
13790add4bf648fed816361794d8277a75253410Lennart Poettering int r;
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBusMessageIter iter, sub, sub2, sub3;
13790add4bf648fed816361794d8277a75253410Lennart Poettering StatusInfo info;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering assert(args);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering r = bus_method_call_with_reply(
13790add4bf648fed816361794d8277a75253410Lennart Poettering bus,
13790add4bf648fed816361794d8277a75253410Lennart Poettering "org.freedesktop.locale1",
13790add4bf648fed816361794d8277a75253410Lennart Poettering "/org/freedesktop/locale1",
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering "org.freedesktop.DBus.Properties",
13790add4bf648fed816361794d8277a75253410Lennart Poettering "GetAll",
13790add4bf648fed816361794d8277a75253410Lennart Poettering &reply,
13790add4bf648fed816361794d8277a75253410Lennart Poettering NULL,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_STRING, &interface,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_INVALID);
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (r < 0)
13790add4bf648fed816361794d8277a75253410Lennart Poettering return r;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!dbus_message_iter_init(reply, &iter) ||
13790add4bf648fed816361794d8277a75253410Lennart Poettering dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
13790add4bf648fed816361794d8277a75253410Lennart Poettering dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_DICT_ENTRY) {
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering log_error("Failed to parse reply.");
13790add4bf648fed816361794d8277a75253410Lennart Poettering return -EIO;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering zero(info);
13790add4bf648fed816361794d8277a75253410Lennart Poettering dbus_message_iter_recurse(&iter, &sub);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering const char *name;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_DICT_ENTRY) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering log_error("Failed to parse reply.");
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering return -EIO;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering dbus_message_iter_recurse(&sub, &sub2);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &name, true) < 0) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering log_error("Failed to parse reply.");
13790add4bf648fed816361794d8277a75253410Lennart Poettering return -EIO;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering if (dbus_message_iter_get_arg_type(&sub2) != DBUS_TYPE_VARIANT) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering log_error("Failed to parse reply.");
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering return -EIO;
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering }
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering dbus_message_iter_recurse(&sub2, &sub3);
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering r = status_property(name, &sub3, &info);
dacd6cee76a08331b8c8616c5f30f70ee49aa2f9Lennart Poettering if (r < 0) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering log_error("Failed to parse reply.");
13790add4bf648fed816361794d8277a75253410Lennart Poettering return r;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering dbus_message_iter_next(&sub);
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek }
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek print_status_info(&info);
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek strv_free(info.locale);
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek return 0;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering}
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int set_locale(DBusConnection *bus, char **args, unsigned n) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering dbus_bool_t interactive = true;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering DBusError error;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering DBusMessageIter iter;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering int r;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering assert(bus);
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek assert(args);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering dbus_error_init(&error);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering polkit_agent_open_if_enabled();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering m = dbus_message_new_method_call(
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering "org.freedesktop.locale1",
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering "/org/freedesktop/locale1",
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering "org.freedesktop.locale1",
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering "SetLocale");
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen if (!m)
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen return log_oom();
40b71e89bae4e51768db4dc50ec64c1e9c96eec4Sebastian Thorarensen
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering dbus_message_iter_init_append(m, &iter);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek r = bus_append_strv_iter(&iter, args + 1);
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek if (r < 0)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return log_oom();
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &interactive))
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek return log_oom();
e3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51Zbigniew Jędrzejewski-Szmek
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!reply) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Failed to issue method call: %s", bus_error_message(&error));
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = -EIO;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = 0;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringfinish:
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering dbus_error_free(&error);
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek return r;
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek}
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int list_locales(DBusConnection *bus, char **args, unsigned n) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* Stolen from glibc... */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering struct locarhead {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t magic;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* Serial number. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t serial;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* Name hash table. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t namehash_offset;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t namehash_used;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t namehash_size;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* String table. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t string_offset;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t string_used;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t string_size;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* Table with locale records. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t locrectab_offset;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t locrectab_used;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t locrectab_size;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* MD5 sum hash table. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t sumhash_offset;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t sumhash_used;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t sumhash_size;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering };
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering struct namehashent {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* Hash value of the name. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t hashval;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* Offset of the name in the string table. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t name_offset;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering /* Offset of the locale record. */
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering uint32_t locrec_offset;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering };
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const struct locarhead *h;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const struct namehashent *e;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const void *p = MAP_FAILED;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering _cleanup_close_ int fd = -1;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering _cleanup_strv_free_ char **l = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering char **j;
41891700e02daf0cab9e86908c76ac6f411bbd57Lennart Poettering Set *locales;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering size_t sz = 0;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering struct stat st;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering unsigned i;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering int r;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering locales = set_new(string_hash_func, string_compare_func);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!locales)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return log_oom();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering fd = open("/usr/lib/locale/locale-archive", O_RDONLY|O_NOCTTY|O_CLOEXEC);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (fd < 0) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Failed to open locale archive: %m");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = -errno;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (fstat(fd, &st) < 0) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("fstat() failed: %m");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = -errno;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!S_ISREG(st.st_mode)) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Archive file is not regular");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = -EBADMSG;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (st.st_size < (off_t) sizeof(struct locarhead)) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Archive has invalid size");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = -EBADMSG;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering p = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (p == MAP_FAILED) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Failed to map archive: %m");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = -errno;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering h = (const struct locarhead *) p;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (h->magic != 0xde020109 ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering h->namehash_offset + h->namehash_size > st.st_size ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering h->string_offset + h->string_size > st.st_size ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering h->locrectab_offset + h->locrectab_size > st.st_size ||
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering h->sumhash_offset + h->sumhash_size > st.st_size) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Invalid archive file.");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = -EBADMSG;
13790add4bf648fed816361794d8277a75253410Lennart Poettering goto finish;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering e = (const struct namehashent*) ((const uint8_t*) p + h->namehash_offset);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering for (i = 0; i < h->namehash_size; i++) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering char *z;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (e[i].locrec_offset == 0)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering continue;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering z = strdup((char*) p + e[i].name_offset);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!z) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = log_oom();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = set_put(locales, z);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (r < 0) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering free(z);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Failed to add locale: %s", strerror(-r));
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering l = set_get_strv(locales);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!l) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = log_oom();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering goto finish;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering set_free(locales);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering locales = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering strv_sort(l);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering pager_open_if_enabled();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering STRV_FOREACH(j, l)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering puts(*j);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering r = 0;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringfinish:
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (p != MAP_FAILED)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering munmap((void*) p, sz);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering set_free_free(locales);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return r;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering}
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int set_vconsole_keymap(DBusConnection *bus, char **args, unsigned n) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering dbus_bool_t interactive = true, b;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const char *map, *toggle_map;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering assert(bus);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering assert(args);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (n > 3) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Too many arguments.");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return -EINVAL;
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering }
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering polkit_agent_open_if_enabled();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering map = args[1];
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering toggle_map = n > 2 ? args[2] : "";
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering b = arg_convert;
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering return bus_method_call_with_reply(
91bf3b3e124575f6f647bff29766e9d992f55b32Lennart Poettering bus,
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering "org.freedesktop.locale1",
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering "/org/freedesktop/locale1",
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering "org.freedesktop.locale1",
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering "SetVConsoleKeyboard",
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering &reply,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering NULL,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering DBUS_TYPE_STRING, &map,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering DBUS_TYPE_STRING, &toggle_map,
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidt DBUS_TYPE_BOOLEAN, &b,
91bf3b3e124575f6f647bff29766e9d992f55b32Lennart Poettering DBUS_TYPE_BOOLEAN, &interactive,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering DBUS_TYPE_INVALID);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering}
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
7b77ed8cf36e8eca6017791626044b61ae2d68e7Lennart Poetteringstatic Set *keymaps = NULL;
91bf3b3e124575f6f647bff29766e9d992f55b32Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int nftw_cb(
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const char *fpath,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering const struct stat *sb,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering int tflag,
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering struct FTW *ftwbuf) {
91bf3b3e124575f6f647bff29766e9d992f55b32Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering char *p, *e;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering int r;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
91bf3b3e124575f6f647bff29766e9d992f55b32Lennart Poettering if (tflag != FTW_F)
13790add4bf648fed816361794d8277a75253410Lennart Poettering return 0;
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (!endswith(fpath, ".map") &&
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering !endswith(fpath, ".map.gz"))
13790add4bf648fed816361794d8277a75253410Lennart Poettering return 0;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering p = strdup(path_get_file_name(fpath));
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!p)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return log_oom();
13790add4bf648fed816361794d8277a75253410Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering e = endswith(p, ".map");
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (e)
13790add4bf648fed816361794d8277a75253410Lennart Poettering *e = 0;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering e = endswith(p, ".map.gz");
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (e)
13790add4bf648fed816361794d8277a75253410Lennart Poettering *e = 0;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering r = set_put(keymaps, p);
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (r == -EEXIST)
13790add4bf648fed816361794d8277a75253410Lennart Poettering free(p);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering else if (r < 0) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering log_error("Can't add keymap: %s", strerror(-r));
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek free(p);
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek return r;
2de56f70941eaf91a4520bf33de47a87ebd8b2cbZbigniew Jędrzejewski-Szmek }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return 0;
13790add4bf648fed816361794d8277a75253410Lennart Poettering}
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering char _cleanup_strv_free_ **l = NULL;
13790add4bf648fed816361794d8277a75253410Lennart Poettering char **i;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering keymaps = set_new(string_hash_func, string_compare_func);
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!keymaps)
13790add4bf648fed816361794d8277a75253410Lennart Poettering return log_oom();
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering nftw("/usr/share/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);
13790add4bf648fed816361794d8277a75253410Lennart Poettering nftw("/usr/lib/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);
13790add4bf648fed816361794d8277a75253410Lennart Poettering nftw("/lib/kbd/keymaps/", nftw_cb, 20, FTW_MOUNT|FTW_PHYS);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering l = set_get_strv(keymaps);
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (!l) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering set_free_free(keymaps);
13790add4bf648fed816361794d8277a75253410Lennart Poettering return log_oom();
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering set_free(keymaps);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (strv_isempty(l)) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Couldn't find any console keymaps.");
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering return -ENOENT;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering strv_sort(l);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering pager_open_if_enabled();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering STRV_FOREACH(i, l)
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering puts(*i);
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering return 0;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering}
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poetteringstatic int set_x11_keymap(DBusConnection *bus, char **args, unsigned n) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering dbus_bool_t interactive = true, b;
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidt const char *layout, *model, *variant, *options;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering assert(bus);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering assert(args);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (n > 5) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Too many arguments.");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return -EINVAL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering polkit_agent_open_if_enabled();
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering layout = args[1];
13790add4bf648fed816361794d8277a75253410Lennart Poettering model = n > 2 ? args[2] : "";
13790add4bf648fed816361794d8277a75253410Lennart Poettering variant = n > 3 ? args[3] : "";
13790add4bf648fed816361794d8277a75253410Lennart Poettering options = n > 3 ? args[4] : "";
13790add4bf648fed816361794d8277a75253410Lennart Poettering b = arg_convert;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering return bus_method_call_with_reply(
13790add4bf648fed816361794d8277a75253410Lennart Poettering bus,
13790add4bf648fed816361794d8277a75253410Lennart Poettering "org.freedesktop.locale1",
13790add4bf648fed816361794d8277a75253410Lennart Poettering "/org/freedesktop/locale1",
13790add4bf648fed816361794d8277a75253410Lennart Poettering "org.freedesktop.locale1",
13790add4bf648fed816361794d8277a75253410Lennart Poettering "SetX11Keyboard",
13790add4bf648fed816361794d8277a75253410Lennart Poettering &reply,
13790add4bf648fed816361794d8277a75253410Lennart Poettering NULL,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_STRING, &layout,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_STRING, &model,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_STRING, &variant,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_STRING, &options,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_BOOLEAN, &b,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_BOOLEAN, &interactive,
13790add4bf648fed816361794d8277a75253410Lennart Poettering DBUS_TYPE_INVALID);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering}
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int help(void) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering printf("%s [OPTIONS...] COMMAND ...\n\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering "Query or change system time and date settings.\n\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " -h --help Show this help\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " --version Show package version\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " --no-convert Don't convert keyboard mappings\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " --no-pager Do not pipe output into a pager\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " --no-ask-password Do not prompt for password\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " -H --host=[USER@]HOST Operate on remote host\n\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering "Commands:\n"
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering " status Show current locale settings\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " set-locale LOCALE... Set system locale\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " list-locales Show known locales\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " set-keymap MAP [MAP] Set virtual console keyboard mapping\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " list-keymaps Show known virtual console keyboard mappings\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " set-x11-keymap LAYOUT [MODEL] [VARIANT] [OPTIONS]\n"
13790add4bf648fed816361794d8277a75253410Lennart Poettering " Set X11 keyboard mapping\n",
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering program_invocation_short_name);
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering return 0;
13790add4bf648fed816361794d8277a75253410Lennart Poettering}
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int parse_argv(int argc, char *argv[]) {
d682b3a7e7c7c2941a4d3e193f1e330dbc9fae89Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering enum {
13790add4bf648fed816361794d8277a75253410Lennart Poettering ARG_VERSION = 0x100,
13790add4bf648fed816361794d8277a75253410Lennart Poettering ARG_NO_PAGER,
13790add4bf648fed816361794d8277a75253410Lennart Poettering ARG_NO_CONVERT,
13790add4bf648fed816361794d8277a75253410Lennart Poettering ARG_NO_ASK_PASSWORD
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering };
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering static const struct option options[] = {
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "help", no_argument, NULL, 'h' },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "version", no_argument, NULL, ARG_VERSION },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "no-pager", no_argument, NULL, ARG_NO_PAGER },
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering { "host", required_argument, NULL, 'H' },
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering { "privileged", no_argument, NULL, 'P' },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "no-convert", no_argument, NULL, ARG_NO_CONVERT },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { NULL, 0, NULL, 0 }
13790add4bf648fed816361794d8277a75253410Lennart Poettering };
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering int c;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering assert(argc >= 0);
13790add4bf648fed816361794d8277a75253410Lennart Poettering assert(argv);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering while ((c = getopt_long(argc, argv, "has:H:P", options, NULL)) >= 0) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering switch (c) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case 'h':
13790add4bf648fed816361794d8277a75253410Lennart Poettering help();
13790add4bf648fed816361794d8277a75253410Lennart Poettering return 0;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case ARG_VERSION:
13790add4bf648fed816361794d8277a75253410Lennart Poettering puts(PACKAGE_STRING);
13790add4bf648fed816361794d8277a75253410Lennart Poettering puts(DISTRIBUTION);
13790add4bf648fed816361794d8277a75253410Lennart Poettering puts(SYSTEMD_FEATURES);
13790add4bf648fed816361794d8277a75253410Lennart Poettering return 0;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case 'P':
13790add4bf648fed816361794d8277a75253410Lennart Poettering arg_transport = TRANSPORT_POLKIT;
13790add4bf648fed816361794d8277a75253410Lennart Poettering break;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case 'H':
13790add4bf648fed816361794d8277a75253410Lennart Poettering arg_transport = TRANSPORT_SSH;
13790add4bf648fed816361794d8277a75253410Lennart Poettering arg_host = optarg;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering break;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case ARG_NO_CONVERT:
13790add4bf648fed816361794d8277a75253410Lennart Poettering arg_convert = false;
15d91bff36c61d38df8edff258d1702a017a0e66Zbigniew Jędrzejewski-Szmek break;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case ARG_NO_PAGER:
13790add4bf648fed816361794d8277a75253410Lennart Poettering arg_no_pager = true;
13790add4bf648fed816361794d8277a75253410Lennart Poettering break;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering case '?':
13790add4bf648fed816361794d8277a75253410Lennart Poettering return -EINVAL;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering default:
13790add4bf648fed816361794d8277a75253410Lennart Poettering log_error("Unknown option code %c", c);
13790add4bf648fed816361794d8277a75253410Lennart Poettering return -EINVAL;
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering }
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering return 1;
13790add4bf648fed816361794d8277a75253410Lennart Poettering}
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poetteringstatic int localectl_main(DBusConnection *bus, int argc, char *argv[], DBusError *error) {
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering static const struct {
13790add4bf648fed816361794d8277a75253410Lennart Poettering const char* verb;
13790add4bf648fed816361794d8277a75253410Lennart Poettering const enum {
13790add4bf648fed816361794d8277a75253410Lennart Poettering MORE,
13790add4bf648fed816361794d8277a75253410Lennart Poettering LESS,
13790add4bf648fed816361794d8277a75253410Lennart Poettering EQUAL
13790add4bf648fed816361794d8277a75253410Lennart Poettering } argc_cmp;
13790add4bf648fed816361794d8277a75253410Lennart Poettering const int argc;
13790add4bf648fed816361794d8277a75253410Lennart Poettering int (* const dispatch)(DBusConnection *bus, char **args, unsigned n);
13790add4bf648fed816361794d8277a75253410Lennart Poettering } verbs[] = {
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "status", LESS, 1, show_status },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "set-locale", MORE, 2, set_locale },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "list-locales", EQUAL, 1, list_locales },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "set-keymap", MORE, 2, set_vconsole_keymap },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "list-keymaps", EQUAL, 1, list_vconsole_keymaps },
13790add4bf648fed816361794d8277a75253410Lennart Poettering { "set-x11-keymap", MORE, 2, set_x11_keymap },
13790add4bf648fed816361794d8277a75253410Lennart Poettering };
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering int left;
13790add4bf648fed816361794d8277a75253410Lennart Poettering unsigned i;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering assert(argc >= 0);
13790add4bf648fed816361794d8277a75253410Lennart Poettering assert(argv);
13790add4bf648fed816361794d8277a75253410Lennart Poettering assert(error);
13790add4bf648fed816361794d8277a75253410Lennart Poettering
13790add4bf648fed816361794d8277a75253410Lennart Poettering left = argc - optind;
13790add4bf648fed816361794d8277a75253410Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (left <= 0)
7b77ed8cf36e8eca6017791626044b61ae2d68e7Lennart Poettering /* Special rule: no arguments means "status" */
13790add4bf648fed816361794d8277a75253410Lennart Poettering i = 0;
13790add4bf648fed816361794d8277a75253410Lennart Poettering else {
13790add4bf648fed816361794d8277a75253410Lennart Poettering if (streq(argv[optind], "help")) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering help();
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return 0;
15d91bff36c61d38df8edff258d1702a017a0e66Zbigniew Jędrzejewski-Szmek }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering for (i = 0; i < ELEMENTSOF(verbs); i++)
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (streq(argv[optind], verbs[i].verb))
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering break;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek if (i >= ELEMENTSOF(verbs)) {
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek log_error("Unknown operation %s", argv[optind]);
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek return -EINVAL;
b92bea5d2a9481de69bb627a7b442a9f58fca43dZbigniew Jędrzejewski-Szmek }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt switch (verbs[i].argc_cmp) {
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering case EQUAL:
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering if (left != verbs[i].argc) {
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering log_error("Invalid number of arguments.");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return -EINVAL;
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt }
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering break;
4a61c3e51e96a747c30598d78ee3a24e7c569e9fZbigniew Jędrzejewski-Szmek
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering case MORE:
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt if (left < verbs[i].argc) {
4a62c710b62a5a3c7a8a278b810b9d5b5a0c8f4fMichal Schmidt log_error("Too few arguments.");
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering return -EINVAL;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
151b9b9662a90455262ce575a8a8ae74bf4ff336Lennart Poettering break;
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt case LESS:
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering if (left > verbs[i].argc) {
f9a810bedacf1da7c505c1786a2416d592665926Lennart Poettering log_error("Too many arguments.");
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt return -EINVAL;
23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41Michal Schmidt }
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering break;
a45b9fca6b91a767dcd9060cfcb30617dad234c7Lennart Poettering
default:
assert_not_reached("Unknown comparison operator.");
}
if (!bus) {
log_error("Failed to get D-Bus connection: %s", error->message);
return -EIO;
}
return verbs[i].dispatch(bus, argv + optind, left);
}
int main(int argc, char *argv[]) {
int r, retval = EXIT_FAILURE;
DBusConnection *bus = NULL;
DBusError error;
dbus_error_init(&error);
log_parse_environment();
log_open();
r = parse_argv(argc, argv);
if (r < 0)
goto finish;
else if (r == 0) {
retval = EXIT_SUCCESS;
goto finish;
}
if (arg_transport == TRANSPORT_NORMAL)
bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
else if (arg_transport == TRANSPORT_POLKIT)
bus_connect_system_polkit(&bus, &error);
else if (arg_transport == TRANSPORT_SSH)
bus_connect_system_ssh(NULL, arg_host, &bus, &error);
else
assert_not_reached("Uh, invalid transport...");
r = localectl_main(bus, argc, argv, &error);
retval = r < 0 ? EXIT_FAILURE : r;
finish:
if (bus) {
dbus_connection_flush(bus);
dbus_connection_close(bus);
dbus_connection_unref(bus);
}
dbus_error_free(&error);
dbus_shutdown();
pager_close();
return retval;
}