diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index 005ea6d977..a4512d48e5 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;