From cea8e6a01bb03bbe565c9bf5dd4f439f30ca953f Mon Sep 17 00:00:00 2001
From: Jan Beich <jbeich@FreeBSD.org>
Date: Fri, 28 Feb 2020 16:49:38 +0000
Subject: Bug 1618914 - [Wayland] Fall back to ftruncate if posix_fallocate isn't supported by filesystem.

diff --git widget/gtk/WaylandShmBuffer.cpp widget/gtk/WaylandShmBuffer.cpp
index 42eeedd3429ac..2a5c23d287413 100644
--- widget/gtk/WaylandShmBuffer.cpp
+++ widget/gtk/WaylandShmBuffer.cpp
@@ -67,36 +67,37 @@ static int WaylandAllocateShmMemory(int aSize) {
     return -1;
   }
 
   int ret = 0;
 #ifdef HAVE_POSIX_FALLOCATE
   do {
     ret = posix_fallocate(fd, 0, aSize);
   } while (ret == EINTR);
-  if (ret != 0) {
+  if (ret == 0) {
+    return fd;
+  } else if (ret != ENODEV && ret != EINVAL && ret != EOPNOTSUPP) {
     NS_WARNING(
         nsPrintfCString("posix_fallocate() fails to allocate shm memory: %s",
                         strerror(ret))
             .get());
     close(fd);
     return -1;
   }
-#else
+#endif
   do {
     ret = ftruncate(fd, aSize);
   } while (ret < 0 && errno == EINTR);
   if (ret < 0) {
     NS_WARNING(nsPrintfCString("ftruncate() fails to allocate shm memory: %s",
                                strerror(ret))
                    .get());
     close(fd);
     fd = -1;
   }
-#endif
 
   return fd;
 }
 
 /* static */
 RefPtr<WaylandShmPool> WaylandShmPool::Create(
     const RefPtr<nsWaylandDisplay>& aWaylandDisplay, int aSize) {
   RefPtr<WaylandShmPool> shmPool = new WaylandShmPool(aSize);
