1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-21 02:50:18 +03:00

locale: replace context_get_x11_context() with context_get_x11_context_safe()

Then, context_get_x11_context() always replies a valid X11 context.
No functional change, just refactoring.
This commit is contained in:
Yu Watanabe 2023-01-26 17:34:08 +09:00
parent 90005a4f0a
commit f59d83afaa
3 changed files with 11 additions and 16 deletions

View File

@ -245,7 +245,7 @@ void context_clear(Context *c) {
c->polkit_registry = bus_verify_polkit_async_registry_free(c->polkit_registry);
};
static X11Context *context_get_x11_context(Context *c) {
X11Context *context_get_x11_context(Context *c) {
assert(c);
if (!x11_context_isempty(&c->x11_from_vc))
@ -254,12 +254,7 @@ static X11Context *context_get_x11_context(Context *c) {
if (!x11_context_isempty(&c->x11_from_xorg))
return &c->x11_from_xorg;
return NULL;
}
X11Context *context_get_x11_context_safe(Context *c) {
assert(c);
return context_get_x11_context(c) ?: &c->x11_from_vc;
return &c->x11_from_vc;
}
int locale_read_data(Context *c, sd_bus_message *m) {
@ -460,19 +455,19 @@ int vconsole_write_data(Context *c) {
if (r < 0)
return r;
r = strv_env_assign(&l, "XKBLAYOUT", xc ? empty_to_null(xc->layout) : NULL);
r = strv_env_assign(&l, "XKBLAYOUT", empty_to_null(xc->layout));
if (r < 0)
return r;
r = strv_env_assign(&l, "XKBMODEL", xc ? empty_to_null(xc->model) : NULL);
r = strv_env_assign(&l, "XKBMODEL", empty_to_null(xc->model));
if (r < 0)
return r;
r = strv_env_assign(&l, "XKBVARIANT", xc ? empty_to_null(xc->variant) : NULL);
r = strv_env_assign(&l, "XKBVARIANT", empty_to_null(xc->variant));
if (r < 0)
return r;
r = strv_env_assign(&l, "XKBOPTIONS", xc ? empty_to_null(xc->options) : NULL);
r = strv_env_assign(&l, "XKBOPTIONS", empty_to_null(xc->options));
if (r < 0)
return r;
@ -503,7 +498,7 @@ int x11_write_data(Context *c) {
assert(c);
xc = context_get_x11_context(c);
if (!xc) {
if (x11_context_isempty(xc)) {
if (unlink("/etc/X11/xorg.conf.d/00-keyboard.conf") < 0)
return errno == ENOENT ? 0 : -errno;

View File

@ -44,7 +44,7 @@ bool x11_context_is_safe(const X11Context *xc);
bool x11_context_equal(const X11Context *a, const X11Context *b);
int x11_context_copy(X11Context *dest, const X11Context *src);
X11Context *context_get_x11_context_safe(Context *c);
X11Context *context_get_x11_context(Context *c);
void vc_context_clear(VCContext *vc);
void vc_context_replace(VCContext *dest, VCContext *src);

View File

@ -144,7 +144,7 @@ static int property_get_xkb(
if (r < 0)
return r;
xc = context_get_x11_context_safe(c);
xc = context_get_x11_context(c);
if (streq(property, "X11Layout"))
return sd_bus_message_append_basic(reply, 's', xc->layout);
@ -432,7 +432,7 @@ static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_erro
}
/* save the result of conversion to emit changed properties later. */
xc = context_get_x11_context_safe(c);
xc = context_get_x11_context(c);
convert = !x11_context_equal(xc, &converted);
x11_context_replace(xc, &converted);
}
@ -586,7 +586,7 @@ static int method_set_x11_keyboard(sd_bus_message *m, void *userdata, sd_bus_err
return sd_bus_error_set(error, SD_BUS_ERROR_FAILED, "Failed to read x11 keyboard layout data");
}
xc = context_get_x11_context_safe(c);
xc = context_get_x11_context(c);
if (x11_context_equal(xc, &in))
return sd_bus_reply_method_return(m, NULL);