summaryrefslogtreecommitdiff
path: root/src/locale
diff options
context:
space:
mode:
Diffstat (limited to 'src/locale')
-rw-r--r--src/locale/keymap-util.c23
-rw-r--r--src/locale/keymap-util.h1
-rw-r--r--src/locale/localectl.c85
-rw-r--r--src/locale/localed.c5
-rw-r--r--src/locale/meson.build22
-rw-r--r--src/locale/org.freedesktop.locale1.conf2
-rw-r--r--src/locale/org.freedesktop.locale1.policy.in10
-rw-r--r--src/locale/org.freedesktop.locale1.service2
-rw-r--r--src/locale/test-keymap-util.c1
9 files changed, 57 insertions, 94 deletions
diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c
index b71091f706..2d788106bb 100644
--- a/src/locale/keymap-util.c
+++ b/src/locale/keymap-util.c
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
@@ -19,6 +20,7 @@
***/
#include <errno.h>
+#include <stdio_ext.h>
#include <string.h>
#include <unistd.h>
@@ -200,9 +202,7 @@ static int x11_read_data(Context *c) {
p = &c->x11_options;
if (p) {
- free(*p);
- *p = a[2];
- a[2] = NULL;
+ free_and_replace(*p, a[2]);
}
}
@@ -359,14 +359,15 @@ int x11_write_data(Context *c) {
if (r < 0)
return r;
- fchmod(fileno(f), 0644);
+ (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+ (void) fchmod(fileno(f), 0644);
- fputs_unlocked("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n"
- "# probably wise not to edit this file manually. Use localectl(1) to\n"
- "# instruct systemd-localed to update it.\n"
- "Section \"InputClass\"\n"
- " Identifier \"system-keyboard\"\n"
- " MatchIsKeyboard \"on\"\n", f);
+ fputs("# Written by systemd-localed(8), read by systemd-localed and Xorg. It's\n"
+ "# probably wise not to edit this file manually. Use localectl(1) to\n"
+ "# instruct systemd-localed to update it.\n"
+ "Section \"InputClass\"\n"
+ " Identifier \"system-keyboard\"\n"
+ " MatchIsKeyboard \"on\"\n", f);
if (!isempty(c->x11_layout))
fprintf(f, " Option \"XkbLayout\" \"%s\"\n", c->x11_layout);
@@ -380,7 +381,7 @@ int x11_write_data(Context *c) {
if (!isempty(c->x11_options))
fprintf(f, " Option \"XkbOptions\" \"%s\"\n", c->x11_options);
- fputs_unlocked("EndSection\n", f);
+ fputs("EndSection\n", f);
r = fflush_sync_and_check(f);
if (r < 0)
diff --git a/src/locale/keymap-util.h b/src/locale/keymap-util.h
index 20ef2a4a34..371bbf2622 100644
--- a/src/locale/keymap-util.h
+++ b/src/locale/keymap-util.h
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 0bd18a5c0b..f09fe42626 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
@@ -46,18 +47,6 @@ static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
static char *arg_host = NULL;
static bool arg_convert = true;
-static void polkit_agent_open_if_enabled(void) {
-
- /* Open the polkit agent as a child process if necessary */
- if (!arg_ask_password)
- return;
-
- if (arg_transport != BUS_TRANSPORT_LOCAL)
- return;
-
- polkit_agent_open();
-}
-
typedef struct StatusInfo {
char **locale;
char *vconsole_keymap;
@@ -195,7 +184,7 @@ static int set_locale(sd_bus *bus, char **args, unsigned n) {
assert(bus);
assert(args);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = sd_bus_message_new_method_call(
bus,
@@ -253,7 +242,7 @@ static int set_vconsole_keymap(sd_bus *bus, char **args, unsigned n) {
return -EINVAL;
}
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
map = args[1];
toggle_map = n > 2 ? args[2] : "";
@@ -273,68 +262,15 @@ static int set_vconsole_keymap(sd_bus *bus, char **args, unsigned n) {
return r;
}
-static Set *keymaps = NULL;
-
-static int nftw_cb(
- const char *fpath,
- const struct stat *sb,
- int tflag,
- struct FTW *ftwbuf) {
-
- char *p, *e;
- int r;
-
- if (tflag != FTW_F)
- return 0;
-
- if (!endswith(fpath, ".map") &&
- !endswith(fpath, ".map.gz"))
- return 0;
-
- p = strdup(basename(fpath));
- if (!p)
- return log_oom();
-
- e = endswith(p, ".map");
- if (e)
- *e = 0;
-
- e = endswith(p, ".map.gz");
- if (e)
- *e = 0;
-
- r = set_consume(keymaps, p);
- if (r < 0 && r != -EEXIST)
- return log_error_errno(r, "Can't add keymap: %m");
-
- return 0;
-}
-
static int list_vconsole_keymaps(sd_bus *bus, char **args, unsigned n) {
_cleanup_strv_free_ char **l = NULL;
- const char *dir;
-
- keymaps = set_new(&string_hash_ops);
- if (!keymaps)
- return log_oom();
-
- NULSTR_FOREACH(dir, KBD_KEYMAP_DIRS)
- nftw(dir, nftw_cb, 20, FTW_MOUNT|FTW_PHYS);
-
- l = set_get_strv(keymaps);
- if (!l) {
- set_free_free(keymaps);
- return log_oom();
- }
-
- set_free(keymaps);
+ int r;
- if (strv_isempty(l)) {
- log_error("Couldn't find any console keymaps.");
- return -ENOENT;
- }
+ assert(args);
- strv_sort(l);
+ r = get_keymaps(&l);
+ if (r < 0)
+ return log_error_errno(r, "Failed to read list of keymaps: %m");
pager_open(arg_no_pager, false);
@@ -356,7 +292,7 @@ static int set_x11_keymap(sd_bus *bus, char **args, unsigned n) {
return -EINVAL;
}
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
layout = args[1];
model = n > 2 ? args[2] : "";
@@ -659,7 +595,7 @@ static int localectl_main(sd_bus *bus, int argc, char *argv[]) {
}
int main(int argc, char*argv[]) {
- sd_bus *bus = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
setlocale(LC_ALL, "");
@@ -679,7 +615,6 @@ int main(int argc, char*argv[]) {
r = localectl_main(bus, argc, argv);
finish:
- sd_bus_flush_close_unref(bus);
pager_close();
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 3c0c167dcf..3e3f03e046 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
@@ -380,7 +381,7 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
if ((keymap && (!filename_is_valid(keymap) || !string_is_safe(keymap))) ||
(keymap_toggle && (!filename_is_valid(keymap_toggle) || !string_is_safe(keymap_toggle))))
- return sd_bus_error_set_errnof(error, -EINVAL, "Received invalid keymap data");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Received invalid keymap data");
r = bus_verify_polkit_async(
m,
@@ -559,7 +560,7 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
(model && !string_is_safe(model)) ||
(variant && !string_is_safe(variant)) ||
(options && !string_is_safe(options)))
- return sd_bus_error_set_errnof(error, -EINVAL, "Received invalid keyboard data");
+ return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Received invalid keyboard data");
r = bus_verify_polkit_async(
m,
diff --git a/src/locale/meson.build b/src/locale/meson.build
index e9de6089f3..dca2c51d2f 100644
--- a/src/locale/meson.build
+++ b/src/locale/meson.build
@@ -1,3 +1,20 @@
+# SPDX-License-Identifier: LGPL-2.1+
+#
+# Copyright 2017 Zbigniew Jędrzejewski-Szmek
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# systemd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+
systemd_localed_sources = files('''
localed.c
keymap-util.c
@@ -12,11 +29,12 @@ if conf.get('ENABLE_LOCALED') == 1
install_data('org.freedesktop.locale1.service',
install_dir : dbussystemservicedir)
- custom_target(
+ i18n.merge_file(
'org.freedesktop.locale1.policy',
input : 'org.freedesktop.locale1.policy.in',
output : 'org.freedesktop.locale1.policy',
- command : intltool_command,
+ po_dir : po_dir,
+ data_dirs : po_dir,
install : install_polkit,
install_dir : polkitpolicydir)
endif
diff --git a/src/locale/org.freedesktop.locale1.conf b/src/locale/org.freedesktop.locale1.conf
index 2c5b2fa4b0..b6cbfaa7e0 100644
--- a/src/locale/org.freedesktop.locale1.conf
+++ b/src/locale/org.freedesktop.locale1.conf
@@ -3,6 +3,8 @@
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<!--
+ SPDX-License-Identifier: LGPL-2.1+
+
This file is part of systemd.
systemd is free software; you can redistribute it and/or modify it
diff --git a/src/locale/org.freedesktop.locale1.policy.in b/src/locale/org.freedesktop.locale1.policy.in
index df63845e9b..4c1c34da09 100644
--- a/src/locale/org.freedesktop.locale1.policy.in
+++ b/src/locale/org.freedesktop.locale1.policy.in
@@ -3,6 +3,8 @@
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<!--
+ SPDX-License-Identifier: LGPL-2.1+
+
This file is part of systemd.
systemd is free software; you can redistribute it and/or modify it
@@ -17,8 +19,8 @@
<vendor_url>http://www.freedesktop.org/wiki/Software/systemd</vendor_url>
<action id="org.freedesktop.locale1.set-locale">
- <_description>Set system locale</_description>
- <_message>Authentication is required to set the system locale.</_message>
+ <description>Set system locale</description>
+ <message>Authentication is required to set the system locale.</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_inactive>auth_admin_keep</allow_inactive>
@@ -28,8 +30,8 @@
</action>
<action id="org.freedesktop.locale1.set-keyboard">
- <_description>Set system keyboard settings</_description>
- <_message>Authentication is required to set the system keyboard settings.</_message>
+ <description>Set system keyboard settings</description>
+ <message>Authentication is required to set the system keyboard settings.</message>
<defaults>
<allow_any>auth_admin_keep</allow_any>
<allow_inactive>auth_admin_keep</allow_inactive>
diff --git a/src/locale/org.freedesktop.locale1.service b/src/locale/org.freedesktop.locale1.service
index 025f9a0fc2..b15d39540c 100644
--- a/src/locale/org.freedesktop.locale1.service
+++ b/src/locale/org.freedesktop.locale1.service
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1+
+#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
diff --git a/src/locale/test-keymap-util.c b/src/locale/test-keymap-util.c
index 2adda3da2b..fa26a0294e 100644
--- a/src/locale/test-keymap-util.c
+++ b/src/locale/test-keymap-util.c
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.