]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale: replace context_get_x11_context() with context_get_x11_context_safe()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 26 Jan 2023 08:34:08 +0000 (17:34 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 28 Jan 2023 05:47:36 +0000 (14:47 +0900)
Then, context_get_x11_context() always replies a valid X11 context.
No functional change, just refactoring.

src/locale/localed-util.c
src/locale/localed-util.h
src/locale/localed.c

index 3c95885e28e2595910f3fc6c87f4484c1b46978b..87e232e08f841bc9360cb6cabb290b4ba5278956 100644 (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;
 
index 015fcf8901786b4d978c5d704d482b4f119f8af9..83d253c18d9e55ee46cf46800fa64a94bbf094c1 100644 (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);
index b91ebf79ec70e25db891182aabe368a21b3b2374..dcd3b3e38dce9b881b2e6df8b45aecd995d35998 100644 (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);