]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
xdg-autostart-service: Use common boolean parser
authorDavid Edmundson <kde@davidedmundson.co.uk>
Tue, 13 Sep 2022 12:06:09 +0000 (13:06 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 13 Sep 2022 18:54:28 +0000 (03:54 +0900)
Technically the desktop entry specification says value should be the
string "true" or "false". Pragmatically every desktop has their own
parsing rules which are typically less strict on how to interpret other
values.

This caused some regressions downstream when we switched to the
xdg-autostart-generator where existing handmade files contained values
with "True" or "False".

src/xdg-autostart-generator/test-xdg-autostart.c
src/xdg-autostart-generator/xdg-autostart-service.c

index e18c918daad5f71830337d1ade3268ab995712b4..7866d3a7b4a148d779c5473eefbe333454feb07d 100644 (file)
@@ -48,6 +48,8 @@ static const char* const xdg_desktop_file[] = {
 
         ("[Desktop Entry]\n"
          "Hidden=\t true\n"),
+        ("[Desktop Entry]\n"
+         "Hidden=\t True\n"),
 };
 
 static void test_xdg_desktop_parse_one(unsigned i, const char *s) {
@@ -75,6 +77,7 @@ static void test_xdg_desktop_parse_one(unsigned i, const char *s) {
                 assert_se(streq(service->exec_string, "a"));
                 break;
         case 2:
+        case 3:
                 assert_se(service->hidden);
                 break;
         }
index 75b6a62a9750c6bf9432c644bf36dd880c8b7f00..56cc4ceeb9abebe9bacc34826864ed9527bec94a 100644 (file)
@@ -8,15 +8,16 @@
 
 #include "conf-parser.h"
 #include "escape.h"
-#include "unit-name.h"
-#include "path-util.h"
 #include "fd-util.h"
 #include "generator.h"
 #include "log.h"
+#include "nulstr-util.h"
+#include "parse-util.h"
+#include "path-util.h"
 #include "specifier.h"
 #include "string-util.h"
-#include "nulstr-util.h"
 #include "strv.h"
+#include "unit-name.h"
 
 XdgAutostartService* xdg_autostart_service_free(XdgAutostartService *s) {
         if (!s)
@@ -74,18 +75,16 @@ static int xdg_config_parse_bool(
                 void *userdata) {
 
         bool *b = ASSERT_PTR(data);
+        int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
 
-        if (streq(rvalue, "true"))
-                *b = true;
-        else if (streq(rvalue, "false"))
-                *b = false;
-        else
+        r = parse_boolean(rvalue);
+        if (r < 0)
                 return log_syntax(unit, LOG_ERR, filename, line, SYNTHETIC_ERRNO(EINVAL), "Invalid value for boolean: %s", rvalue);
-
+        *b = r;
         return 0;
 }