Open the metadata file with open and pass the fd to zlib instead of the path. This is groundwork for supporting bzip2. (gzclose() still closes the fd later).
Signed-off-by: Andrew Price <[email protected]> --- gfs2/edit/savemeta.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c index 18432b7c..9de53a97 100644 --- a/gfs2/edit/savemeta.c +++ b/gfs2/edit/savemeta.c @@ -1197,6 +1197,7 @@ void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly) gzFile gzfd; off_t pos = 0; struct savemeta_header smh = {0}; + int fd; termlines = 0; if (!in_fn) @@ -1204,7 +1205,12 @@ void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly) if (!printonly && !out_device) complain("No destination file system specified."); - gzfd = gzopen(in_fn, "rb"); + fd = open(in_fn, O_RDONLY|O_CLOEXEC); + if (fd < 0) { + perror("Could not open file"); + exit(1); + } + gzfd = gzdopen(fd, "rb"); if (!gzfd) die("Can't open source file %s: %s\n", in_fn, strerror(errno)); -- 2.24.1
