localectl.c revision 7568345034f2890af745747783c5abfbf6eccf0f
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2012 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2013 Kay Sievers
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool arg_no_pager = false;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool arg_ask_password = true;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool arg_convert = true;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic void pager_open_if_enabled(void) {
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poetteringstatic void polkit_agent_open_if_enabled(void) {
e1c959948c0e31d6997bcdfbabfbd077784b2baeLennart Poettering /* Open the polkit agent as a child process if necessary */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (arg_transport != BUS_TRANSPORT_LOCAL)
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringtypedef struct StatusInfo {
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poetteringstatic void print_status_info(StatusInfo *i) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering printf(" System Locale: %s\n", i->locale[0]);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering printf(" VC Keymap: %s\n", strna(i->vconsole_keymap));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering printf("VC Toggle Keymap: %s\n", i->vconsole_keymap_toggle);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering printf(" X11 Layout: %s\n", strna(i->x11_layout));
3cb10d3a0b1b6a7c44f307f2abb5215104e16941Lennart Poettering printf(" X11 Model: %s\n", i->x11_model);
3cb10d3a0b1b6a7c44f307f2abb5215104e16941Lennart Poettering printf(" X11 Variant: %s\n", i->x11_variant);
ad867662936a4c7ab2c7116d804c272338801231Lennart Poettering printf(" X11 Options: %s\n", i->x11_options);
8b757a38611006a751c90933d1810cccaa47e1afDaniel Mackstatic int show_status(sd_bus *bus, char **args, unsigned n) {
8b757a38611006a751c90933d1810cccaa47e1afDaniel Mack static const struct bus_properties_map map[] = {
8b757a38611006a751c90933d1810cccaa47e1afDaniel Mack { "VConsoleKeymap", "s", NULL, offsetof(StatusInfo, vconsole_keymap) },
8b757a38611006a751c90933d1810cccaa47e1afDaniel Mack { "VConsoleKeymap", "s", NULL, offsetof(StatusInfo, vconsole_keymap) },
8b757a38611006a751c90933d1810cccaa47e1afDaniel Mack { "VConsoleKeymapToggle", "s", NULL, offsetof(StatusInfo, vconsole_keymap_toggle) },
8b757a38611006a751c90933d1810cccaa47e1afDaniel Mack { "X11Layout", "s", NULL, offsetof(StatusInfo, x11_layout) },
8b757a38611006a751c90933d1810cccaa47e1afDaniel Mack { "X11Model", "s", NULL, offsetof(StatusInfo, x11_model) },
3cb10d3a0b1b6a7c44f307f2abb5215104e16941Lennart Poettering { "X11Variant", "s", NULL, offsetof(StatusInfo, x11_variant) },
3cb10d3a0b1b6a7c44f307f2abb5215104e16941Lennart Poettering { "X11Options", "s", NULL, offsetof(StatusInfo, x11_options) },
3cb10d3a0b1b6a7c44f307f2abb5215104e16941Lennart Poettering { "Locale", "as", NULL, offsetof(StatusInfo, locale) },
f0258e473667f44f4656dde49597b2badb9f598aLennart Poettering "org.freedesktop.locale1",
3cb10d3a0b1b6a7c44f307f2abb5215104e16941Lennart Poettering log_error("Could not get properties: %s", strerror(-r));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int set_locale(sd_bus *bus, char **args, unsigned n) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering "org.freedesktop.locale1",
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek "org.freedesktop.locale1",
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = sd_bus_message_append_strv(m, args + 1);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = sd_bus_message_append(m, "b", arg_ask_password);
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek return bus_log_create_error(r);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering r = sd_bus_call(bus, m, 0, &error, NULL);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Failed to issue method call: %s", bus_error_message(&error, -r));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int list_locales(sd_bus *bus, char **args, unsigned n) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Failed to read list of locales: %s", strerror(-r));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int set_vconsole_keymap(sd_bus *bus, char **args, unsigned n) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek polkit_agent_open_if_enabled();
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek toggle_map = n > 2 ? args[2] : "";
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek "org.freedesktop.locale1",
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek "org.freedesktop.locale1",
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek "SetVConsoleKeyboard",
ff3d6560bead6879a2fed1bf99bfe8273b3723f1Zbigniew Jędrzejewski-Szmek "ssbb", map, toggle_map, arg_convert, arg_ask_password);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen log_error("Failed to set keymap: %s", bus_error_message(&error, -r));
if (r < 0 && r != -EEXIST) {
const char *dir;
if (!keymaps)
return log_oom();
return log_oom();
if (strv_isempty(l)) {
return -ENOENT;
strv_sort(l);
strv_print(l);
return -EINVAL;
r = sd_bus_call_method(
bus,
"/org/freedesktop/locale1",
&error,
NULL,
NONE,
return -EINVAL;
return -errno;
if (isempty(l))
return log_oom();
return -ENOENT;
static int help(void) {
return help();
case ARG_VERSION:
case ARG_NO_CONVERT:
arg_convert = false;
case ARG_NO_PAGER:
arg_no_pager = true;
case ARG_NO_ASK_PASSWORD:
arg_ask_password = false;
return -EINVAL;
const char* verb;
MORE,
LESS,
} argc_cmp;
const int argc;
} verbs[] = {
int left;
if (left <= 0)
help();
return -EINVAL;
case EQUAL:
return -EINVAL;
case MORE:
return -EINVAL;
case LESS:
return -EINVAL;
log_open();
goto finish;
goto finish;
pager_close();