]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: add dissected_image_close() that closes all references to resources
authorLennart Poettering <lennart@poettering.net>
Tue, 14 Mar 2023 21:46:56 +0000 (22:46 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 6 Apr 2024 14:08:23 +0000 (16:08 +0200)
src/shared/dissect-image.c
src/shared/dissect-image.h

index a0832c98281faffdbd3dbbc9ac24141b86d6f0b4..ebaff0df123f32e9977816ebcd665700b7767229 100644 (file)
@@ -1643,6 +1643,20 @@ int dissect_image_file_and_warn(
                         verity);
 }
 
+void dissected_image_close(DissectedImage *m) {
+        if (!m)
+                return;
+
+        /* Closes all fds we keep open assocated with this, but nothing else */
+
+        FOREACH_ARRAY(p, m->partitions, _PARTITION_DESIGNATOR_MAX) {
+                p->mount_node_fd = safe_close(p->mount_node_fd);
+                p->fsmount_fd = safe_close(p->fsmount_fd);
+        }
+
+        m->loop = loop_device_unref(m->loop);
+}
+
 DissectedImage* dissected_image_unref(DissectedImage *m) {
         if (!m)
                 return NULL;
index 559d5b861d9288eef6397fed4dddacb2a3d0cad2..416c9cb46b030ba64c2e155934de3865a2586f51 100644 (file)
@@ -163,6 +163,7 @@ int dissect_image_file_and_warn(const char *path, const VeritySettings *verity,
 int dissect_loop_device(LoopDevice *loop, const VeritySettings *verity, const MountOptions *mount_options, const ImagePolicy *image_policy, DissectImageFlags flags, DissectedImage **ret);
 int dissect_loop_device_and_warn(LoopDevice *loop, const VeritySettings *verity, const MountOptions *mount_options, const ImagePolicy *image_policy, DissectImageFlags flags, DissectedImage **ret);
 
+void dissected_image_close(DissectedImage *m);
 DissectedImage* dissected_image_unref(DissectedImage *m);
 DEFINE_TRIVIAL_CLEANUP_FUNC(DissectedImage*, dissected_image_unref);