]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-parser: introduce config_parse_uint32_invert_flag()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Aug 2024 04:11:43 +0000 (13:11 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 6 Sep 2024 01:35:02 +0000 (10:35 +0900)
It is similar to config_parse_uint32_flag(), but drops the specified flag
when true.

src/shared/conf-parser.c
src/shared/conf-parser.h

index d29d113bbc00311b280cc7c40cd9957f8f3083fc..6db94317086317998b4457db45bbb459d150626e 100644 (file)
@@ -1061,6 +1061,31 @@ int config_parse_uint32_flag(
         return 1;
 }
 
+int config_parse_uint32_invert_flag(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        uint32_t *flags = ASSERT_PTR(data);
+        int r;
+
+        assert(ltype != 0);
+
+        r = isempty(rvalue) ? 0 : parse_boolean(rvalue);
+        if (r < 0)
+                return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
+
+        SET_FLAG(*flags, ltype, !r);
+        return 1;
+}
+
 int config_parse_id128(
                 const char *unit,
                 const char *filename,
index bd7caf1f4623b9c9922c7bf501c6bc22af2cd60d..c542839a927c6c30eb1157fcbb97e86bd4988571 100644 (file)
@@ -274,6 +274,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64);
 CONFIG_PARSER_PROTOTYPE(config_parse_iec_uint64_infinity);
 CONFIG_PARSER_PROTOTYPE(config_parse_bool);
 CONFIG_PARSER_PROTOTYPE(config_parse_uint32_flag);
+CONFIG_PARSER_PROTOTYPE(config_parse_uint32_invert_flag);
 CONFIG_PARSER_PROTOTYPE(config_parse_id128);
 CONFIG_PARSER_PROTOTYPE(config_parse_tristate);
 CONFIG_PARSER_PROTOTYPE(config_parse_string);