From: Krzesimir Nowak Date: Thu, 15 Feb 2024 14:01:20 +0000 (+0100) Subject: sysext: Factor out adding overlayfs option X-Git-Tag: v256-rc1~731^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f681bb6c02d38d1328595dd8407e5b6bc740c9c;p=thirdparty%2Fsystemd.git sysext: Factor out adding overlayfs option We will use it later when adding workdir and upperdir options for overlayfs mount operation. --- diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index 2db5d375cf8..b6420926799 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -478,6 +478,31 @@ static int verb_status(int argc, char **argv, void *userdata) { return ret; } +static int append_overlayfs_path_option( + char **options, + const char *separator, + const char *option, + const char *path) { + + _cleanup_free_ char *escaped = NULL; + + assert(options); + assert(separator); + assert(path); + + escaped = shell_escape(path, ",:"); + if (!escaped) + return log_oom(); + + if (option) { + if (!strextend(options, separator, option, "=", escaped)) + return log_oom(); + } else if (!strextend(options, separator, escaped)) + return log_oom(); + + return 0; +} + static int mount_overlayfs( ImageClass image_class, int noexec, @@ -496,14 +521,9 @@ static int mount_overlayfs( return log_oom(); STRV_FOREACH(l, layers) { - _cleanup_free_ char *escaped = NULL; - - escaped = shell_escape(*l, ",:"); - if (!escaped) - return log_oom(); - - if (!strextend(&options, separator ? ":" : "", escaped)) - return log_oom(); + r = append_overlayfs_path_option(&options, separator ? ":" : "", NULL, *l); + if (r < 0) + return r; separator = true; }