localectl.c revision 4d7859d173282e16bb75254c2b4ec14a915ef30b
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering This file is part of systemd.
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering Copyright 2012 Lennart Poettering
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering Copyright 2013 Kay Sievers
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering (at your option) any later version.
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering systemd is distributed in the hope that it will be useful, but
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering Lesser General Public License for more details.
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskogstatic bool arg_no_pager = false;
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskogstatic bool arg_ask_password = true;
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskogstatic BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskogstatic bool arg_convert = true;
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poetteringstatic void pager_open_if_enabled(void) {
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskogstatic void polkit_agent_open_if_enabled(void) {
5ffa8c818120e35c89becd938d160235c069dd12Zbigniew Jędrzejewski-Szmek /* Open the polkit agent as a child process if necessary */
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poetteringtypedef struct StatusInfo {
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskogstatic void print_status_info(StatusInfo *i) {
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering printf(" System Locale: %s\n", i->locale[0]);
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering printf(" VC Keymap: %s\n", strna(i->vconsole_keymap));
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering printf("VC Toggle Keymap: %s\n", i->vconsole_keymap_toggle);
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering printf(" X11 Layout: %s\n", strna(i->x11_layout));
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering printf(" X11 Model: %s\n", i->x11_model);
ad79565d6b37bcc93cf773a39b975e5b85d122daUmut Tezduyar Lindskog printf(" X11 Variant: %s\n", i->x11_variant);
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poettering printf(" X11 Options: %s\n", i->x11_options);
3b7124a8db56ed57525b9ecfd19cfdc8c9facba0Lennart Poetteringstatic int status_read_property(const char *name, sd_bus_message *property, StatusInfo *i) {
56f64d95763a799ba4475daf44d8e9f72a1bd474Michal Schmidt r = sd_bus_message_peek_type(property, &type, &contents);
03e334a1c7dc8c20c38902aa039440763acc9b17Lennart Poettering log_error("Could not determine type of message: %s", strerror(-r));
switch (type) {
case SD_BUS_TYPE_STRING: {
if (isempty(s))
i->vconsole_keymap = s;
i->vconsole_keymap_toggle = s;
i->x11_layout = s;
i->x11_model = s;
i->x11_variant = s;
i->x11_options = s;
case SD_BUS_TYPE_ARRAY: {
i->locale = l;
l = NULL;
"/org/freedesktop/locale1",
&error,
&reply,
goto fail;
const char *name;
const char *contents;
goto fail;
goto fail;
goto fail;
goto fail;
goto fail;
fail:
"/org/freedesktop/locale1",
struct locarhead {
struct namehashent {
const struct locarhead *h;
const struct namehashent *e;
const void *p = MAP_FAILED;
if (fd < 0) {
r = -errno;
goto finish;
r = -errno;
goto finish;
r = -EBADMSG;
goto finish;
r = -EBADMSG;
goto finish;
if (p == MAP_FAILED) {
r = -errno;
goto finish;
h = (const struct locarhead *) p;
r = -EBADMSG;
goto finish;
for (i = 0; i < h->namehash_size; i++) {
if (e[i].locrec_offset == 0)
r = log_oom();
goto finish;
goto finish;
if (p != MAP_FAILED)
if (!dir) {
return -errno;
errno = 0;
return log_oom();
if (r < 0 && r != -EEXIST) {
errno = 0;
if (errno > 0) {
return -errno;
if (!locales)
return log_oom();
if (r < 0 && r != -ENOENT)
return log_oom();
strv_sort(l);
strv_print(l);
return -EINVAL;
"/org/freedesktop/locale1",
&error,
NULL,
static int nftw_cb(
const char *fpath,
int tflag,
return log_oom();
if (r < 0 && r != -EEXIST) {
if (!keymaps)
return log_oom();
return log_oom();
if (strv_isempty(l)) {
return -ENOENT;
strv_sort(l);
strv_print(l);
return -EINVAL;
"/org/freedesktop/locale1",
&error,
NULL,
NONE,
return -EINVAL;
return -errno;
if (isempty(l))
return log_oom();
return -ENOENT;
static int help(void) {
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;
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;
goto finish;
pager_close();
return ret;