1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-26 14:04:03 +03:00

fstab-generator: get rid of fstab_extract_values()

This was a parallel implementation of option parsing that didn't
support escaping of separators. Let's port this over to the common code.

Fixes #18952.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-03-11 11:10:32 +01:00
parent ff0c31bc27
commit d6cef552dc
3 changed files with 7 additions and 38 deletions

View File

@ -241,7 +241,7 @@ static int write_dependency(
assert(f);
assert(opts);
r = fstab_extract_values(opts, filter, &names);
r = fstab_filter_options(opts, filter, NULL, NULL, &names, NULL);
if (r < 0)
return log_warning_errno(r, "Failed to parse options: %m");
if (r == 0)
@ -274,17 +274,17 @@ static int write_dependency(
static int write_after(FILE *f, const char *opts) {
return write_dependency(f, opts,
"x-systemd.after", "After=%1$s\n");
"x-systemd.after\0", "After=%1$s\n");
}
static int write_requires_after(FILE *f, const char *opts) {
return write_dependency(f, opts,
"x-systemd.requires", "After=%1$s\nRequires=%1$s\n");
"x-systemd.requires\0", "After=%1$s\nRequires=%1$s\n");
}
static int write_before(FILE *f, const char *opts) {
return write_dependency(f, opts,
"x-systemd.before", "Before=%1$s\n");
"x-systemd.before\0", "Before=%1$s\n");
}
static int write_requires_mounts_for(FILE *f, const char *opts) {
@ -295,7 +295,7 @@ static int write_requires_mounts_for(FILE *f, const char *opts) {
assert(f);
assert(opts);
r = fstab_extract_values(opts, "x-systemd.requires-mounts-for", &paths);
r = fstab_filter_options(opts, "x-systemd.requires-mounts-for\0", NULL, NULL, &paths, NULL);
if (r < 0)
return log_warning_errno(r, "Failed to parse options: %m");
if (r == 0)
@ -376,11 +376,11 @@ static int add_mount(
mount_point_ignore(where))
return 0;
r = fstab_extract_values(opts, "x-systemd.wanted-by", &wanted_by);
r = fstab_filter_options(opts, "x-systemd.wanted-by\0", NULL, NULL, &wanted_by, NULL);
if (r < 0)
return r;
r = fstab_extract_values(opts, "x-systemd.required-by", &required_by);
r = fstab_filter_options(opts, "x-systemd.required-by\0", NULL, NULL, &required_by, NULL);
if (r < 0)
return r;

View File

@ -210,35 +210,6 @@ answer:
return !!namefound;
}
int fstab_extract_values(const char *opts, const char *name, char ***values) {
_cleanup_strv_free_ char **optsv = NULL, **res = NULL;
char **s;
assert(opts);
assert(name);
assert(values);
optsv = strv_split(opts, ",");
if (!optsv)
return -ENOMEM;
STRV_FOREACH(s, optsv) {
char *arg;
int r;
arg = startswith(*s, name);
if (!arg || *arg != '=')
continue;
r = strv_extend(&res, arg + 1);
if (r < 0)
return r;
}
*values = TAKE_PTR(res);
return !!*values;
}
int fstab_find_pri(const char *options, int *ret) {
_cleanup_free_ char *opt = NULL;
int r, pri;

View File

@ -18,8 +18,6 @@ int fstab_filter_options(
char ***ret_values,
char **ret_filtered);
int fstab_extract_values(const char *opts, const char *name, char ***values);
static inline bool fstab_test_option(const char *opts, const char *names) {
return !!fstab_filter_options(opts, names, NULL, NULL, NULL, NULL);
}