X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flocale%2Flocaled.c;h=bce99b8cbaae0817eabf668d4db880af06f123c3;hb=601185b43da638b1c74153deae01dbd518680889;hp=7c41822a2f7d6df9f9dcdb8d8349ab5501d37d03;hpb=cde93897cdefdd7c7f66c400a61e42ceee5f6a46;p=elogind.git diff --git a/src/locale/localed.c b/src/locale/localed.c index 7c41822a2..bce99b8cb 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -38,6 +38,7 @@ #include "bus-error.h" #include "bus-message.h" #include "event-util.h" +#include "locale-util.h" enum { /* We don't list LC_ALL here on purpose. People should be @@ -209,6 +210,7 @@ static int x11_read_data(Context *c) { FILE *f; char line[LINE_MAX]; bool in_section = false; + int r; context_free_x11(c); @@ -228,10 +230,10 @@ static int x11_read_data(Context *c) { if (in_section && first_word(l, "Option")) { char **a; - a = strv_split_quoted(l); - if (!a) { + r = strv_split_quoted(&a, l); + if (r < 0) { fclose(f); - return -ENOMEM; + return r; } if (strv_length(a) == 3) { @@ -255,8 +257,8 @@ static int x11_read_data(Context *c) { } else if (!in_section && first_word(l, "Section")) { char **a; - a = strv_split_quoted(l); - if (!a) { + r = strv_split_quoted(&a, l); + if (r < 0) { fclose(f); return -ENOMEM; } @@ -288,7 +290,7 @@ static int locale_write_data(Context *c) { int r, p; char **l = NULL; - r = load_env_file("/etc/locale.conf", NULL, &l); + r = load_env_file(NULL, "/etc/locale.conf", NULL, &l); if (r < 0 && r != -ENOENT) return r; @@ -366,11 +368,11 @@ static int locale_update_system_manager(Context *c, sd_bus *bus) { } assert(c_set + c_unset == _LOCALE_MAX); - r = sd_bus_message_new_method_call(bus, + r = sd_bus_message_new_method_call(bus, &m, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", - "UnsetAndSetEnvironment", &m); + "UnsetAndSetEnvironment"); if (r < 0) return r; @@ -393,7 +395,7 @@ static int vconsole_write_data(Context *c) { int r; _cleanup_strv_free_ char **l = NULL; - r = load_env_file("/etc/vconsole.conf", NULL, &l); + r = load_env_file(NULL, "/etc/vconsole.conf", NULL, &l); if (r < 0 && r != -ENOENT) return r; @@ -532,6 +534,7 @@ static int read_next_mapping(FILE *f, unsigned *n, char ***a) { for (;;) { char line[LINE_MAX]; char *l, **b; + int r; errno = 0; if (!fgets(line, sizeof(line), f)) { @@ -548,9 +551,9 @@ static int read_next_mapping(FILE *f, unsigned *n, char ***a) { if (l[0] == 0 || l[0] == '#') continue; - b = strv_split_quoted(l); - if (!b) - return -ENOMEM; + r = strv_split_quoted(&b, l); + if (r < 0) + return r; if (strv_length(b) < 5) { log_error("Invalid line "SYSTEMD_KBD_MODEL_MAP":%u, ignoring.", *n); @@ -712,15 +715,16 @@ static int find_legacy_keymap(Context *c, char **new_keymap) { } } - if (matching > 0 && - streq_ptr(c->x11_model, a[2])) { - matching++; - - if (streq_ptr(c->x11_variant, a[3])) { + if (matching > 0) { + if (isempty(c->x11_model) || streq_ptr(c->x11_model, a[2])) { matching++; - if (streq_ptr(c->x11_options, a[4])) + if (streq_ptr(c->x11_variant, a[3])) { matching++; + + if (streq_ptr(c->x11_options, a[4])) + matching++; + } } } @@ -847,7 +851,7 @@ static int method_set_locale(sd_bus *bus, sd_bus_message *m, void *userdata, sd_ k = strlen(names[p]); if (startswith(*i, names[p]) && (*i)[k] == '=' && - string_is_safe((*i) + k + 1)) { + locale_is_valid((*i) + k + 1)) { valid = true; passed[p] = true; @@ -948,7 +952,7 @@ static int method_set_vc_keyboard(sd_bus *bus, sd_bus_message *m, void *userdata if ((keymap && (!filename_is_safe(keymap) || !string_is_safe(keymap))) || (keymap_toggle && (!filename_is_safe(keymap_toggle) || !string_is_safe(keymap_toggle)))) - return sd_bus_error_set_errnof(error, r, "Received invalid keymap data: %s", -EINVAL); + return sd_bus_error_set_errnof(error, -EINVAL, "Received invalid keymap data"); r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.locale1.set-keyboard", @@ -1020,7 +1024,7 @@ static int method_set_x11_keyboard(sd_bus *bus, sd_bus_message *m, void *userdat (model && !string_is_safe(model)) || (variant && !string_is_safe(variant)) || (options && !string_is_safe(options))) - return sd_bus_error_set_errnof(error, r, "Received invalid keyboard data: %s", -EINVAL); + return sd_bus_error_set_errnof(error, -EINVAL, "Received invalid keyboard data"); r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freedesktop.locale1.set-keyboard", @@ -1088,13 +1092,13 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { return r; } - r = sd_bus_add_object_vtable(bus, "/org/freedesktop/locale1", "org.freedesktop.locale1", locale_vtable, c); + r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/locale1", "org.freedesktop.locale1", locale_vtable, c); if (r < 0) { log_error("Failed to register object: %s", strerror(-r)); return r; } - r = sd_bus_request_name(bus, "org.freedesktop.locale1", SD_BUS_NAME_REPLACE_EXISTING|SD_BUS_NAME_DO_NOT_QUEUE); + r = sd_bus_request_name(bus, "org.freedesktop.locale1", 0); if (r < 0) { log_error("Failed to register name: %s", strerror(-r)); return r; @@ -1149,14 +1153,12 @@ int main(int argc, char *argv[]) { goto finish; } - r = bus_event_loop_with_idle(event, bus, "org.freedesktop.locale1", DEFAULT_EXIT_USEC); + r = bus_event_loop_with_idle(event, bus, "org.freedesktop.locale1", DEFAULT_EXIT_USEC, NULL, NULL); if (r < 0) { log_error("Failed to run event loop: %s", strerror(-r)); goto finish; } - r = 0; - finish: context_free(&context, bus);