#include "tmpfile-util.h"
static bool startswith_comma(const char *s, const char *prefix) {
+ assert(s);
+ assert(prefix);
+
s = startswith(s, prefix);
if (!s)
return false;
}
static void context_free_x11(Context *c) {
+ assert(c);
+
c->x11_layout = mfree(c->x11_layout);
c->x11_options = mfree(c->x11_options);
c->x11_model = mfree(c->x11_model);
}
static void context_free_vconsole(Context *c) {
+ assert(c);
+
c->vc_keymap = mfree(c->vc_keymap);
c->vc_keymap_toggle = mfree(c->vc_keymap_toggle);
}
void context_clear(Context *c) {
+ assert(c);
+
locale_context_clear(&c->locale_context);
context_free_x11(c);
context_free_vconsole(c);
_cleanup_close_ int fd = -EBADF;
struct stat st;
+ assert(c);
+
/* Do not try to re-read the file within single bus operation. */
if (m) {
if (m == c->vc_cache)
struct stat st;
int r;
+ assert(c);
+
/* Do not try to re-read the file within single bus operation. */
if (m) {
if (m == c->x11_cache)
_cleanup_strv_free_ char **l = NULL;
int r;
+ assert(c);
+
r = load_env_file(NULL, "/etc/vconsole.conf", &l);
if (r < 0 && r != -ENOENT)
return r;
_cleanup_(unlink_and_freep) char *temp_path = NULL;
int r;
+ assert(c);
+
if (isempty(c->x11_layout) &&
isempty(c->x11_model) &&
isempty(c->x11_variant) &&
return 0;
}
-static int read_next_mapping(const char* filename,
- unsigned min_fields, unsigned max_fields,
- FILE *f, unsigned *n, char ***a) {
+static int read_next_mapping(
+ const char *filename,
+ unsigned min_fields,
+ unsigned max_fields,
+ FILE *f,
+ unsigned *n,
+ char ***ret) {
+
assert(f);
assert(n);
- assert(a);
+ assert(ret);
for (;;) {
+ _cleanup_strv_free_ char **b = NULL;
_cleanup_free_ char *line = NULL;
size_t length;
- char *l, **b;
+ const char *l;
int r;
r = read_line(f, LONG_LINE_MAX, &line);
length = strv_length(b);
if (length < min_fields || length > max_fields) {
- log_error("Invalid line %s:%u, ignoring.", filename, *n);
- strv_free(b);
+ log_warning("Invalid line %s:%u, ignoring.", strna(filename), *n);
continue;
}
- *a = b;
+ *ret = TAKE_PTR(b);
return 1;
}
+ *ret = NULL;
return 0;
}
int vconsole_convert_to_x11(Context *c) {
- const char *map;
- int modified = -1;
+ int r, modified = -1;
- map = systemd_kbd_model_map();
+ assert(c);
if (isempty(c->vc_keymap)) {
modified =
context_free_x11(c);
} else {
_cleanup_fclose_ FILE *f = NULL;
- unsigned n = 0;
+ const char *map;
+ map = systemd_kbd_model_map();
f = fopen(map, "re");
if (!f)
return -errno;
- for (;;) {
+ for (unsigned n = 0;;) {
_cleanup_strv_free_ char **a = NULL;
- int r;
r = read_next_mapping(map, 5, UINT_MAX, f, &n, &a);
if (r < 0)
return modified > 0;
}
-int find_converted_keymap(const char *x11_layout, const char *x11_variant, char **new_keymap) {
+int find_converted_keymap(const char *x11_layout, const char *x11_variant, char **ret) {
_cleanup_free_ char *n = NULL;
+ assert(x11_layout);
+ assert(ret);
+
if (x11_variant)
n = strjoin(x11_layout, "-", x11_variant);
else
uncompressed = access(p, F_OK) == 0;
if (uncompressed || access(pz, F_OK) == 0) {
- log_debug("Found converted keymap %s at %s",
- n, uncompressed ? p : pz);
-
- *new_keymap = TAKE_PTR(n);
+ log_debug("Found converted keymap %s at %s", n, uncompressed ? p : pz);
+ *ret = TAKE_PTR(n);
return 1;
}
}
+ *ret = NULL;
return 0;
}
const char *map;
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *new_keymap = NULL;
- unsigned n = 0;
unsigned best_matching = 0;
int r;
+ assert(c);
assert(!isempty(c->x11_layout));
map = systemd_kbd_model_map();
-
f = fopen(map, "re");
if (!f)
return -errno;
- for (;;) {
+ for (unsigned n = 0;;) {
_cleanup_strv_free_ char **a = NULL;
unsigned matching = 0;
/* Determine how well matching this entry is */
if (streq(c->x11_layout, a[1]))
- /* If we got an exact match, this is best */
+ /* If we got an exact match, this is the best */
matching = 10;
else {
/* We have multiple X layouts, look for an
* but the first layout stripped off. */
if (startswith_comma(c->x11_layout, a[1]))
matching = 5;
- else {
+ else {
_cleanup_free_ char *x = NULL;
/* If that didn't work, strip off the
/* The best matching entry so far, then let's save that */
if (matching >= MAX(best_matching, 1u)) {
- log_debug("Found legacy keymap %s with score %u",
- a[0], matching);
+ log_debug("Found legacy keymap %s with score %u", a[0], matching);
if (matching > best_matching) {
best_matching = matching;
}
*ret = TAKE_PTR(new_keymap);
- return (bool) *ret;
+ return !!*ret;
}
-int find_language_fallback(const char *lang, char **language) {
+int find_language_fallback(const char *lang, char **ret) {
const char *map;
_cleanup_fclose_ FILE *f = NULL;
unsigned n = 0;
+ int r;
assert(lang);
- assert(language);
+ assert(ret);
map = systemd_language_fallback_map();
-
f = fopen(map, "re");
if (!f)
return -errno;
for (;;) {
_cleanup_strv_free_ char **a = NULL;
- int r;
r = read_next_mapping(map, 2, 2, f, &n, &a);
if (r <= 0)
if (streq(lang, a[0])) {
assert(strv_length(a) == 2);
- *language = TAKE_PTR(a[1]);
+ *ret = TAKE_PTR(a[1]);
return 1;
}
}
-
- assert_not_reached();
}
int x11_convert_to_vconsole(Context *c) {
bool modified = false;
+ assert(c);
+
if (isempty(c->x11_layout)) {
modified =
!isempty(c->vc_keymap) ||
int r;
r = find_converted_keymap(c->x11_layout, c->x11_variant, &new_keymap);
+ if (r == 0)
+ r = find_legacy_keymap(c, &new_keymap);
if (r < 0)
return r;
- else if (r == 0) {
- r = find_legacy_keymap(c, &new_keymap);
- if (r < 0)
- return r;
- }
if (r == 0)
/* We search for layout-variant match first, but then we also look
* for anything which matches just the layout. So it's accurate to say
* that we couldn't find anything which matches the layout. */
- log_notice("No conversion to virtual console map found for \"%s\".",
- c->x11_layout);
+ log_notice("No conversion to virtual console map found for \"%s\".", c->x11_layout);
if (!streq_ptr(c->vc_keymap, new_keymap)) {
free_and_replace(c->vc_keymap, new_keymap);
static int vconsole_convert_to_x11_and_emit(Context *c, sd_bus_message *m) {
int r;
+ assert(c);
assert(m);
r = x11_read_data(c, m);
static int x11_convert_to_vconsole_and_emit(Context *c, sd_bus_message *m) {
int r;
+ assert(c);
assert(m);
r = vconsole_read_data(c, m);
void *userdata,
sd_bus_error *error) {
- Context *c = userdata;
+ Context *c = ASSERT_PTR(userdata);
_cleanup_strv_free_ char **l = NULL;
int r;
void *userdata,
sd_bus_error *error) {
- Context *c = userdata;
+ Context *c = ASSERT_PTR(userdata);
int r;
+ assert(property);
+
r = vconsole_read_data(c, reply);
if (r < 0)
return r;
if (streq(property, "VConsoleKeymap"))
return sd_bus_message_append_basic(reply, 's', c->vc_keymap);
- else if (streq(property, "VConsoleKeymapToggle"))
+ if (streq(property, "VConsoleKeymapToggle"))
return sd_bus_message_append_basic(reply, 's', c->vc_keymap_toggle);
return -EINVAL;
void *userdata,
sd_bus_error *error) {
- Context *c = userdata;
+ Context *c = ASSERT_PTR(userdata);
int r;
+ assert(property);
+
r = x11_read_data(c, reply);
if (r < 0)
return r;
if (streq(property, "X11Layout"))
return sd_bus_message_append_basic(reply, 's', c->x11_layout);
- else if (streq(property, "X11Model"))
+ if (streq(property, "X11Model"))
return sd_bus_message_append_basic(reply, 's', c->x11_model);
- else if (streq(property, "X11Variant"))
+ if (streq(property, "X11Variant"))
return sd_bus_message_append_basic(reply, 's', c->x11_variant);
- else if (streq(property, "X11Options"))
+ if (streq(property, "X11Options"))
return sd_bus_message_append_basic(reply, 's', c->x11_options);
return -EINVAL;
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Locale assignment %s not valid, refusing.", assignment);
}
-static int locale_gen_process_locale(char *new_locale[static _VARIABLE_LC_MAX],
- sd_bus_error *error) {
+static int locale_gen_process_locale(char *new_locale[static _VARIABLE_LC_MAX], sd_bus_error *error) {
int r;
+
assert(new_locale);
for (LocaleVariable p = 0; p < _VARIABLE_LC_MAX; p++) {
SD_BUS_ERROR_INVALID_ARGS,
"Specified locale is not installed and non-UTF-8 locale will not be auto-generated: %s",
new_locale[p]);
- } else if (r == -EINVAL) {
+ }
+ if (r == -EINVAL) {
log_error_errno(r, "Failed to enable invalid locale %s for generation.", new_locale[p]);
return sd_bus_error_setf(error,
SD_BUS_ERROR_INVALID_ARGS,
"Can not enable locale generation for invalid locale: %s",
new_locale[p]);
- } else if (r < 0) {
+ }
+ if (r < 0) {
log_error_errno(r, "Failed to enable locale for generation: %m");
return sd_bus_error_set_errnof(error, r, "Failed to enable locale generation: %m");
}