]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-tool: expose image filtering via new --image-filter= parameter
authorLennart Poettering <lennart@poettering.net>
Wed, 19 Mar 2025 08:09:16 +0000 (09:09 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 3 Apr 2025 09:08:57 +0000 (11:08 +0200)
src/dissect/dissect.c

index fda688b21e14e2fefc2e89a15f9fdf5663a6b53f..55232914ed3b9ca6f35ba13cfd6a8dee6a307a18 100644 (file)
@@ -102,6 +102,7 @@ static RuntimeScope arg_runtime_scope = _RUNTIME_SCOPE_INVALID;
 static bool arg_all = false;
 static uid_t arg_uid_base = UID_INVALID;
 static bool arg_quiet = false;
+static ImageFilter *arg_image_filter = NULL;
 
 STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_root, freep);
@@ -110,6 +111,7 @@ STATIC_DESTRUCTOR_REGISTER(arg_verity_settings, verity_settings_done);
 STATIC_DESTRUCTOR_REGISTER(arg_argv, strv_freep);
 STATIC_DESTRUCTOR_REGISTER(arg_loop_ref, freep);
 STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_image_filter, image_filter_freep);
 
 static int help(void) {
         _cleanup_free_ char *link = NULL;
@@ -155,6 +157,8 @@ static int help(void) {
                "                          not embedded in IMAGE\n"
                "     --image-policy=POLICY\n"
                "                          Specify image dissection policy\n"
+               "     --image-filter=FILTER\n"
+               "                          Specify image dissection filter\n"
                "     --json=pretty|short|off\n"
                "                          Generate JSON output\n"
                "     --loop-ref=NAME      Set reference string for loopback device\n"
@@ -295,6 +299,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_SYSTEM,
                 ARG_USER,
                 ARG_ALL,
+                ARG_IMAGE_FILTER,
         };
 
         static const struct option options[] = {
@@ -336,6 +341,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "user",          no_argument,       NULL, ARG_USER          },
                 { "all",           no_argument,       NULL, ARG_ALL           },
                 { "quiet",         no_argument,       NULL, 'q'               },
+                { "image-filter",  required_argument, NULL, ARG_IMAGE_FILTER  },
                 {}
         };
 
@@ -610,6 +616,17 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_quiet = true;
                         break;
 
+                case ARG_IMAGE_FILTER: {
+                        _cleanup_(image_filter_freep) ImageFilter *f = NULL;
+                        r = image_filter_parse(optarg, &f);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to parse image filter expression: %s", optarg);
+
+                        image_filter_free(arg_image_filter);
+                        arg_image_filter = TAKE_PTR(f);
+                        break;
+                }
+
                 case '?':
                         return -EINVAL;
 
@@ -2108,7 +2125,7 @@ static int action_validate(void) {
                         &arg_verity_settings,
                         /* mount_options= */ NULL,
                         arg_image_policy,
-                        /* image_filter= */ NULL,
+                        arg_image_filter,
                         arg_flags,
                         /* ret= */ NULL);
         if (r < 0)
@@ -2232,7 +2249,7 @@ static int run(int argc, char *argv[]) {
                                                 &arg_verity_settings,
                                                 /* mount_options= */ NULL,
                                                 arg_image_policy,
-                                                /* image_filter= */ NULL,
+                                                arg_image_filter,
                                                 arg_flags,
                                                 &m);
                                 if (r < 0)