From: Aki Tuomi Date: Fri, 29 Dec 2023 14:05:27 +0000 (+0200) Subject: lib-fs,lib-storage: Fix posix_fadvise usage X-Git-Tag: 2.4.0~1381 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2decb5ae26bae103c3562f355da12608b17ffcef;p=thirdparty%2Fdovecot%2Fcore.git lib-fs,lib-storage: Fix posix_fadvise usage Return value is non-zero on error, not negative. --- diff --git a/src/lib-fs/fs-posix.c b/src/lib-fs/fs-posix.c index b60555ddbd..b996539c41 100644 --- a/src/lib-fs/fs-posix.c +++ b/src/lib-fs/fs-posix.c @@ -424,7 +424,7 @@ static bool fs_posix_prefetch(struct fs_file *_file, uoff_t length ATTR_UNUSED) /* HAVE_POSIX_FADVISE alone isn't enough for CentOS 4.9 */ #if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED) - if (posix_fadvise(file->fd, 0, length, POSIX_FADV_WILLNEED) < 0) { + if ((errno = posix_fadvise(file->fd, 0, (off_t)length, POSIX_FADV_WILLNEED)) != 0) { e_error(_file->event, "posix_fadvise(%s) failed: %m", file->full_path); return TRUE; } diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index f660770d15..ddded22e38 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -2211,8 +2211,8 @@ bool index_mail_prefetch(struct mail *_mail) if ((mail->data.access_part & (READ_BODY | PARSE_BODY)) != 0) len = 0; else - len = MAIL_READ_HDR_BLOCK_SIZE; - if (posix_fadvise(fd, 0, len, POSIX_FADV_WILLNEED) < 0) { + len = (off_t)MAIL_READ_HDR_BLOCK_SIZE; + if ((errno = posix_fadvise(fd, 0, len, POSIX_FADV_WILLNEED)) != 0) { e_error(mail_event(_mail), "posix_fadvise(%s) failed: %m", i_stream_get_name(mail->data.stream));