From b839101aacb38131f0f4313b1b76316e663e58e9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 23 Mar 2023 12:33:41 +0100 Subject: fileio: add new helper fdopen_independent() This is a combination of fdopen() and fd_reopen(). i.e. it first reopens the fd, and then converts that into a FILE*. We do this at various places already manually. let's move this into a helper call of its own. --- src/portable/portable.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/portable') diff --git a/src/portable/portable.c b/src/portable/portable.c index 23102e51dd..664c873ca7 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -594,7 +594,6 @@ static int extract_image_and_extensions( _cleanup_(portable_metadata_unrefp) PortableMetadata *extension_release_meta = NULL; _cleanup_hashmap_free_ Hashmap *extra_unit_files = NULL; _cleanup_strv_free_ char **extension_release = NULL; - _cleanup_close_ int extension_release_fd = -EBADF; _cleanup_fclose_ FILE *f = NULL; const char *e; @@ -610,11 +609,7 @@ static int extract_image_and_extensions( continue; /* We need to keep the fd valid, to return the PortableMetadata to the caller. */ - extension_release_fd = fd_reopen(extension_release_meta->fd, O_CLOEXEC|O_RDONLY); - if (extension_release_fd < 0) - return extension_release_fd; - - r = take_fdopen_unlocked(&extension_release_fd, "r", &f); + r = fdopen_independent(extension_release_meta->fd, "re", &f); if (r < 0) return r; -- cgit v1.2.1