summaryrefslogtreecommitdiffstats
path: root/src/shared/conf-parser.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-04-16 03:28:06 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-04-19 03:23:01 +0200
commitf72e851fd33375841823195fef9a8fc44904645b (patch)
treeca07c9007df37113ca07795d1c34ecc3295ba938 /src/shared/conf-parser.c
parentnspawn: rename config_parse_timezone() -> config_parse_timezone_mode() (diff)
downloadsystemd-f72e851fd33375841823195fef9a8fc44904645b.tar.xz
systemd-f72e851fd33375841823195fef9a8fc44904645b.zip
conf-parser: move config_parse_timezone() to conf-parser.[ch]
Even though it is currently only used by networkd, the parser itself is quite generic. Let's move it to the shared library.
Diffstat (limited to 'src/shared/conf-parser.c')
-rw-r--r--src/shared/conf-parser.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index e2d3b65f88..277f4ee42f 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -1979,3 +1979,37 @@ int config_parse_unsigned_bounded(
DEFINE_CONFIG_PARSE(config_parse_percent, parse_percent, "Failed to parse percent value");
DEFINE_CONFIG_PARSE(config_parse_permyriad, parse_permyriad, "Failed to parse permyriad value");
DEFINE_CONFIG_PARSE_PTR(config_parse_sec_fix_0, parse_sec_fix_0, usec_t, "Failed to parse time value");
+
+int config_parse_timezone(
+ 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) {
+
+ char **tz = ASSERT_PTR(data);
+ int r;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+
+ if (isempty(rvalue)) {
+ *tz = mfree(*tz);
+ return 0;
+ }
+
+ r = verify_timezone(rvalue, LOG_WARNING);
+ if (r < 0) {
+ log_syntax(unit, LOG_WARNING, filename, line, r,
+ "Timezone is not valid, ignoring assignment: %s", rvalue);
+ return 0;
+ }
+
+ return free_and_strdup_warn(tz, rvalue);
+}