From: Lennart Poettering Date: Tue, 14 Mar 2023 21:46:56 +0000 (+0100) Subject: dissect-image: add dissected_image_close() that closes all references to resources X-Git-Tag: v256-rc1~283^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9444e54e56b3d9ea81135700abe0792ead7f69ae;p=thirdparty%2Fsystemd.git dissect-image: add dissected_image_close() that closes all references to resources --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index a0832c98281..ebaff0df123 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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; diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index 559d5b861d9..416c9cb46b0 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -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);