bridges/source/cpp_uno/shared/vtablefactory.cxx |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

New commits:
commit 9fb26786b75e30df593378954044af4e4753a192
Author:     Emmanuel Dreyfus <m...@netbsd.org>
AuthorDate: Thu Apr 10 17:31:17 2025 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Wed Apr 16 16:39:44 2025 +0200

    tdf#165837 Avoid UNO failure if filesystem does not implement fallocate.
    
    posix_fallocate() may be available but unimplemented for a
    given filesystem. Detect that situation once and use ftruncate()
    instead.
    
    Change-Id: Ic1422bfbcbcda21ef4923a6fc30ceb5ce662db3e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183977
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    Tested-by: Jenkins

diff --git a/bridges/source/cpp_uno/shared/vtablefactory.cxx 
b/bridges/source/cpp_uno/shared/vtablefactory.cxx
index 10db7cc505a7..e428d042be56 100644
--- a/bridges/source/cpp_uno/shared/vtablefactory.cxx
+++ b/bridges/source/cpp_uno/shared/vtablefactory.cxx
@@ -282,18 +282,25 @@ bool VtableFactory::createBlock(Block &block, sal_Int32 
slotCount) const
         }
         unlink(tmpfname.get());
         tmpfname.reset();
+
+        int err;
 #if defined(HAVE_POSIX_FALLOCATE)
-        int err = posix_fallocate(block.fd, 0, block.size);
-#else
-        int err = ftruncate(block.fd, block.size);
+        /*
+         * configure may have detected posix_fallocate() is available,
+         * while the underlying filesystem does not implement it. In
+         * this case, posix_fallocate() will fail with EOPNOTSUPP
+         * (at least on NetBSD), and we must fallback to ftruncate().
+         */
+        err = posix_fallocate(block.fd, 0, block.size);
+        if (err == EOPNOTSUPP)
 #endif
+        {
+            err = ftruncate(block.fd, block.size);
+        }
+
         if (err != 0)
         {
-#if defined(HAVE_POSIX_FALLOCATE)
-            SAL_WARN("bridges", "posix_fallocate failed with code " << err);
-#else
             SAL_WARN("bridges", "truncation of executable memory area failed 
with code " << err);
-#endif
             close(block.fd);
             block.fd = -1;
             break;

Reply via email to