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.
This commit is contained in:
Emanuele Giuseppe Esposito
2025-07-29 05:34:50 -04:00
parent d0cd25fff6
commit eea5745f9e
+38
View File
@@ -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;