]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysext: introduce global config file
authorEmanuele Giuseppe Esposito <eesposit@redhat.com>
Thu, 17 Jul 2025 09:03:54 +0000 (05:03 -0400)
committerEmanuele Giuseppe Esposito <eesposit@redhat.com>
Tue, 29 Jul 2025 09:34:50 +0000 (05:34 -0400)
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.

src/sysext/sysext.c

index 005ea6d977dac5fc56739505d74b22ec9a2f8c33..a4512d48e55bae987e47cb947494f00f02be9258 100644 (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;