about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-11-04 08:55:31 +0100
committerbptato <nincsnevem662@gmail.com>2024-11-04 08:56:05 +0100
commit64308987e0ae245977a875ec0015dd1d051587bd (patch)
tree16043d09ce99bfb24df5865c39496fa18a879c3f /src/io
parentcfc6bb4c3cb773b035fa54de2aa90efbdd47216e (diff)
downloadchawan-64308987e0ae245977a875ec0015dd1d051587bd.tar.gz
dynstream: fix crash on *BSD
turns out fchmod on sockets only works on Linux.
Diffstat (limited to 'src/io')
-rw-r--r--src/io/dynstream.nim5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/io/dynstream.nim b/src/io/dynstream.nim
index 19944ed5..063dcfc4 100644
--- a/src/io/dynstream.nim
+++ b/src/io/dynstream.nim
@@ -479,7 +479,10 @@ proc newServerSocket*(fd: cint; sockDir: string; sockDirFd: cint; pid: int):
 proc newServerSocket*(sockDir: string; sockDirFd: cint; pid: int): ServerSocket =
   let fd = cint(socket(AF_UNIX, SOCK_STREAM, IPPROTO_IP))
   let ssock = newServerSocket(fd, sockDir, sockDirFd, pid)
-  doAssert fchmod(fd, 0o700) == 0
+  # POSIX leaves the result of fchmod on a socket undefined, and while
+  # it works on Linux, it returns an error on BSD descendants.
+  when defined(linux):
+    doAssert fchmod(fd, 0o700) == 0
   if sockDirFd == -1:
     discard tryRemoveFile(ssock.path)
     if bind_unix_from_c(fd, cstring(ssock.path), cint(ssock.path.len)) != 0: