File: | build-scan/../src/locale/localed.c |
Warning: | line 60, column 41 Potential leak of memory pointed to by 'l_set' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | ||||
3 | #include <errno(*__errno_location ()).h> | |||
4 | #include <string.h> | |||
5 | #include <unistd.h> | |||
6 | ||||
7 | #if HAVE_XKBCOMMON1 | |||
8 | #include <xkbcommon/xkbcommon.h> | |||
9 | #include <dlfcn.h> | |||
10 | #endif | |||
11 | ||||
12 | #include "sd-bus.h" | |||
13 | ||||
14 | #include "alloc-util.h" | |||
15 | #include "bus-error.h" | |||
16 | #include "bus-message.h" | |||
17 | #include "bus-util.h" | |||
18 | #include "def.h" | |||
19 | #include "keymap-util.h" | |||
20 | #include "locale-util.h" | |||
21 | #include "macro.h" | |||
22 | #include "path-util.h" | |||
23 | #include "selinux-util.h" | |||
24 | #include "string-util.h" | |||
25 | #include "strv.h" | |||
26 | #include "user-util.h" | |||
27 | ||||
28 | static Hashmap *polkit_registry = NULL((void*)0); | |||
29 | ||||
30 | static int locale_update_system_manager(Context *c, sd_bus *bus) { | |||
31 | _cleanup_free___attribute__((cleanup(freep))) char **l_unset = NULL((void*)0); | |||
32 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l_set = NULL((void*)0); | |||
33 | _cleanup_(sd_bus_message_unrefp)__attribute__((cleanup(sd_bus_message_unrefp))) sd_bus_message *m = NULL((void*)0); | |||
34 | sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0}); | |||
35 | unsigned c_set, c_unset, p; | |||
36 | int r; | |||
37 | ||||
38 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/locale/localed.c", 38, __PRETTY_FUNCTION__ ); } while (0); | |||
| ||||
39 | ||||
40 | l_unset = new0(char*, _VARIABLE_LC_MAX)((char**) calloc((_VARIABLE_LC_MAX), sizeof(char*))); | |||
41 | if (!l_unset) | |||
42 | return -ENOMEM12; | |||
43 | ||||
44 | l_set = new0(char*, _VARIABLE_LC_MAX)((char**) calloc((_VARIABLE_LC_MAX), sizeof(char*))); | |||
45 | if (!l_set) | |||
46 | return -ENOMEM12; | |||
47 | ||||
48 | for (p = 0, c_set = 0, c_unset = 0; p < _VARIABLE_LC_MAX; p++) { | |||
49 | const char *name; | |||
50 | ||||
51 | name = locale_variable_to_string(p); | |||
52 | assert(name)do { if ((__builtin_expect(!!(!(name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("name"), "../src/locale/localed.c", 52, __PRETTY_FUNCTION__ ); } while (0); | |||
53 | ||||
54 | if (isempty(c->locale[p])) | |||
55 | l_unset[c_set++] = (char*) name; | |||
56 | else { | |||
57 | char *s; | |||
58 | ||||
59 | if (asprintf(&s, "%s=%s", name, c->locale[p]) < 0) | |||
60 | return -ENOMEM12; | |||
| ||||
61 | ||||
62 | l_set[c_unset++] = s; | |||
63 | } | |||
64 | } | |||
65 | ||||
66 | assert(c_set + c_unset == _VARIABLE_LC_MAX)do { if ((__builtin_expect(!!(!(c_set + c_unset == _VARIABLE_LC_MAX )),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("c_set + c_unset == _VARIABLE_LC_MAX" ), "../src/locale/localed.c", 66, __PRETTY_FUNCTION__); } while (0); | |||
67 | r = sd_bus_message_new_method_call(bus, &m, | |||
68 | "org.freedesktop.systemd1", | |||
69 | "/org/freedesktop/systemd1", | |||
70 | "org.freedesktop.systemd1.Manager", | |||
71 | "UnsetAndSetEnvironment"); | |||
72 | if (r < 0) | |||
73 | return r; | |||
74 | ||||
75 | r = sd_bus_message_append_strv(m, l_unset); | |||
76 | if (r < 0) | |||
77 | return r; | |||
78 | ||||
79 | r = sd_bus_message_append_strv(m, l_set); | |||
80 | if (r < 0) | |||
81 | return r; | |||
82 | ||||
83 | r = sd_bus_call(bus, m, 0, &error, NULL((void*)0)); | |||
84 | if (r < 0) | |||
85 | log_error_errno(r, "Failed to update the manager environment, ignoring: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 85, __func__, "Failed to update the manager environment, ignoring: %m" ) : -abs(_e); }); | |||
86 | ||||
87 | return 0; | |||
88 | } | |||
89 | ||||
90 | static int vconsole_reload(sd_bus *bus) { | |||
91 | _cleanup_(sd_bus_error_free)__attribute__((cleanup(sd_bus_error_free))) sd_bus_error error = SD_BUS_ERROR_NULL((const sd_bus_error) {(((void*)0)), (((void*)0)), 0}); | |||
92 | int r; | |||
93 | ||||
94 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/locale/localed.c", 94, __PRETTY_FUNCTION__ ); } while (0); | |||
95 | ||||
96 | r = sd_bus_call_method(bus, | |||
97 | "org.freedesktop.systemd1", | |||
98 | "/org/freedesktop/systemd1", | |||
99 | "org.freedesktop.systemd1.Manager", | |||
100 | "RestartUnit", | |||
101 | &error, | |||
102 | NULL((void*)0), | |||
103 | "ss", "systemd-vconsole-setup.service", "replace"); | |||
104 | ||||
105 | if (r < 0) | |||
106 | return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, -r))({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 106, __func__, "Failed to issue method call: %s" , bus_error_message(&error, -r)) : -abs(_e); }); | |||
107 | ||||
108 | return 0; | |||
109 | } | |||
110 | ||||
111 | static int vconsole_convert_to_x11_and_emit(Context *c, sd_bus_message *m) { | |||
112 | int r; | |||
113 | ||||
114 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/locale/localed.c", 114, __PRETTY_FUNCTION__ ); } while (0); | |||
115 | ||||
116 | r = x11_read_data(c, m); | |||
117 | if (r < 0) | |||
118 | return r; | |||
119 | ||||
120 | r = vconsole_convert_to_x11(c); | |||
121 | if (r <= 0) | |||
122 | return r; | |||
123 | ||||
124 | /* modified */ | |||
125 | r = x11_write_data(c); | |||
126 | if (r < 0) | |||
127 | return log_error_errno(r, "Failed to write X11 keyboard layout: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 127, __func__, "Failed to write X11 keyboard layout: %m" ) : -abs(_e); }); | |||
128 | ||||
129 | sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), | |||
130 | "/org/freedesktop/locale1", | |||
131 | "org.freedesktop.locale1", | |||
132 | "X11Layout", "X11Model", "X11Variant", "X11Options", NULL((void*)0)); | |||
133 | ||||
134 | return 1; | |||
135 | } | |||
136 | ||||
137 | static int x11_convert_to_vconsole_and_emit(Context *c, sd_bus_message *m) { | |||
138 | int r; | |||
139 | ||||
140 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/locale/localed.c", 140, __PRETTY_FUNCTION__ ); } while (0); | |||
141 | ||||
142 | r = vconsole_read_data(c, m); | |||
143 | if (r < 0) | |||
144 | return r; | |||
145 | ||||
146 | r = x11_convert_to_vconsole(c); | |||
147 | if (r <= 0) | |||
148 | return r; | |||
149 | ||||
150 | /* modified */ | |||
151 | r = vconsole_write_data(c); | |||
152 | if (r < 0) | |||
153 | log_error_errno(r, "Failed to save virtual console keymap: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 153, __func__, "Failed to save virtual console keymap: %m" ) : -abs(_e); }); | |||
154 | ||||
155 | sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), | |||
156 | "/org/freedesktop/locale1", | |||
157 | "org.freedesktop.locale1", | |||
158 | "VConsoleKeymap", "VConsoleKeymapToggle", NULL((void*)0)); | |||
159 | ||||
160 | return vconsole_reload(sd_bus_message_get_bus(m)); | |||
161 | } | |||
162 | ||||
163 | static int property_get_locale( | |||
164 | sd_bus *bus, | |||
165 | const char *path, | |||
166 | const char *interface, | |||
167 | const char *property, | |||
168 | sd_bus_message *reply, | |||
169 | void *userdata, | |||
170 | sd_bus_error *error) { | |||
171 | ||||
172 | Context *c = userdata; | |||
173 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0); | |||
174 | int p, q, r; | |||
175 | ||||
176 | r = locale_read_data(c, reply); | |||
177 | if (r < 0) | |||
178 | return r; | |||
179 | ||||
180 | l = new0(char*, _VARIABLE_LC_MAX+1)((char**) calloc((_VARIABLE_LC_MAX+1), sizeof(char*))); | |||
181 | if (!l) | |||
182 | return -ENOMEM12; | |||
183 | ||||
184 | for (p = 0, q = 0; p < _VARIABLE_LC_MAX; p++) { | |||
185 | char *t; | |||
186 | const char *name; | |||
187 | ||||
188 | name = locale_variable_to_string(p); | |||
189 | assert(name)do { if ((__builtin_expect(!!(!(name)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("name"), "../src/locale/localed.c", 189, __PRETTY_FUNCTION__); } while (0); | |||
190 | ||||
191 | if (isempty(c->locale[p])) | |||
192 | continue; | |||
193 | ||||
194 | if (asprintf(&t, "%s=%s", name, c->locale[p]) < 0) | |||
195 | return -ENOMEM12; | |||
196 | ||||
197 | l[q++] = t; | |||
198 | } | |||
199 | ||||
200 | return sd_bus_message_append_strv(reply, l); | |||
201 | } | |||
202 | ||||
203 | static int property_get_vconsole( | |||
204 | sd_bus *bus, | |||
205 | const char *path, | |||
206 | const char *interface, | |||
207 | const char *property, | |||
208 | sd_bus_message *reply, | |||
209 | void *userdata, | |||
210 | sd_bus_error *error) { | |||
211 | ||||
212 | Context *c = userdata; | |||
213 | int r; | |||
214 | ||||
215 | r = vconsole_read_data(c, reply); | |||
216 | if (r < 0) | |||
217 | return r; | |||
218 | ||||
219 | if (streq(property, "VConsoleKeymap")(strcmp((property),("VConsoleKeymap")) == 0)) | |||
220 | return sd_bus_message_append_basic(reply, 's', c->vc_keymap); | |||
221 | else if (streq(property, "VConsoleKeymapToggle")(strcmp((property),("VConsoleKeymapToggle")) == 0)) | |||
222 | return sd_bus_message_append_basic(reply, 's', c->vc_keymap_toggle); | |||
223 | ||||
224 | return -EINVAL22; | |||
225 | } | |||
226 | ||||
227 | static int property_get_xkb( | |||
228 | sd_bus *bus, | |||
229 | const char *path, | |||
230 | const char *interface, | |||
231 | const char *property, | |||
232 | sd_bus_message *reply, | |||
233 | void *userdata, | |||
234 | sd_bus_error *error) { | |||
235 | ||||
236 | Context *c = userdata; | |||
237 | int r; | |||
238 | ||||
239 | r = x11_read_data(c, reply); | |||
240 | if (r < 0) | |||
241 | return r; | |||
242 | ||||
243 | if (streq(property, "X11Layout")(strcmp((property),("X11Layout")) == 0)) | |||
244 | return sd_bus_message_append_basic(reply, 's', c->x11_layout); | |||
245 | else if (streq(property, "X11Model")(strcmp((property),("X11Model")) == 0)) | |||
246 | return sd_bus_message_append_basic(reply, 's', c->x11_model); | |||
247 | else if (streq(property, "X11Variant")(strcmp((property),("X11Variant")) == 0)) | |||
248 | return sd_bus_message_append_basic(reply, 's', c->x11_variant); | |||
249 | else if (streq(property, "X11Options")(strcmp((property),("X11Options")) == 0)) | |||
250 | return sd_bus_message_append_basic(reply, 's', c->x11_options); | |||
251 | ||||
252 | return -EINVAL22; | |||
253 | } | |||
254 | ||||
255 | static void locale_free(char ***l) { | |||
256 | int p; | |||
257 | ||||
258 | for (p = 0; p < _VARIABLE_LC_MAX; p++) | |||
259 | (*l)[p] = mfree((*l)[p]); | |||
260 | } | |||
261 | ||||
262 | static int process_locale_list_item( | |||
263 | const char *assignment, | |||
264 | char *new_locale[static _VARIABLE_LC_MAX], | |||
265 | sd_bus_error *error) { | |||
266 | ||||
267 | assert(assignment)do { if ((__builtin_expect(!!(!(assignment)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("assignment"), "../src/locale/localed.c" , 267, __PRETTY_FUNCTION__); } while (0); | |||
268 | assert(new_locale)do { if ((__builtin_expect(!!(!(new_locale)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("new_locale"), "../src/locale/localed.c" , 268, __PRETTY_FUNCTION__); } while (0); | |||
269 | ||||
270 | for (LocaleVariable p = 0; p < _VARIABLE_LC_MAX; p++) { | |||
271 | const char *name, *e; | |||
272 | ||||
273 | assert_se(name = locale_variable_to_string(p))do { if ((__builtin_expect(!!(!(name = locale_variable_to_string (p))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("name = locale_variable_to_string(p)" ), "../src/locale/localed.c", 273, __PRETTY_FUNCTION__); } while (0); | |||
274 | ||||
275 | e = startswith(assignment, name); | |||
276 | if (!e) | |||
277 | continue; | |||
278 | ||||
279 | if (*e != '=') | |||
280 | continue; | |||
281 | ||||
282 | e++; | |||
283 | ||||
284 | if (!locale_is_valid(e)) | |||
285 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Locale %s is not valid, refusing.", e); | |||
286 | if (locale_is_installed(e) <= 0) | |||
287 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Locale %s not installed, refusing.", e); | |||
288 | if (new_locale[p]) | |||
289 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Locale variable %s set twice, refusing.", name); | |||
290 | ||||
291 | new_locale[p] = strdup(e); | |||
292 | if (!new_locale[p]) | |||
293 | return -ENOMEM12; | |||
294 | ||||
295 | return 0; | |||
296 | } | |||
297 | ||||
298 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Locale assignment %s not valid, refusing.", assignment); | |||
299 | } | |||
300 | ||||
301 | static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *error) { | |||
302 | Context *c = userdata; | |||
303 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **settings = NULL((void*)0), **l = NULL((void*)0); | |||
304 | char *new_locale[_VARIABLE_LC_MAX] = {}, **i; | |||
305 | _cleanup_(locale_free)__attribute__((cleanup(locale_free))) _unused___attribute__ ((unused)) char **dummy = new_locale; | |||
306 | bool_Bool modified = false0; | |||
307 | int interactive, r; | |||
308 | ||||
309 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/locale/localed.c", 309, __PRETTY_FUNCTION__ ); } while (0); | |||
310 | assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("c"), "../src/locale/localed.c", 310, __PRETTY_FUNCTION__ ); } while (0); | |||
311 | ||||
312 | r = sd_bus_message_read_strv(m, &l); | |||
313 | if (r < 0) | |||
314 | return r; | |||
315 | ||||
316 | r = sd_bus_message_read_basic(m, 'b', &interactive); | |||
317 | if (r < 0) | |||
318 | return r; | |||
319 | ||||
320 | /* If single locale without variable name is provided, then we assume it is LANG=. */ | |||
321 | if (strv_length(l) == 1 && !strchr(l[0], '=')) { | |||
322 | if (!locale_is_valid(l[0])) | |||
323 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Invalid locale specification: %s", l[0]); | |||
324 | if (locale_is_installed(l[0]) <= 0) | |||
325 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Specified locale is not installed: %s", l[0]); | |||
326 | ||||
327 | new_locale[VARIABLE_LANG] = strdup(l[0]); | |||
328 | if (!new_locale[VARIABLE_LANG]) | |||
329 | return -ENOMEM12; | |||
330 | ||||
331 | l = strv_free(l); | |||
332 | } | |||
333 | ||||
334 | /* Check whether a variable is valid */ | |||
335 | STRV_FOREACH(i, l)for ((i) = (l); (i) && *(i); (i)++) { | |||
336 | r = process_locale_list_item(*i, new_locale, error); | |||
337 | if (r < 0) | |||
338 | return r; | |||
339 | } | |||
340 | ||||
341 | /* If LANG was specified, but not LANGUAGE, check if we should | |||
342 | * set it based on the language fallback table. */ | |||
343 | if (!isempty(new_locale[VARIABLE_LANG]) && | |||
344 | isempty(new_locale[VARIABLE_LANGUAGE])) { | |||
345 | _cleanup_free___attribute__((cleanup(freep))) char *language = NULL((void*)0); | |||
346 | ||||
347 | (void) find_language_fallback(new_locale[VARIABLE_LANG], &language); | |||
348 | if (language) { | |||
349 | log_debug("Converted LANG=%s to LANGUAGE=%s", new_locale[VARIABLE_LANG], language)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 349, __func__, "Converted LANG=%s to LANGUAGE=%s" , new_locale[VARIABLE_LANG], language) : -abs(_e); }); | |||
350 | free_and_replace(new_locale[VARIABLE_LANGUAGE], language)({ free(new_locale[VARIABLE_LANGUAGE]); (new_locale[VARIABLE_LANGUAGE ]) = (language); (language) = ((void*)0); 0; }); | |||
351 | } | |||
352 | } | |||
353 | ||||
354 | r = locale_read_data(c, m); | |||
355 | if (r < 0) { | |||
356 | log_error_errno(r, "Failed to read locale data: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 356, __func__, "Failed to read locale data: %m" ) : -abs(_e); }); | |||
357 | return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED"org.freedesktop.DBus.Error.Failed", "Failed to read locale data"); | |||
358 | } | |||
359 | ||||
360 | /* Merge with the current settings */ | |||
361 | for (LocaleVariable p = 0; p < _VARIABLE_LC_MAX; p++) | |||
362 | if (!isempty(c->locale[p]) && isempty(new_locale[p])) { | |||
363 | new_locale[p] = strdup(c->locale[p]); | |||
364 | if (!new_locale[p]) | |||
365 | return -ENOMEM12; | |||
366 | } | |||
367 | ||||
368 | locale_simplify(new_locale); | |||
369 | ||||
370 | for (LocaleVariable p = 0; p < _VARIABLE_LC_MAX; p++) | |||
371 | if (!streq_ptr(c->locale[p], new_locale[p])) { | |||
372 | modified = true1; | |||
373 | break; | |||
374 | } | |||
375 | ||||
376 | if (!modified) { | |||
377 | log_debug("Locale settings were not modified.")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 377, __func__, "Locale settings were not modified." ) : -abs(_e); }); | |||
378 | return sd_bus_reply_method_return(m, NULL((void*)0)); | |||
379 | } | |||
380 | ||||
381 | r = bus_verify_polkit_async( | |||
382 | m, | |||
383 | CAP_SYS_ADMIN21, | |||
384 | "org.freedesktop.locale1.set-locale", | |||
385 | NULL((void*)0), | |||
386 | interactive, | |||
387 | UID_INVALID((uid_t) -1), | |||
388 | &polkit_registry, | |||
389 | error); | |||
390 | if (r < 0) | |||
391 | return r; | |||
392 | if (r == 0) | |||
393 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
394 | ||||
395 | for (LocaleVariable p = 0; p < _VARIABLE_LC_MAX; p++) | |||
396 | free_and_replace(c->locale[p], new_locale[p])({ free(c->locale[p]); (c->locale[p]) = (new_locale[p]) ; (new_locale[p]) = ((void*)0); 0; }); | |||
397 | ||||
398 | r = locale_write_data(c, &settings); | |||
399 | if (r < 0) { | |||
400 | log_error_errno(r, "Failed to set locale: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 400, __func__, "Failed to set locale: %m" ) : -abs(_e); }); | |||
401 | return sd_bus_error_set_errnof(error, r, "Failed to set locale: %m"); | |||
402 | } | |||
403 | ||||
404 | (void) locale_update_system_manager(c, sd_bus_message_get_bus(m)); | |||
405 | ||||
406 | if (settings) { | |||
407 | _cleanup_free___attribute__((cleanup(freep))) char *line; | |||
408 | ||||
409 | line = strv_join(settings, ", "); | |||
410 | log_info("Changed locale to %s.", strnull(line))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 410, __func__, "Changed locale to %s." , strnull(line)) : -abs(_e); }); | |||
411 | } else | |||
412 | log_info("Changed locale to unset.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 412, __func__, "Changed locale to unset." ) : -abs(_e); }); | |||
413 | ||||
414 | (void) sd_bus_emit_properties_changed( | |||
415 | sd_bus_message_get_bus(m), | |||
416 | "/org/freedesktop/locale1", | |||
417 | "org.freedesktop.locale1", | |||
418 | "Locale", NULL((void*)0)); | |||
419 | ||||
420 | return sd_bus_reply_method_return(m, NULL((void*)0)); | |||
421 | } | |||
422 | ||||
423 | static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_error *error) { | |||
424 | Context *c = userdata; | |||
425 | const char *keymap, *keymap_toggle; | |||
426 | int convert, interactive, r; | |||
427 | ||||
428 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/locale/localed.c", 428, __PRETTY_FUNCTION__ ); } while (0); | |||
429 | assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("c"), "../src/locale/localed.c", 429, __PRETTY_FUNCTION__ ); } while (0); | |||
430 | ||||
431 | r = sd_bus_message_read(m, "ssbb", &keymap, &keymap_toggle, &convert, &interactive); | |||
432 | if (r < 0) | |||
433 | return r; | |||
434 | ||||
435 | keymap = empty_to_null(keymap); | |||
436 | keymap_toggle = empty_to_null(keymap_toggle); | |||
437 | ||||
438 | r = vconsole_read_data(c, m); | |||
439 | if (r < 0) { | |||
440 | log_error_errno(r, "Failed to read virtual console keymap data: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 440, __func__, "Failed to read virtual console keymap data: %m" ) : -abs(_e); }); | |||
441 | return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED"org.freedesktop.DBus.Error.Failed", "Failed to read virtual console keymap data"); | |||
442 | } | |||
443 | ||||
444 | if (streq_ptr(keymap, c->vc_keymap) && | |||
445 | streq_ptr(keymap_toggle, c->vc_keymap_toggle)) | |||
446 | return sd_bus_reply_method_return(m, NULL((void*)0)); | |||
447 | ||||
448 | if ((keymap && (!filename_is_valid(keymap) || !string_is_safe(keymap))) || | |||
449 | (keymap_toggle && (!filename_is_valid(keymap_toggle) || !string_is_safe(keymap_toggle)))) | |||
450 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Received invalid keymap data"); | |||
451 | ||||
452 | r = bus_verify_polkit_async( | |||
453 | m, | |||
454 | CAP_SYS_ADMIN21, | |||
455 | "org.freedesktop.locale1.set-keyboard", | |||
456 | NULL((void*)0), | |||
457 | interactive, | |||
458 | UID_INVALID((uid_t) -1), | |||
459 | &polkit_registry, | |||
460 | error); | |||
461 | if (r < 0) | |||
462 | return r; | |||
463 | if (r == 0) | |||
464 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
465 | ||||
466 | if (free_and_strdup(&c->vc_keymap, keymap) < 0 || | |||
467 | free_and_strdup(&c->vc_keymap_toggle, keymap_toggle) < 0) | |||
468 | return -ENOMEM12; | |||
469 | ||||
470 | r = vconsole_write_data(c); | |||
471 | if (r < 0) { | |||
472 | log_error_errno(r, "Failed to set virtual console keymap: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 472, __func__, "Failed to set virtual console keymap: %m" ) : -abs(_e); }); | |||
473 | return sd_bus_error_set_errnof(error, r, "Failed to set virtual console keymap: %m"); | |||
474 | } | |||
475 | ||||
476 | log_info("Changed virtual console keymap to '%s' toggle '%s'",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 477, __func__, "Changed virtual console keymap to '%s' toggle '%s'" , strempty(c->vc_keymap), strempty(c->vc_keymap_toggle) ) : -abs(_e); }) | |||
477 | strempty(c->vc_keymap), strempty(c->vc_keymap_toggle))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 477, __func__, "Changed virtual console keymap to '%s' toggle '%s'" , strempty(c->vc_keymap), strempty(c->vc_keymap_toggle) ) : -abs(_e); }); | |||
478 | ||||
479 | r = vconsole_reload(sd_bus_message_get_bus(m)); | |||
480 | if (r < 0) | |||
481 | log_error_errno(r, "Failed to request keymap reload: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 481, __func__, "Failed to request keymap reload: %m" ) : -abs(_e); }); | |||
482 | ||||
483 | (void) sd_bus_emit_properties_changed( | |||
484 | sd_bus_message_get_bus(m), | |||
485 | "/org/freedesktop/locale1", | |||
486 | "org.freedesktop.locale1", | |||
487 | "VConsoleKeymap", "VConsoleKeymapToggle", NULL((void*)0)); | |||
488 | ||||
489 | if (convert) { | |||
490 | r = vconsole_convert_to_x11_and_emit(c, m); | |||
491 | if (r < 0) | |||
492 | log_error_errno(r, "Failed to convert keymap data: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 492, __func__, "Failed to convert keymap data: %m" ) : -abs(_e); }); | |||
493 | } | |||
494 | ||||
495 | return sd_bus_reply_method_return(m, NULL((void*)0)); | |||
496 | } | |||
497 | ||||
498 | #if HAVE_XKBCOMMON1 | |||
499 | ||||
500 | _printf_(3, 0)__attribute__ ((format (printf, 3, 0))) | |||
501 | static void log_xkb(struct xkb_context *ctx, enum xkb_log_level lvl, const char *format, va_list args) { | |||
502 | const char *fmt; | |||
503 | ||||
504 | fmt = strjoina("libxkbcommon: ", format)({ const char *_appendees_[] = { "libxkbcommon: ", format }; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p (typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_ )/sizeof((_appendees_)[0]), ((void)0))) && _appendees_ [_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr ( !__builtin_types_compatible_p(typeof(_appendees_), typeof(& *(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0] ), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy (_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); | |||
505 | #pragma GCC diagnostic push | |||
506 | #pragma GCC diagnostic ignored "-Wformat-nonliteral" | |||
507 | log_internalv(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, fmt, args)log_internalv_realm(((LOG_REALM_SYSTEMD) << 10 | ((7))) , 0, "../src/locale/localed.c", 507, __func__, fmt, args); | |||
508 | #pragma GCC diagnostic pop | |||
509 | } | |||
510 | ||||
511 | #define LOAD_SYMBOL(symbol, dl, name)({ (symbol) = (typeof(symbol)) dlvsym((dl), (name), "V_0.5.0" ); (symbol) ? 0 : -95; }) \ | |||
512 | ({ \ | |||
513 | (symbol) = (typeof(symbol)) dlvsym((dl), (name), "V_0.5.0"); \ | |||
514 | (symbol) ? 0 : -EOPNOTSUPP95; \ | |||
515 | }) | |||
516 | ||||
517 | static int verify_xkb_rmlvo(const char *model, const char *layout, const char *variant, const char *options) { | |||
518 | ||||
519 | /* We dlopen() the library in order to make the dependency soft. The library (and what it pulls in) is huge | |||
520 | * after all, hence let's support XKB maps when the library is around, and refuse otherwise. The function | |||
521 | * pointers to the shared library are below: */ | |||
522 | ||||
523 | struct xkb_context* (*symbol_xkb_context_new)(enum xkb_context_flags flags) = NULL((void*)0); | |||
524 | void (*symbol_xkb_context_unref)(struct xkb_context *context) = NULL((void*)0); | |||
525 | void (*symbol_xkb_context_set_log_fn)(struct xkb_context *context, void (*log_fn)(struct xkb_context *context, enum xkb_log_level level, const char *format, va_list args)) = NULL((void*)0); | |||
526 | struct xkb_keymap* (*symbol_xkb_keymap_new_from_names)(struct xkb_context *context, const struct xkb_rule_names *names, enum xkb_keymap_compile_flags flags) = NULL((void*)0); | |||
527 | void (*symbol_xkb_keymap_unref)(struct xkb_keymap *keymap) = NULL((void*)0); | |||
528 | ||||
529 | const struct xkb_rule_names rmlvo = { | |||
530 | .model = model, | |||
531 | .layout = layout, | |||
532 | .variant = variant, | |||
533 | .options = options, | |||
534 | }; | |||
535 | struct xkb_context *ctx = NULL((void*)0); | |||
536 | struct xkb_keymap *km = NULL((void*)0); | |||
537 | void *dl; | |||
538 | int r; | |||
539 | ||||
540 | /* Compile keymap from RMLVO information to check out its validity */ | |||
541 | ||||
542 | dl = dlopen("libxkbcommon.so.0", RTLD_LAZY0x00001); | |||
543 | if (!dl) | |||
544 | return -EOPNOTSUPP95; | |||
545 | ||||
546 | r = LOAD_SYMBOL(symbol_xkb_context_new, dl, "xkb_context_new")({ (symbol_xkb_context_new) = (typeof(symbol_xkb_context_new) ) dlvsym((dl), ("xkb_context_new"), "V_0.5.0"); (symbol_xkb_context_new ) ? 0 : -95; }); | |||
547 | if (r < 0) | |||
548 | goto finish; | |||
549 | ||||
550 | r = LOAD_SYMBOL(symbol_xkb_context_unref, dl, "xkb_context_unref")({ (symbol_xkb_context_unref) = (typeof(symbol_xkb_context_unref )) dlvsym((dl), ("xkb_context_unref"), "V_0.5.0"); (symbol_xkb_context_unref ) ? 0 : -95; }); | |||
551 | if (r < 0) | |||
552 | goto finish; | |||
553 | ||||
554 | r = LOAD_SYMBOL(symbol_xkb_context_set_log_fn, dl, "xkb_context_set_log_fn")({ (symbol_xkb_context_set_log_fn) = (typeof(symbol_xkb_context_set_log_fn )) dlvsym((dl), ("xkb_context_set_log_fn"), "V_0.5.0"); (symbol_xkb_context_set_log_fn ) ? 0 : -95; }); | |||
555 | if (r < 0) | |||
556 | goto finish; | |||
557 | ||||
558 | r = LOAD_SYMBOL(symbol_xkb_keymap_new_from_names, dl, "xkb_keymap_new_from_names")({ (symbol_xkb_keymap_new_from_names) = (typeof(symbol_xkb_keymap_new_from_names )) dlvsym((dl), ("xkb_keymap_new_from_names"), "V_0.5.0"); (symbol_xkb_keymap_new_from_names ) ? 0 : -95; }); | |||
559 | if (r < 0) | |||
560 | goto finish; | |||
561 | ||||
562 | r = LOAD_SYMBOL(symbol_xkb_keymap_unref, dl, "xkb_keymap_unref")({ (symbol_xkb_keymap_unref) = (typeof(symbol_xkb_keymap_unref )) dlvsym((dl), ("xkb_keymap_unref"), "V_0.5.0"); (symbol_xkb_keymap_unref ) ? 0 : -95; }); | |||
563 | if (r < 0) | |||
564 | goto finish; | |||
565 | ||||
566 | ctx = symbol_xkb_context_new(XKB_CONTEXT_NO_ENVIRONMENT_NAMES); | |||
567 | if (!ctx) { | |||
568 | r = -ENOMEM12; | |||
569 | goto finish; | |||
570 | } | |||
571 | ||||
572 | symbol_xkb_context_set_log_fn(ctx, log_xkb); | |||
573 | ||||
574 | km = symbol_xkb_keymap_new_from_names(ctx, &rmlvo, XKB_KEYMAP_COMPILE_NO_FLAGS); | |||
575 | if (!km) { | |||
576 | r = -EINVAL22; | |||
577 | goto finish; | |||
578 | } | |||
579 | ||||
580 | r = 0; | |||
581 | ||||
582 | finish: | |||
583 | if (symbol_xkb_keymap_unref && km) | |||
584 | symbol_xkb_keymap_unref(km); | |||
585 | ||||
586 | if (symbol_xkb_context_unref && ctx) | |||
587 | symbol_xkb_context_unref(ctx); | |||
588 | ||||
589 | (void) dlclose(dl); | |||
590 | return r; | |||
591 | } | |||
592 | ||||
593 | #else | |||
594 | ||||
595 | static int verify_xkb_rmlvo(const char *model, const char *layout, const char *variant, const char *options) { | |||
596 | return 0; | |||
597 | } | |||
598 | ||||
599 | #endif | |||
600 | ||||
601 | static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_error *error) { | |||
602 | Context *c = userdata; | |||
603 | const char *layout, *model, *variant, *options; | |||
604 | int convert, interactive, r; | |||
605 | ||||
606 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/locale/localed.c", 606, __PRETTY_FUNCTION__ ); } while (0); | |||
607 | assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("c"), "../src/locale/localed.c", 607, __PRETTY_FUNCTION__ ); } while (0); | |||
608 | ||||
609 | r = sd_bus_message_read(m, "ssssbb", &layout, &model, &variant, &options, &convert, &interactive); | |||
610 | if (r < 0) | |||
611 | return r; | |||
612 | ||||
613 | layout = empty_to_null(layout); | |||
614 | model = empty_to_null(model); | |||
615 | variant = empty_to_null(variant); | |||
616 | options = empty_to_null(options); | |||
617 | ||||
618 | r = x11_read_data(c, m); | |||
619 | if (r < 0) { | |||
620 | log_error_errno(r, "Failed to read x11 keyboard layout data: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 620, __func__, "Failed to read x11 keyboard layout data: %m" ) : -abs(_e); }); | |||
621 | return sd_bus_error_setf(error, SD_BUS_ERROR_FAILED"org.freedesktop.DBus.Error.Failed", "Failed to read x11 keyboard layout data"); | |||
622 | } | |||
623 | ||||
624 | if (streq_ptr(layout, c->x11_layout) && | |||
625 | streq_ptr(model, c->x11_model) && | |||
626 | streq_ptr(variant, c->x11_variant) && | |||
627 | streq_ptr(options, c->x11_options)) | |||
628 | return sd_bus_reply_method_return(m, NULL((void*)0)); | |||
629 | ||||
630 | if ((layout && !string_is_safe(layout)) || | |||
631 | (model && !string_is_safe(model)) || | |||
632 | (variant && !string_is_safe(variant)) || | |||
633 | (options && !string_is_safe(options))) | |||
634 | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Received invalid keyboard data"); | |||
635 | ||||
636 | r = verify_xkb_rmlvo(model, layout, variant, options); | |||
637 | if (r < 0) { | |||
638 | log_error_errno(r, "Cannot compile XKB keymap for new x11 keyboard layout ('%s' / '%s' / '%s' / '%s'): %m",({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 639, __func__, "Cannot compile XKB keymap for new x11 keyboard layout ('%s' / '%s' / '%s' / '%s'): %m" , strempty(model), strempty(layout), strempty(variant), strempty (options)) : -abs(_e); }) | |||
639 | strempty(model), strempty(layout), strempty(variant), strempty(options))({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 639, __func__, "Cannot compile XKB keymap for new x11 keyboard layout ('%s' / '%s' / '%s' / '%s'): %m" , strempty(model), strempty(layout), strempty(variant), strempty (options)) : -abs(_e); }); | |||
640 | ||||
641 | if (r == -EOPNOTSUPP95) | |||
642 | return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED"org.freedesktop.DBus.Error.NotSupported", "Local keyboard configuration not supported on this system."); | |||
643 | ||||
644 | return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS"org.freedesktop.DBus.Error.InvalidArgs", "Specified keymap cannot be compiled, refusing as invalid."); | |||
645 | } | |||
646 | ||||
647 | r = bus_verify_polkit_async( | |||
648 | m, | |||
649 | CAP_SYS_ADMIN21, | |||
650 | "org.freedesktop.locale1.set-keyboard", | |||
651 | NULL((void*)0), | |||
652 | interactive, | |||
653 | UID_INVALID((uid_t) -1), | |||
654 | &polkit_registry, | |||
655 | error); | |||
656 | if (r < 0) | |||
657 | return r; | |||
658 | if (r == 0) | |||
659 | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
660 | ||||
661 | if (free_and_strdup(&c->x11_layout, layout) < 0 || | |||
662 | free_and_strdup(&c->x11_model, model) < 0 || | |||
663 | free_and_strdup(&c->x11_variant, variant) < 0 || | |||
664 | free_and_strdup(&c->x11_options, options) < 0) | |||
665 | return -ENOMEM12; | |||
666 | ||||
667 | r = x11_write_data(c); | |||
668 | if (r < 0) { | |||
669 | log_error_errno(r, "Failed to set X11 keyboard layout: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 669, __func__, "Failed to set X11 keyboard layout: %m" ) : -abs(_e); }); | |||
670 | return sd_bus_error_set_errnof(error, r, "Failed to set X11 keyboard layout: %m"); | |||
671 | } | |||
672 | ||||
673 | log_info("Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 677, __func__, "Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'" , strempty(c->x11_layout), strempty(c->x11_model), strempty (c->x11_variant), strempty(c->x11_options)) : -abs(_e); }) | |||
674 | strempty(c->x11_layout),({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 677, __func__, "Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'" , strempty(c->x11_layout), strempty(c->x11_model), strempty (c->x11_variant), strempty(c->x11_options)) : -abs(_e); }) | |||
675 | strempty(c->x11_model),({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 677, __func__, "Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'" , strempty(c->x11_layout), strempty(c->x11_model), strempty (c->x11_variant), strempty(c->x11_options)) : -abs(_e); }) | |||
676 | strempty(c->x11_variant),({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 677, __func__, "Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'" , strempty(c->x11_layout), strempty(c->x11_model), strempty (c->x11_variant), strempty(c->x11_options)) : -abs(_e); }) | |||
677 | strempty(c->x11_options))({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 677, __func__, "Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'" , strempty(c->x11_layout), strempty(c->x11_model), strempty (c->x11_variant), strempty(c->x11_options)) : -abs(_e); }); | |||
678 | ||||
679 | (void) sd_bus_emit_properties_changed( | |||
680 | sd_bus_message_get_bus(m), | |||
681 | "/org/freedesktop/locale1", | |||
682 | "org.freedesktop.locale1", | |||
683 | "X11Layout", "X11Model", "X11Variant", "X11Options", NULL((void*)0)); | |||
684 | ||||
685 | if (convert) { | |||
686 | r = x11_convert_to_vconsole_and_emit(c, m); | |||
687 | if (r < 0) | |||
688 | log_error_errno(r, "Failed to convert keymap data: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 688, __func__, "Failed to convert keymap data: %m" ) : -abs(_e); }); | |||
689 | } | |||
690 | ||||
691 | return sd_bus_reply_method_return(m, NULL((void*)0)); | |||
692 | } | |||
693 | ||||
694 | static const sd_bus_vtable locale_vtable[] = { | |||
695 | SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = { .element_size = sizeof(sd_bus_vtable) }, }, }, | |||
696 | SD_BUS_PROPERTY("Locale", "as", property_get_locale, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "Locale", .signature = "as", .get = property_get_locale, .set = ((void*)0), .offset = 0, } , }, }, | |||
697 | SD_BUS_PROPERTY("X11Layout", "s", property_get_xkb, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "X11Layout", .signature = "s" , .get = property_get_xkb, .set = ((void*)0), .offset = 0, }, }, }, | |||
698 | SD_BUS_PROPERTY("X11Model", "s", property_get_xkb, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "X11Model", .signature = "s" , .get = property_get_xkb, .set = ((void*)0), .offset = 0, }, }, }, | |||
699 | SD_BUS_PROPERTY("X11Variant", "s", property_get_xkb, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "X11Variant", .signature = "s" , .get = property_get_xkb, .set = ((void*)0), .offset = 0, }, }, }, | |||
700 | SD_BUS_PROPERTY("X11Options", "s", property_get_xkb, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "X11Options", .signature = "s" , .get = property_get_xkb, .set = ((void*)0), .offset = 0, }, }, }, | |||
701 | SD_BUS_PROPERTY("VConsoleKeymap", "s", property_get_vconsole, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "VConsoleKeymap", .signature = "s", .get = property_get_vconsole, .set = ((void*)0), .offset = 0, }, }, }, | |||
702 | SD_BUS_PROPERTY("VConsoleKeymapToggle", "s", property_get_vconsole, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "VConsoleKeymapToggle", .signature = "s", .get = property_get_vconsole, .set = ((void*)0), .offset = 0, }, }, }, | |||
703 | SD_BUS_METHOD("SetLocale", "asb", NULL, method_set_locale, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "SetLocale", .signature = "asb" , .result = ((void*)0), .handler = method_set_locale, .offset = 0, }, }, }, | |||
704 | SD_BUS_METHOD("SetVConsoleKeyboard", "ssbb", NULL, method_set_vc_keyboard, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "SetVConsoleKeyboard", .signature = "ssbb", .result = ((void*)0), .handler = method_set_vc_keyboard , .offset = 0, }, }, }, | |||
705 | SD_BUS_METHOD("SetX11Keyboard", "ssssbb", NULL, method_set_x11_keyboard, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "SetX11Keyboard", .signature = "ssssbb", .result = ((void*)0), .handler = method_set_x11_keyboard , .offset = 0, }, }, }, | |||
706 | SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, } | |||
707 | }; | |||
708 | ||||
709 | static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { | |||
710 | _cleanup_(sd_bus_flush_close_unrefp)__attribute__((cleanup(sd_bus_flush_close_unrefp))) sd_bus *bus = NULL((void*)0); | |||
711 | int r; | |||
712 | ||||
713 | assert(c)do { if ((__builtin_expect(!!(!(c)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("c"), "../src/locale/localed.c", 713, __PRETTY_FUNCTION__ ); } while (0); | |||
714 | assert(event)do { if ((__builtin_expect(!!(!(event)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("event"), "../src/locale/localed.c", 714 , __PRETTY_FUNCTION__); } while (0); | |||
715 | assert(_bus)do { if ((__builtin_expect(!!(!(_bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("_bus"), "../src/locale/localed.c", 715, __PRETTY_FUNCTION__); } while (0); | |||
716 | ||||
717 | r = sd_bus_default_system(&bus); | |||
718 | if (r < 0) | |||
719 | return log_error_errno(r, "Failed to get system bus connection: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 719, __func__, "Failed to get system bus connection: %m" ) : -abs(_e); }); | |||
720 | ||||
721 | r = sd_bus_add_object_vtable(bus, NULL((void*)0), "/org/freedesktop/locale1", "org.freedesktop.locale1", locale_vtable, c); | |||
722 | if (r < 0) | |||
723 | return log_error_errno(r, "Failed to register object: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 723, __func__, "Failed to register object: %m" ) : -abs(_e); }); | |||
724 | ||||
725 | r = sd_bus_request_name_async(bus, NULL((void*)0), "org.freedesktop.locale1", 0, NULL((void*)0), NULL((void*)0)); | |||
726 | if (r < 0) | |||
727 | return log_error_errno(r, "Failed to request name: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 727, __func__, "Failed to request name: %m" ) : -abs(_e); }); | |||
728 | ||||
729 | r = sd_bus_attach_event(bus, event, 0); | |||
730 | if (r < 0) | |||
731 | return log_error_errno(r, "Failed to attach bus to event loop: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 731, __func__, "Failed to attach bus to event loop: %m" ) : -abs(_e); }); | |||
732 | ||||
733 | *_bus = TAKE_PTR(bus)({ typeof(bus) _ptr_ = (bus); (bus) = ((void*)0); _ptr_; }); | |||
734 | ||||
735 | return 0; | |||
736 | } | |||
737 | ||||
738 | int main(int argc, char *argv[]) { | |||
739 | _cleanup_(context_free)__attribute__((cleanup(context_free))) Context context = { | |||
740 | .locale_mtime = USEC_INFINITY((usec_t) -1), | |||
741 | .vc_mtime = USEC_INFINITY((usec_t) -1), | |||
742 | .x11_mtime = USEC_INFINITY((usec_t) -1), | |||
743 | }; | |||
744 | _cleanup_(sd_event_unrefp)__attribute__((cleanup(sd_event_unrefp))) sd_event *event = NULL((void*)0); | |||
745 | _cleanup_(sd_bus_flush_close_unrefp)__attribute__((cleanup(sd_bus_flush_close_unrefp))) sd_bus *bus = NULL((void*)0); | |||
746 | int r; | |||
747 | ||||
748 | log_set_target(LOG_TARGET_AUTO); | |||
749 | log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD); | |||
750 | log_open(); | |||
751 | ||||
752 | umask(0022); | |||
753 | mac_selinux_init(); | |||
754 | ||||
755 | if (argc != 1) { | |||
756 | log_error("This program takes no arguments.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 756, __func__, "This program takes no arguments." ) : -abs(_e); }); | |||
757 | r = -EINVAL22; | |||
758 | goto finish; | |||
759 | } | |||
760 | ||||
761 | r = sd_event_default(&event); | |||
762 | if (r < 0) { | |||
763 | log_error_errno(r, "Failed to allocate event loop: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 763, __func__, "Failed to allocate event loop: %m" ) : -abs(_e); }); | |||
764 | goto finish; | |||
765 | } | |||
766 | ||||
767 | sd_event_set_watchdog(event, true1); | |||
768 | ||||
769 | r = connect_bus(&context, event, &bus); | |||
770 | if (r < 0) | |||
771 | goto finish; | |||
772 | ||||
773 | r = bus_event_loop_with_idle(event, bus, "org.freedesktop.locale1", DEFAULT_EXIT_USEC(30*((usec_t) 1000000ULL)), NULL((void*)0), NULL((void*)0)); | |||
774 | if (r < 0) | |||
775 | log_error_errno(r, "Failed to run event loop: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/locale/localed.c", 775, __func__, "Failed to run event loop: %m" ) : -abs(_e); }); | |||
776 | ||||
777 | finish: | |||
778 | bus_verify_polkit_async_registry_free(polkit_registry); | |||
779 | ||||
780 | return r < 0 ? EXIT_FAILURE1 : EXIT_SUCCESS0; | |||
781 | } |