diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-01-26 17:34:08 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-01-28 14:47:36 +0900 |
commit | f59d83afaab95a60998428579da505144cc4906d (patch) | |
tree | 7eea18549b27f5cc81b910b84db9df095ee28eaa /src/locale | |
parent | 90005a4f0a2c0a229e2356fb75cc75ea538503d3 (diff) | |
download | systemd-f59d83afaab95a60998428579da505144cc4906d.tar.gz |
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.
Diffstat (limited to 'src/locale')
-rw-r--r-- | src/locale/localed-util.c | 19 | ||||
-rw-r--r-- | src/locale/localed-util.h | 2 | ||||
-rw-r--r-- | src/locale/localed.c | 6 |
3 files changed, 11 insertions, 16 deletions
diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c index 3c95885e28..87e232e08f 100644 --- a/src/locale/localed-util.c +++ b/src/locale/localed-util.c @@ -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; diff --git a/src/locale/localed-util.h b/src/locale/localed-util.h index 015fcf8901..83d253c18d 100644 --- a/src/locale/localed-util.h +++ b/src/locale/localed-util.h @@ -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); diff --git a/src/locale/localed.c b/src/locale/localed.c index b91ebf79ec..dcd3b3e38d 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -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); |