From: Zbigniew Jędrzejewski-Szmek Date: Thu, 11 Mar 2021 10:10:32 +0000 (+0100) Subject: fstab-generator: get rid of fstab_extract_values() X-Git-Tag: v248-rc3~2^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F18955%2Fhead;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index b454a5980d4..8c1087a9a33 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -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; diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 6674ed4a19f..7fd3d9c2c34 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -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; diff --git a/src/shared/fstab-util.h b/src/shared/fstab-util.h index 97f40221afb..6b596baafa1 100644 --- a/src/shared/fstab-util.h +++ b/src/shared/fstab-util.h @@ -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); }