From: Michael Tremer Date: Sun, 12 Jan 2025 11:27:07 +0000 (+0000) Subject: archive: Don't try to set fadvise() on an invalid fd X-Git-Tag: 0.9.30~406 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73b1e3a3af4a1b7206a914da7f72e40dc7b87e84;p=pakfire.git archive: Don't try to set fadvise() on an invalid fd Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/archive.c b/src/pakfire/archive.c index 4c76fcd1..f7822c24 100644 --- a/src/pakfire/archive.c +++ b/src/pakfire/archive.c @@ -179,6 +179,12 @@ static int archive_read_file_open(struct archive* a, FILE* f) { goto ERROR; } + // Let the kernel know, that we will read the file sequentially + r = posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); + if (r < 0) { + r = -errno; + goto ERROR; + } // Re-open the file handle f = fdopen(fd, "r"); @@ -197,15 +203,14 @@ static int archive_read_file_open(struct archive* a, FILE* f) { // Allocate an object file = calloc(1, sizeof(*file)); - if (!file) + if (!file) { + r = -errno; goto ERROR; + } // Store the file handle file->f = f; - // Let the kernel know, that we will read the file sequentially - posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); - // Open the archive return archive_read_open2(a, file, NULL, archive_file_read, archive_file_skip, archive_file_close);