From: Emanuele Giuseppe Esposito Date: Thu, 17 Jul 2025 09:03:54 +0000 (-0400) Subject: sysext: introduce global config file X-Git-Tag: v259-rc1~558^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eea5745f9e8617c806f7451f61b3b43422b242a1;p=thirdparty%2Fsystemd.git sysext: introduce global config file Introduce systemd/{sysext/confext}.conf and systemd/{sysext/confext}.conf.d to provide an alternative way of setting the cmdline options in systemd-sysext. The config file has to have a [Sysext] or [Confext] option respectively, which will be overridden by the cmdline. As an example of supported config, add Mutable= option. --- diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index 005ea6d977d..a4512d48e55 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -17,6 +17,7 @@ #include "bus-util.h" #include "capability-util.h" #include "chase.h" +#include "conf-parser.h" #include "devnum-util.h" #include "discover-image.h" #include "dissect-image.h" @@ -148,6 +149,36 @@ static int parse_mutable_mode(const char *p) { return mutable_mode_from_string(p); } +static DEFINE_CONFIG_PARSE_ENUM(config_parse_mutable_mode, mutable_mode, MutableMode); + +static int parse_config_file(ImageClass image_class) { + const char *section = image_class == IMAGE_SYSEXT ? "SysExt" : "ConfExt"; + const ConfigTableItem items[] = { + { section, "Mutable", config_parse_mutable_mode, 0, &arg_mutable }, + {} + }; + _cleanup_free_ char *config_file = NULL; + int r; + + config_file = strjoin("systemd/", image_class_info[image_class].short_identifier, ".conf"); + if (!config_file) + return log_oom(); + + r = config_parse_standard_file_with_dropins_full( + arg_root, + config_file, + image_class == IMAGE_SYSEXT ? "SysExt\0" : "ConfExt\0", + config_item_table_lookup, items, + CONFIG_PARSE_WARN, + /* userdata = */ NULL, + /* ret_stats_by_path = */ NULL, + /* ret_dropin_files = */ NULL); + if (r < 0) + return r; + + return 0; +} + static int is_our_mount_point( ImageClass image_class, const char *p) { @@ -2593,6 +2624,7 @@ static int run(int argc, char *argv[]) { arg_image_class = invoked_as(argv, "systemd-confext") ? IMAGE_CONFEXT : IMAGE_SYSEXT; + /* Parse environment variable first */ env_var = getenv(image_class_info[arg_image_class].mode_env); if (env_var) { r = parse_mutable_mode(env_var); @@ -2603,6 +2635,12 @@ static int run(int argc, char *argv[]) { arg_mutable = r; } + /* Parse configuration file */ + r = parse_config_file(arg_image_class); + if (r < 0) + log_warning_errno(r, "Failed to parse global config file, ignoring: %m"); + + /* Parse command line */ r = parse_argv(argc, argv); if (r <= 0) return r;