]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-parser: introduce config_parse_uint32_flag()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 24 Aug 2024 19:56:43 +0000 (04:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 24 Aug 2024 21:18:37 +0000 (06:18 +0900)
This is not used currently, but will be used later.

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

index d33ee8a9b0fa9919d87c772514f7001f74df24e0..ac0df88b4d583afd224fdfae521d28a011bbfd80 100644 (file)
@@ -1008,6 +1008,35 @@ int config_parse_bool(
         return 1; /* set */
 }
 
+int config_parse_uint32_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) {
+                log_syntax(unit, LOG_WARNING, filename, line, r,
+                           "Failed to parse %s=%s. Ignoring assignment: %m",
+                           lvalue, rvalue);
+                return 0;
+        }
+
+        SET_FLAG(*flags, ltype, r);
+        return 1;
+}
+
 int config_parse_id128(
                 const char *unit,
                 const char *filename,
index 94f81a3bd631b58cf30c64ba9e4281eb6dc305c7..ad40c6224c5df25e6c166f03ef7c1cca9cd4e0d1 100644 (file)
@@ -254,6 +254,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_si_uint64);
 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_id128);
 CONFIG_PARSER_PROTOTYPE(config_parse_tristate);
 CONFIG_PARSER_PROTOTYPE(config_parse_string);