[PATCH] Support build on NetBSD

Sergey A. Osokin osa at freebsd.org.ru
Sat Aug 8 21:07:03 UTC 2020


Hi,

a couple of patches to support Unit build on NetBSD.

--
Sergey A. Osokin
-------------- next part --------------
--- src/nxt_conn_write.c.orig	2020-05-28 12:04:00.000000000 -0400
+++ src/nxt_conn_write.c	2020-08-08 16:49:50.752693316 -0400
@@ -266,6 +266,21 @@
     res = sendfile(s, fd, &pos, size);
 #endif
 
+#ifdef NXT_HAVE_NETBSD_SENDFILE
+    struct stat fileinfo;
+    void *fmem = NULL;
+    res = fstat(fd, &fileinfo);
+    if (res == 0) {
+        fmem = mmap(NULL, fileinfo.st_size, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0);
+    }
+    if (fmem != NULL) {
+        res = write(s, fmem, fileinfo.st_size);
+        munmap(fmem, fileinfo.st_size);
+    } else {
+        res = -1;
+    }
+#endif 
+
     return res;
 }
 
-------------- next part --------------
--- auto/sendfile.orig	2020-08-08 16:00:55.378410575 -0400
+++ auto/sendfile	2020-08-08 16:16:14.270362755 -0400
@@ -5,6 +5,7 @@
 
 NXT_HAVE_LINUX_SENDFILE=NO
 NXT_HAVE_FREEBSD_SENDFILE=NO
+NXT_HAVE_NETBSD_SENDFILE=NO
 NXT_HAVE_MACOSX_SENDFILE=NO
 NXT_HAVE_SOLARIS_SENDFILEV=NO
 NXT_HAVE_AIX_SEND_FILE=NO
@@ -82,6 +83,34 @@
     fi
 fi
 
+if [ $nxt_found = no ]; then
+
+    # NetBSD has no sendfile().
+
+    nxt_feature="NetBSD sendfile()"
+    nxt_feature_name=NXT_HAVE_NETBSD_SENDFILE
+    nxt_feature_libs=
+    nxt_feature_test="#include <sys/types.h>
+                      #include <sys/mman.h>
+                      #include <sys/stat.h>
+                      #include <fcntl.h>
+                      #include <unistd.h>
+
+                      int main() {
+                          struct stat f;
+                          void *m = NULL;
+
+                          fstat(-1, &f);
+                          m = mmap(NULL, f.st_size, PROT_READ, MAP_FILE | MAP_SHARED, -1, 0);
+                          write(-1, m, f.st_size);
+                          munmap(m, f.st_size);
+                      }"
+    . auto/feature
+
+    if [ $nxt_found = yes ]; then
+        NXT_HAVE_NETBSD_SENDFILE=YES
+    fi
+fi
 
 if [ $nxt_found = no ]; then
     $echo


More information about the unit mailing list