From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Price Date: Thu, 23 Jan 2020 15:55:40 +0000 Subject: [Cluster-devel] [PATCH 01/13] restoremeta: Use zlib by file descriptor In-Reply-To: <20200123155552.1080247-1-anprice@redhat.com> References: <20200123155552.1080247-1-anprice@redhat.com> Message-ID: <20200123155552.1080247-2-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 --- 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