From 01ea6ba5f13a38f369acf57a128953dcda3c08bb Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Tue, 13 Sep 2022 13:06:09 +0100 Subject: [PATCH] xdg-autostart-service: Use common boolean parser 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". (cherry picked from commit 38429cb1e3f37c298aa20ab25d644c87a23dd2e2) (cherry picked from commit c40fa78968821096b3e9757107bfd10657ef92ff) --- .../test-xdg-autostart.c | 3 +++ .../xdg-autostart-service.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/xdg-autostart-generator/test-xdg-autostart.c b/src/xdg-autostart-generator/test-xdg-autostart.c index c7a816bc25..b0dd2ab56b 100644 --- a/src/xdg-autostart-generator/test-xdg-autostart.c +++ b/src/xdg-autostart-generator/test-xdg-autostart.c @@ -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(unsigned i, const char *s) { @@ -75,6 +77,7 @@ static void test_xdg_desktop_parse(unsigned i, const char *s) { assert_se(streq(service->exec_string, "a")); break; case 2: + case 3: assert_se(service->hidden); break; } diff --git a/src/xdg-autostart-generator/xdg-autostart-service.c b/src/xdg-autostart-generator/xdg-autostart-service.c index c60a9d81ac..f17aba9818 100644 --- a/src/xdg-autostart-generator/xdg-autostart-service.c +++ b/src/xdg-autostart-generator/xdg-autostart-service.c @@ -8,15 +8,17 @@ #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 "user-util.h" +#include "unit-name.h" XdgAutostartService* xdg_autostart_service_free(XdgAutostartService *s) { if (!s) @@ -74,19 +76,17 @@ static int xdg_config_parse_bool( void *userdata) { bool *b = data; + int r; assert(filename); assert(lvalue); assert(rvalue); assert(data); - 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; }