2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2015-09-23 03:01:06 +02:00
|
|
|
#include <ftw.h>
|
|
|
|
#include <getopt.h>
|
2012-10-19 04:55:49 +02:00
|
|
|
#include <stdbool.h>
|
2015-09-23 03:01:06 +02:00
|
|
|
#include <stdlib.h>
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2013-10-30 22:50:09 +01:00
|
|
|
#include "sd-bus.h"
|
2015-09-23 03:01:06 +02:00
|
|
|
|
2013-10-30 22:50:09 +01:00
|
|
|
#include "bus-error.h"
|
2020-06-28 15:59:37 +02:00
|
|
|
#include "bus-locator.h"
|
2020-06-28 16:08:37 +02:00
|
|
|
#include "bus-map-properties.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "fd-util.h"
|
2014-09-24 13:17:43 +02:00
|
|
|
#include "fileio.h"
|
2019-03-14 12:40:29 +01:00
|
|
|
#include "kbd-util.h"
|
2014-07-07 11:49:48 +02:00
|
|
|
#include "locale-util.h"
|
2018-11-20 09:56:18 +01:00
|
|
|
#include "main-func.h"
|
2019-03-13 12:02:21 +01:00
|
|
|
#include "memory-util.h"
|
2015-09-23 03:01:06 +02:00
|
|
|
#include "pager.h"
|
2018-11-20 15:42:57 +01:00
|
|
|
#include "pretty-print.h"
|
2018-11-12 13:49:20 +01:00
|
|
|
#include "proc-cmdline.h"
|
2015-09-23 03:01:06 +02:00
|
|
|
#include "set.h"
|
|
|
|
#include "spawn-polkit-agent.h"
|
|
|
|
#include "strv.h"
|
2019-10-08 18:19:59 +02:00
|
|
|
#include "terminal-util.h"
|
2018-03-14 06:50:40 +01:00
|
|
|
#include "verbs.h"
|
2015-09-23 03:01:06 +02:00
|
|
|
#include "virt.h"
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2018-11-11 12:56:29 +01:00
|
|
|
static PagerFlags arg_pager_flags = 0;
|
2012-10-19 04:55:49 +02:00
|
|
|
static bool arg_ask_password = true;
|
2013-10-30 22:50:09 +01:00
|
|
|
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
|
2018-11-20 10:08:33 +01:00
|
|
|
static const char *arg_host = NULL;
|
2012-10-19 04:55:49 +02:00
|
|
|
static bool arg_convert = true;
|
|
|
|
|
|
|
|
typedef struct StatusInfo {
|
|
|
|
char **locale;
|
2018-03-19 15:46:29 +01:00
|
|
|
const char *vconsole_keymap;
|
|
|
|
const char *vconsole_keymap_toggle;
|
|
|
|
const char *x11_layout;
|
|
|
|
const char *x11_model;
|
|
|
|
const char *x11_variant;
|
|
|
|
const char *x11_options;
|
2012-10-19 04:55:49 +02:00
|
|
|
} StatusInfo;
|
|
|
|
|
2015-06-14 15:08:52 +02:00
|
|
|
static void status_info_clear(StatusInfo *info) {
|
|
|
|
if (info) {
|
|
|
|
strv_free(info->locale);
|
|
|
|
zero(*info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-11 13:49:29 +02:00
|
|
|
static void print_overridden_variables(void) {
|
2018-11-12 16:50:58 +01:00
|
|
|
_cleanup_(locale_variables_freep) char *variables[_VARIABLE_LC_MAX] = {};
|
2014-09-24 13:17:43 +02:00
|
|
|
bool print_warning = true;
|
2018-11-12 16:50:58 +01:00
|
|
|
LocaleVariable j;
|
|
|
|
int r;
|
2014-09-24 13:17:43 +02:00
|
|
|
|
2018-11-12 13:49:20 +01:00
|
|
|
if (arg_transport != BUS_TRANSPORT_LOCAL)
|
2014-09-24 13:17:43 +02:00
|
|
|
return;
|
|
|
|
|
2018-11-12 13:49:20 +01:00
|
|
|
r = proc_cmdline_get_key_many(
|
|
|
|
PROC_CMDLINE_STRIP_RD_PREFIX,
|
|
|
|
"locale.LANG", &variables[VARIABLE_LANG],
|
|
|
|
"locale.LANGUAGE", &variables[VARIABLE_LANGUAGE],
|
|
|
|
"locale.LC_CTYPE", &variables[VARIABLE_LC_CTYPE],
|
|
|
|
"locale.LC_NUMERIC", &variables[VARIABLE_LC_NUMERIC],
|
|
|
|
"locale.LC_TIME", &variables[VARIABLE_LC_TIME],
|
|
|
|
"locale.LC_COLLATE", &variables[VARIABLE_LC_COLLATE],
|
|
|
|
"locale.LC_MONETARY", &variables[VARIABLE_LC_MONETARY],
|
|
|
|
"locale.LC_MESSAGES", &variables[VARIABLE_LC_MESSAGES],
|
|
|
|
"locale.LC_PAPER", &variables[VARIABLE_LC_PAPER],
|
|
|
|
"locale.LC_NAME", &variables[VARIABLE_LC_NAME],
|
|
|
|
"locale.LC_ADDRESS", &variables[VARIABLE_LC_ADDRESS],
|
|
|
|
"locale.LC_TELEPHONE", &variables[VARIABLE_LC_TELEPHONE],
|
|
|
|
"locale.LC_MEASUREMENT", &variables[VARIABLE_LC_MEASUREMENT],
|
|
|
|
"locale.LC_IDENTIFICATION", &variables[VARIABLE_LC_IDENTIFICATION]);
|
2014-09-24 13:17:43 +02:00
|
|
|
if (r < 0 && r != -ENOENT) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_warning_errno(r, "Failed to read /proc/cmdline: %m");
|
2018-11-12 16:50:58 +01:00
|
|
|
return;
|
2014-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
2014-10-02 14:34:55 +02:00
|
|
|
for (j = 0; j < _VARIABLE_LC_MAX; j++)
|
2014-09-24 13:17:43 +02:00
|
|
|
if (variables[j]) {
|
|
|
|
if (print_warning) {
|
2014-10-02 14:35:34 +02:00
|
|
|
log_warning("Warning: Settings on kernel command line override system locale settings in /etc/locale.conf.\n"
|
2016-03-24 02:58:38 +01:00
|
|
|
" Command Line: %s=%s", locale_variable_to_string(j), variables[j]);
|
2014-09-24 13:17:43 +02:00
|
|
|
|
|
|
|
print_warning = false;
|
2014-10-02 14:35:34 +02:00
|
|
|
} else
|
2016-03-24 02:58:38 +01:00
|
|
|
log_warning(" %s=%s", locale_variable_to_string(j), variables[j]);
|
2014-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-19 04:55:49 +02:00
|
|
|
static void print_status_info(StatusInfo *i) {
|
|
|
|
assert(i);
|
|
|
|
|
|
|
|
if (strv_isempty(i->locale))
|
2016-03-24 02:44:36 +01:00
|
|
|
puts(" System Locale: n/a");
|
2012-10-19 04:55:49 +02:00
|
|
|
else {
|
|
|
|
char **j;
|
|
|
|
|
|
|
|
printf(" System Locale: %s\n", i->locale[0]);
|
|
|
|
STRV_FOREACH(j, i->locale + 1)
|
|
|
|
printf(" %s\n", *j);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" VC Keymap: %s\n", strna(i->vconsole_keymap));
|
|
|
|
if (!isempty(i->vconsole_keymap_toggle))
|
|
|
|
printf("VC Toggle Keymap: %s\n", i->vconsole_keymap_toggle);
|
|
|
|
|
|
|
|
printf(" X11 Layout: %s\n", strna(i->x11_layout));
|
|
|
|
if (!isempty(i->x11_model))
|
|
|
|
printf(" X11 Model: %s\n", i->x11_model);
|
|
|
|
if (!isempty(i->x11_variant))
|
|
|
|
printf(" X11 Variant: %s\n", i->x11_variant);
|
|
|
|
if (!isempty(i->x11_options))
|
|
|
|
printf(" X11 Options: %s\n", i->x11_options);
|
|
|
|
}
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static int show_status(int argc, char **argv, void *userdata) {
|
2015-06-14 15:08:52 +02:00
|
|
|
_cleanup_(status_info_clear) StatusInfo info = {};
|
2013-11-05 02:57:49 +01:00
|
|
|
static const struct bus_properties_map map[] = {
|
|
|
|
{ "VConsoleKeymap", "s", NULL, offsetof(StatusInfo, vconsole_keymap) },
|
|
|
|
{ "VConsoleKeymapToggle", "s", NULL, offsetof(StatusInfo, vconsole_keymap_toggle) },
|
|
|
|
{ "X11Layout", "s", NULL, offsetof(StatusInfo, x11_layout) },
|
|
|
|
{ "X11Model", "s", NULL, offsetof(StatusInfo, x11_model) },
|
|
|
|
{ "X11Variant", "s", NULL, offsetof(StatusInfo, x11_variant) },
|
|
|
|
{ "X11Options", "s", NULL, offsetof(StatusInfo, x11_options) },
|
|
|
|
{ "Locale", "as", NULL, offsetof(StatusInfo, locale) },
|
2013-11-02 00:10:12 +01:00
|
|
|
{}
|
|
|
|
};
|
2017-02-08 17:59:58 +01:00
|
|
|
|
|
|
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
2018-03-19 15:46:29 +01:00
|
|
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
2018-03-14 06:50:40 +01:00
|
|
|
sd_bus *bus = userdata;
|
2013-11-02 00:10:12 +01:00
|
|
|
int r;
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2013-11-02 00:10:12 +01:00
|
|
|
assert(bus);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2013-11-02 00:10:12 +01:00
|
|
|
r = bus_map_all_properties(bus,
|
|
|
|
"org.freedesktop.locale1",
|
|
|
|
"/org/freedesktop/locale1",
|
2013-11-05 02:57:49 +01:00
|
|
|
map,
|
2018-03-28 13:37:27 +02:00
|
|
|
0,
|
2017-02-08 17:59:58 +01:00
|
|
|
&error,
|
2018-03-19 15:46:29 +01:00
|
|
|
&m,
|
2013-11-05 02:57:49 +01:00
|
|
|
&info);
|
2015-06-14 15:08:52 +02:00
|
|
|
if (r < 0)
|
2017-02-08 17:59:58 +01:00
|
|
|
return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2015-05-11 13:49:29 +02:00
|
|
|
print_overridden_variables();
|
2012-10-19 04:55:49 +02:00
|
|
|
print_status_info(&info);
|
2013-10-30 22:50:09 +01:00
|
|
|
|
|
|
|
return r;
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static int set_locale(int argc, char **argv, void *userdata) {
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
|
|
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
2018-03-14 06:50:40 +01:00
|
|
|
sd_bus *bus = userdata;
|
2012-10-19 04:55:49 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
|
2017-10-30 09:57:53 +01:00
|
|
|
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2020-05-03 07:45:52 +02:00
|
|
|
r = bus_message_new_method_call(bus, &m, bus_locale, "SetLocale");
|
2013-10-30 22:50:09 +01:00
|
|
|
if (r < 0)
|
2013-11-08 19:48:42 +01:00
|
|
|
return bus_log_create_error(r);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
r = sd_bus_message_append_strv(m, argv + 1);
|
2013-10-30 22:50:09 +01:00
|
|
|
if (r < 0)
|
2013-11-08 19:48:42 +01:00
|
|
|
return bus_log_create_error(r);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2013-10-30 22:50:09 +01:00
|
|
|
r = sd_bus_message_append(m, "b", arg_ask_password);
|
2012-10-19 04:55:49 +02:00
|
|
|
if (r < 0)
|
2013-11-08 19:48:42 +01:00
|
|
|
return bus_log_create_error(r);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2013-11-11 18:55:34 +01:00
|
|
|
r = sd_bus_call(bus, m, 0, &error, NULL);
|
2018-08-07 03:14:30 +02:00
|
|
|
if (r < 0)
|
2020-09-14 18:16:54 +02:00
|
|
|
return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r));
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2013-10-30 22:50:09 +01:00
|
|
|
return 0;
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static int list_locales(int argc, char **argv, void *userdata) {
|
2013-01-05 01:29:53 +01:00
|
|
|
_cleanup_strv_free_ char **l = NULL;
|
|
|
|
int r;
|
|
|
|
|
2014-07-07 11:49:48 +02:00
|
|
|
r = get_locales(&l);
|
2014-11-28 18:50:43 +01:00
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to read list of locales: %m");
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2018-11-11 12:56:29 +01:00
|
|
|
(void) pager_open(arg_pager_flags);
|
2013-02-07 00:15:27 +01:00
|
|
|
strv_print(l);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2013-01-07 17:43:41 +01:00
|
|
|
return 0;
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static int set_vconsole_keymap(int argc, char **argv, void *userdata) {
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
2012-10-19 04:55:49 +02:00
|
|
|
const char *map, *toggle_map;
|
2018-03-14 06:50:40 +01:00
|
|
|
sd_bus *bus = userdata;
|
2013-10-31 03:12:37 +01:00
|
|
|
int r;
|
2012-10-19 04:55:49 +02:00
|
|
|
|
|
|
|
assert(bus);
|
|
|
|
|
2017-10-30 09:57:53 +01:00
|
|
|
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
map = argv[1];
|
|
|
|
toggle_map = argc > 2 ? argv[2] : "";
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2020-05-03 07:45:52 +02:00
|
|
|
r = bus_call_method(
|
2013-10-31 03:12:37 +01:00
|
|
|
bus,
|
2020-05-03 07:45:52 +02:00
|
|
|
bus_locale,
|
2012-10-19 04:55:49 +02:00
|
|
|
"SetVConsoleKeyboard",
|
2013-10-30 22:50:09 +01:00
|
|
|
&error,
|
2012-10-19 04:55:49 +02:00
|
|
|
NULL,
|
2013-10-30 22:50:09 +01:00
|
|
|
"ssbb", map, toggle_map, arg_convert, arg_ask_password);
|
2013-10-31 03:12:37 +01:00
|
|
|
if (r < 0)
|
2020-09-14 18:16:54 +02:00
|
|
|
return log_error_errno(r, "Failed to set keymap: %s", bus_error_message(&error, r));
|
2013-10-31 03:12:37 +01:00
|
|
|
|
2018-08-07 03:14:30 +02:00
|
|
|
return 0;
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static int list_vconsole_keymaps(int argc, char **argv, void *userdata) {
|
2017-12-01 09:37:52 +01:00
|
|
|
_cleanup_strv_free_ char **l = NULL;
|
2017-11-10 10:31:44 +01:00
|
|
|
int r;
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2017-11-10 10:31:44 +01:00
|
|
|
r = get_keymaps(&l);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to read list of keymaps: %m");
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2018-11-11 12:56:29 +01:00
|
|
|
(void) pager_open(arg_pager_flags);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2013-02-07 00:15:27 +01:00
|
|
|
strv_print(l);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static int set_x11_keymap(int argc, char **argv, void *userdata) {
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
2012-10-19 04:55:49 +02:00
|
|
|
const char *layout, *model, *variant, *options;
|
2018-03-14 06:50:40 +01:00
|
|
|
sd_bus *bus = userdata;
|
2013-10-31 03:12:37 +01:00
|
|
|
int r;
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2017-10-30 09:57:53 +01:00
|
|
|
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
layout = argv[1];
|
|
|
|
model = argc > 2 ? argv[2] : "";
|
|
|
|
variant = argc > 3 ? argv[3] : "";
|
|
|
|
options = argc > 4 ? argv[4] : "";
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2020-05-03 07:45:52 +02:00
|
|
|
r = bus_call_method(
|
2013-10-31 03:12:37 +01:00
|
|
|
bus,
|
2020-05-03 07:45:52 +02:00
|
|
|
bus_locale,
|
2012-10-19 04:55:49 +02:00
|
|
|
"SetX11Keyboard",
|
2013-10-30 22:50:09 +01:00
|
|
|
&error,
|
2012-10-19 04:55:49 +02:00
|
|
|
NULL,
|
2013-10-30 22:50:09 +01:00
|
|
|
"ssssbb", layout, model, variant, options,
|
|
|
|
arg_convert, arg_ask_password);
|
2013-10-31 03:12:37 +01:00
|
|
|
if (r < 0)
|
2020-09-14 18:16:54 +02:00
|
|
|
return log_error_errno(r, "Failed to set keymap: %s", bus_error_message(&error, r));
|
2013-10-31 03:12:37 +01:00
|
|
|
|
2018-08-07 03:14:30 +02:00
|
|
|
return 0;
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static int list_x11_keymaps(int argc, char **argv, void *userdata) {
|
2013-04-05 00:23:23 +02:00
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
2013-04-18 09:11:22 +02:00
|
|
|
_cleanup_strv_free_ char **list = NULL;
|
2013-04-05 00:23:23 +02:00
|
|
|
enum {
|
|
|
|
NONE,
|
|
|
|
MODELS,
|
|
|
|
LAYOUTS,
|
|
|
|
VARIANTS,
|
|
|
|
OPTIONS
|
|
|
|
} state = NONE, look_for;
|
|
|
|
int r;
|
|
|
|
|
2013-04-15 01:30:18 +02:00
|
|
|
f = fopen("/usr/share/X11/xkb/rules/base.lst", "re");
|
2014-11-28 19:57:32 +01:00
|
|
|
if (!f)
|
|
|
|
return log_error_errno(errno, "Failed to open keyboard mapping list. %m");
|
2013-04-05 00:23:23 +02:00
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
if (streq(argv[0], "list-x11-keymap-models"))
|
2013-04-05 00:23:23 +02:00
|
|
|
look_for = MODELS;
|
2018-03-14 06:50:40 +01:00
|
|
|
else if (streq(argv[0], "list-x11-keymap-layouts"))
|
2013-04-05 00:23:23 +02:00
|
|
|
look_for = LAYOUTS;
|
2018-03-14 06:50:40 +01:00
|
|
|
else if (streq(argv[0], "list-x11-keymap-variants"))
|
2013-04-05 00:23:23 +02:00
|
|
|
look_for = VARIANTS;
|
2018-03-14 06:50:40 +01:00
|
|
|
else if (streq(argv[0], "list-x11-keymap-options"))
|
2013-04-05 00:23:23 +02:00
|
|
|
look_for = OPTIONS;
|
|
|
|
else
|
|
|
|
assert_not_reached("Wrong parameter");
|
|
|
|
|
2018-10-18 16:15:35 +02:00
|
|
|
for (;;) {
|
|
|
|
_cleanup_free_ char *line = NULL;
|
2013-04-05 00:23:23 +02:00
|
|
|
char *l, *w;
|
|
|
|
|
2018-10-18 16:15:35 +02:00
|
|
|
r = read_line(f, LONG_LINE_MAX, &line);
|
|
|
|
if (r < 0)
|
|
|
|
return log_error_errno(r, "Failed to read keyboard mapping list: %m");
|
|
|
|
if (r == 0)
|
|
|
|
break;
|
|
|
|
|
2013-04-05 00:23:23 +02:00
|
|
|
l = strstrip(line);
|
|
|
|
|
|
|
|
if (isempty(l))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (l[0] == '!') {
|
|
|
|
if (startswith(l, "! model"))
|
|
|
|
state = MODELS;
|
|
|
|
else if (startswith(l, "! layout"))
|
|
|
|
state = LAYOUTS;
|
|
|
|
else if (startswith(l, "! variant"))
|
|
|
|
state = VARIANTS;
|
|
|
|
else if (startswith(l, "! option"))
|
|
|
|
state = OPTIONS;
|
|
|
|
else
|
|
|
|
state = NONE;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state != look_for)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
w = l + strcspn(l, WHITESPACE);
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
if (argc > 1) {
|
2013-04-05 00:23:23 +02:00
|
|
|
char *e;
|
|
|
|
|
|
|
|
if (*w == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*w = 0;
|
|
|
|
w++;
|
|
|
|
w += strspn(w, WHITESPACE);
|
|
|
|
|
|
|
|
e = strchr(w, ':');
|
|
|
|
if (!e)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*e = 0;
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
if (!streq(w, argv[1]))
|
2013-04-05 00:23:23 +02:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
*w = 0;
|
|
|
|
|
2015-08-06 00:31:09 +02:00
|
|
|
r = strv_extend(&list, l);
|
|
|
|
if (r < 0)
|
|
|
|
return log_oom();
|
2013-04-05 00:23:23 +02:00
|
|
|
}
|
|
|
|
|
2018-11-20 23:40:44 +01:00
|
|
|
if (strv_isempty(list))
|
|
|
|
return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
|
|
|
|
"Couldn't find any entries.");
|
2013-04-05 00:23:23 +02:00
|
|
|
|
|
|
|
strv_sort(list);
|
|
|
|
strv_uniq(list);
|
|
|
|
|
2018-11-11 12:56:29 +01:00
|
|
|
(void) pager_open(arg_pager_flags);
|
2013-04-05 00:23:23 +02:00
|
|
|
|
|
|
|
strv_print(list);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static int help(void) {
|
2018-08-09 10:32:31 +02:00
|
|
|
_cleanup_free_ char *link = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = terminal_urlify_man("localectl", "1", &link);
|
|
|
|
if (r < 0)
|
|
|
|
return log_oom();
|
|
|
|
|
2019-11-15 18:38:44 +01:00
|
|
|
printf("%s [OPTIONS...] COMMAND ...\n\n"
|
|
|
|
"%sQuery or change system locale and keyboard settings.%s\n"
|
|
|
|
"\nCommands:\n"
|
2013-04-05 00:23:23 +02:00
|
|
|
" status Show current locale settings\n"
|
|
|
|
" set-locale LOCALE... Set system locale\n"
|
|
|
|
" list-locales Show known locales\n"
|
2014-12-11 06:02:54 +01:00
|
|
|
" set-keymap MAP [MAP] Set console and X11 keyboard mappings\n"
|
2013-04-05 00:23:23 +02:00
|
|
|
" list-keymaps Show known virtual console keyboard mappings\n"
|
2014-11-03 14:01:04 +01:00
|
|
|
" set-x11-keymap LAYOUT [MODEL [VARIANT [OPTIONS]]]\n"
|
2014-12-11 06:02:54 +01:00
|
|
|
" Set X11 and console keyboard mappings\n"
|
2013-04-05 00:23:23 +02:00
|
|
|
" list-x11-keymap-models Show known X11 keyboard mapping models\n"
|
|
|
|
" list-x11-keymap-layouts Show known X11 keyboard mapping layouts\n"
|
|
|
|
" list-x11-keymap-variants [LAYOUT]\n"
|
|
|
|
" Show known X11 keyboard mapping variants\n"
|
2014-08-02 17:12:21 +02:00
|
|
|
" list-x11-keymap-options Show known X11 keyboard mapping options\n"
|
2019-11-15 18:38:44 +01:00
|
|
|
"\nOptions:\n"
|
|
|
|
" -h --help Show this help\n"
|
|
|
|
" --version Show package version\n"
|
|
|
|
" --no-pager Do not pipe output into a pager\n"
|
|
|
|
" --no-ask-password Do not prompt for password\n"
|
|
|
|
" -H --host=[USER@]HOST Operate on remote host\n"
|
|
|
|
" -M --machine=CONTAINER Operate on local container\n"
|
|
|
|
" --no-convert Don't convert keyboard mappings\n"
|
2018-08-09 10:32:31 +02:00
|
|
|
"\nSee the %s for details.\n"
|
|
|
|
, program_invocation_short_name
|
2019-11-15 18:38:44 +01:00
|
|
|
, ansi_highlight()
|
2019-10-08 18:19:59 +02:00
|
|
|
, ansi_normal()
|
2018-08-09 10:32:31 +02:00
|
|
|
, link
|
|
|
|
);
|
2018-03-14 06:50:40 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int verb_help(int argc, char **argv, void *userdata) {
|
|
|
|
return help();
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_argv(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_VERSION = 0x100,
|
|
|
|
ARG_NO_PAGER,
|
|
|
|
ARG_NO_CONVERT,
|
|
|
|
ARG_NO_ASK_PASSWORD
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct option options[] = {
|
2013-10-30 22:50:09 +01:00
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "version", no_argument, NULL, ARG_VERSION },
|
|
|
|
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
|
|
|
|
{ "host", required_argument, NULL, 'H' },
|
|
|
|
{ "machine", required_argument, NULL, 'M' },
|
|
|
|
{ "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
|
|
|
|
{ "no-convert", no_argument, NULL, ARG_NO_CONVERT },
|
2013-11-06 18:28:39 +01:00
|
|
|
{}
|
2012-10-19 04:55:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
assert(argc >= 0);
|
|
|
|
assert(argv);
|
|
|
|
|
2014-08-02 17:12:21 +02:00
|
|
|
while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0)
|
2012-10-19 04:55:49 +02:00
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
|
|
|
case 'h':
|
2018-03-14 06:50:40 +01:00
|
|
|
return help();
|
2012-10-19 04:55:49 +02:00
|
|
|
|
|
|
|
case ARG_VERSION:
|
2015-09-23 03:01:06 +02:00
|
|
|
return version();
|
2012-10-19 04:55:49 +02:00
|
|
|
|
|
|
|
case ARG_NO_CONVERT:
|
|
|
|
arg_convert = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_NO_PAGER:
|
2018-11-11 12:56:29 +01:00
|
|
|
arg_pager_flags |= PAGER_DISABLE;
|
2012-10-19 04:55:49 +02:00
|
|
|
break;
|
|
|
|
|
2013-05-17 15:38:12 +02:00
|
|
|
case ARG_NO_ASK_PASSWORD:
|
|
|
|
arg_ask_password = false;
|
|
|
|
break;
|
|
|
|
|
2013-10-30 22:50:09 +01:00
|
|
|
case 'H':
|
|
|
|
arg_transport = BUS_TRANSPORT_REMOTE;
|
|
|
|
arg_host = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
2014-12-23 23:38:13 +01:00
|
|
|
arg_transport = BUS_TRANSPORT_MACHINE;
|
2013-10-30 22:50:09 +01:00
|
|
|
arg_host = optarg;
|
|
|
|
break;
|
|
|
|
|
2012-10-19 04:55:49 +02:00
|
|
|
case '?':
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
default:
|
2013-11-06 18:28:39 +01:00
|
|
|
assert_not_reached("Unhandled option");
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-10-30 22:50:09 +01:00
|
|
|
static int localectl_main(sd_bus *bus, int argc, char *argv[]) {
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
static const Verb verbs[] = {
|
|
|
|
{ "status", VERB_ANY, 1, VERB_DEFAULT, show_status },
|
|
|
|
{ "set-locale", 2, VERB_ANY, 0, set_locale },
|
|
|
|
{ "list-locales", VERB_ANY, 1, 0, list_locales },
|
|
|
|
{ "set-keymap", 2, 3, 0, set_vconsole_keymap },
|
|
|
|
{ "list-keymaps", VERB_ANY, 1, 0, list_vconsole_keymaps },
|
|
|
|
{ "set-x11-keymap", 2, 5, 0, set_x11_keymap },
|
|
|
|
{ "list-x11-keymap-models", VERB_ANY, 1, 0, list_x11_keymaps },
|
|
|
|
{ "list-x11-keymap-layouts", VERB_ANY, 1, 0, list_x11_keymaps },
|
|
|
|
{ "list-x11-keymap-variants", VERB_ANY, 2, 0, list_x11_keymaps },
|
|
|
|
{ "list-x11-keymap-options", VERB_ANY, 1, 0, list_x11_keymaps },
|
|
|
|
{ "help", VERB_ANY, VERB_ANY, 0, verb_help }, /* Not documented, but supported since it is created. */
|
|
|
|
{}
|
2012-10-19 04:55:49 +02:00
|
|
|
};
|
|
|
|
|
2018-03-14 06:50:40 +01:00
|
|
|
return dispatch_verb(argc, argv, verbs, bus);
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
|
|
|
|
2018-12-04 09:29:54 +01:00
|
|
|
static int run(int argc, char *argv[]) {
|
2018-11-20 09:56:18 +01:00
|
|
|
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
2013-11-06 17:32:51 +01:00
|
|
|
int r;
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2012-11-12 20:16:07 +01:00
|
|
|
setlocale(LC_ALL, "");
|
2020-06-17 21:17:54 +02:00
|
|
|
log_setup_cli();
|
2012-10-19 04:55:49 +02:00
|
|
|
|
|
|
|
r = parse_argv(argc, argv);
|
2013-11-06 17:32:51 +01:00
|
|
|
if (r <= 0)
|
2018-11-20 09:56:18 +01:00
|
|
|
return r;
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2015-09-24 13:30:10 +02:00
|
|
|
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
|
2018-11-20 09:56:18 +01:00
|
|
|
if (r < 0)
|
2020-07-20 13:20:52 +02:00
|
|
|
return bus_log_connect_error(r);
|
2012-10-19 04:55:49 +02:00
|
|
|
|
2018-11-20 09:56:18 +01:00
|
|
|
return localectl_main(bus, argc, argv);
|
2012-10-19 04:55:49 +02:00
|
|
|
}
|
2018-11-20 09:56:18 +01:00
|
|
|
|
|
|
|
DEFINE_MAIN_FUNCTION(run);
|