Fixes to support Dragonfly BSD. (#5552)

* Fix kqueue.nim and ansi_c.nim to support dragonfly.
* Fix ioselectors.nim, threads.nim to support dragonfly.
* Fix deprecated dealloc call in tioselectors.nim.
* Fix tfsmonitor.nim test to run only on Linux.
* Fix osproc.nim return wrong exit codes.
* Fix getAppFilename() for dragonfly.
* Fix proper exit code handling.
This commit is contained in:
Eugene Kabanov 2017-03-17 09:22:11 +02:00 • committed by Andreas Rumpf
commit 336a7c9b3f
9 changed files with 39 additions and 20 deletions

View file

@ -11,7 +11,8 @@
from posix import Timespec from posix import Timespec
when defined(macosx) or defined(freebsd) or defined(openbsd): when defined(macosx) or defined(freebsd) or defined(openbsd) or
defined(dragonfly):
const const
EVFILT_READ* = -1 EVFILT_READ* = -1
EVFILT_WRITE* = -2 EVFILT_WRITE* = -2
@ -40,6 +41,11 @@ elif defined(freebsd):
EVFILT_FS* = -9 ## filesystem events EVFILT_FS* = -9 ## filesystem events
EVFILT_LIO* = -10 ## attached to lio requests EVFILT_LIO* = -10 ## attached to lio requests
EVFILT_USER* = -11 ## user events EVFILT_USER* = -11 ## user events
elif defined(dragonfly):
const
EVFILT_EXCEPT* = -8 ## exceptional conditions
EVFILT_USER* = -9 ## user events
EVFILT_FS* = -10 ## filesystem events
# Actions: # Actions:
const const
@ -64,9 +70,9 @@ const
const const
EV_EOF* = 0x8000 ## EOF detected EV_EOF* = 0x8000 ## EOF detected
EV_ERROR* = 0x4000 ## Error, data contains errno EV_ERROR* = 0x4000 ## Error, data contains errno
EV_NODATA* = 0x1000 ## EOF and no more data
when defined(macosx) or defined(freebsd) or defined(dragonfly):
when defined(macosx) or defined(freebsd):
# EVFILT_USER is not supported by OpenBSD and NetBSD # EVFILT_USER is not supported by OpenBSD and NetBSD
# #
# data/hint flags/masks for EVFILT_USER, shared with userspace # data/hint flags/masks for EVFILT_USER, shared with userspace

View file

@ -33,12 +33,14 @@ const hasThreadSupport = compileOption("threads") and defined(threadsafe)
const ioselSupportedPlatform* = defined(macosx) or defined(freebsd) or const ioselSupportedPlatform* = defined(macosx) or defined(freebsd) or
defined(netbsd) or defined(openbsd) or defined(netbsd) or defined(openbsd) or
defined(dragonfly) or
(defined(linux) and not defined(android)) (defined(linux) and not defined(android))
## This constant is used to determine whether the destination platform is ## This constant is used to determine whether the destination platform is
## fully supported by ``ioselectors`` module. ## fully supported by ``ioselectors`` module.
const bsdPlatform = defined(macosx) or defined(freebsd) or const bsdPlatform = defined(macosx) or defined(freebsd) or
defined(netbsd) or defined(openbsd) defined(netbsd) or defined(openbsd) or
defined(dragonfly)
when defined(nimdoc): when defined(nimdoc):
type type

View file

@ -22,7 +22,7 @@ const
when defined(kqcache): when defined(kqcache):
const CACHE_EVENTS = true const CACHE_EVENTS = true
when defined(macosx) or defined(freebsd): when defined(macosx) or defined(freebsd) or defined(dragonfly):
when defined(macosx): when defined(macosx):
const MAX_DESCRIPTORS_ID = 29 # KERN_MAXFILESPERPROC (MacOS) const MAX_DESCRIPTORS_ID = 29 # KERN_MAXFILESPERPROC (MacOS)
else: else:

View file

@ -1464,7 +1464,7 @@ when declared(paramCount) or defined(nimdoc):
for i in 1..paramCount(): for i in 1..paramCount():
result.add(paramStr(i)) result.add(paramStr(i))
when defined(freebsd): when defined(freebsd) or defined(dragonfly):
proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize, proc sysctl(name: ptr cint, namelen: cuint, oldp: pointer, oldplen: ptr csize,
newp: pointer, newplen: csize): cint newp: pointer, newplen: csize): cint
{.importc: "sysctl",header: """#include <sys/types.h> {.importc: "sysctl",header: """#include <sys/types.h>
@ -1472,9 +1472,13 @@ when defined(freebsd):
const const
CTL_KERN = 1 CTL_KERN = 1
KERN_PROC = 14 KERN_PROC = 14
KERN_PROC_PATHNAME = 12
MAX_PATH = 1024 MAX_PATH = 1024
when defined(freebsd):
const KERN_PROC_PATHNAME = 12
else:
const KERN_PROC_PATHNAME = 9
proc getApplFreebsd(): string = proc getApplFreebsd(): string =
var pathLength = csize(MAX_PATH) var pathLength = csize(MAX_PATH)
result = newString(pathLength) result = newString(pathLength)
@ -1578,7 +1582,7 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
result = getApplAux("/proc/self/exe") result = getApplAux("/proc/self/exe")
elif defined(solaris): elif defined(solaris):
result = getApplAux("/proc/" & $getpid() & "/path/a.out") result = getApplAux("/proc/" & $getpid() & "/path/a.out")
elif defined(freebsd): elif defined(freebsd) or defined(dragonfly):
result = getApplFreebsd() result = getApplFreebsd()
# little heuristic that may work on other POSIX-like systems: # little heuristic that may work on other POSIX-like systems:
if result.len == 0: if result.len == 0:

View file

@ -990,7 +990,7 @@ elif not defined(useNimRtl):
import kqueue, times import kqueue, times
proc waitForExit(p: Process, timeout: int = -1): int = proc waitForExit(p: Process, timeout: int = -1): int =
if p.exitStatus != -3: return int(p.exitStatus) shr 8 if p.exitStatus != -3: return ((p.exitStatus and 0xFF00) shr 8)
if timeout == -1: if timeout == -1:
var status : cint = 1 var status : cint = 1
if waitpid(p.id, status, 0) < 0: if waitpid(p.id, status, 0) < 0:
@ -1155,13 +1155,13 @@ elif not defined(useNimRtl):
proc peekExitCode(p: Process): int = proc peekExitCode(p: Process): int =
var status : cint = 1 var status : cint = 1
if p.exitStatus != -3: return int(p.exitStatus) shr 8 if p.exitStatus != -3: return ((p.exitStatus and 0xFF00) shr 8)
var ret = waitpid(p.id, status, WNOHANG) var ret = waitpid(p.id, status, WNOHANG)
var b = ret == int(p.id) var b = ret == int(p.id)
if b: result = -1 if b: result = -1
if WIFEXITED(status): if WIFEXITED(status):
p.exitStatus = status p.exitStatus = status
result = p.exitStatus.int shr 8 result = (status and 0xFF00) shr 8
else: else:
result = -1 result = -1

View file

@ -38,7 +38,8 @@ when defined(windows):
SIGSEGV = cint(11) SIGSEGV = cint(11)
SIGTERM = cint(15) SIGTERM = cint(15)
elif defined(macosx) or defined(linux) or defined(freebsd) or elif defined(macosx) or defined(linux) or defined(freebsd) or
defined(openbsd) or defined(netbsd) or defined(solaris): defined(openbsd) or defined(netbsd) or defined(solaris) or
defined(dragonfly):
const const
SIGABRT = cint(6) SIGABRT = cint(6)
SIGFPE = cint(8) SIGFPE = cint(8)

View file

@ -204,7 +204,12 @@ else:
proc getThreadId*(): int = proc getThreadId*(): int =
## get the ID of the currently running thread. ## get the ID of the currently running thread.
result = int(syscall(NR_gettid)) result = int(syscall(NR_gettid))
elif defined(macosx) or defined(bsd): elif defined(dragonfly):
proc lwp_gettid(): int32 {.importc, header: "unistd.h".}
proc getThreadId*(): int =
result = int(lwp_gettid())
elif defined(macosx) or defined(freebsd) or defined(openbsd) or defined(netbsd):
proc pthread_threadid_np(y: pointer; x: var uint64): cint {.importc, header: "pthread.h".} proc pthread_threadid_np(y: pointer; x: var uint64): cint {.importc, header: "pthread.h".}
proc getThreadId*(): int = proc getThreadId*(): int =
@ -221,7 +226,6 @@ else:
## get the ID of the currently running thread. ## get the ID of the currently running thread.
result = int(thr_self()) result = int(thr_self())
const const
emulatedThreadVars = compileOption("tlsEmulation") emulatedThreadVars = compileOption("tlsEmulation")

View file

@ -45,11 +45,11 @@ when not defined(windows):
var aiList = getAddrInfo("0.0.0.0", Port(13337)) var aiList = getAddrInfo("0.0.0.0", Port(13337))
if bindAddr(server_socket, aiList.ai_addr, if bindAddr(server_socket, aiList.ai_addr,
aiList.ai_addrlen.Socklen) < 0'i32: aiList.ai_addrlen.Socklen) < 0'i32:
dealloc(aiList) freeAddrInfo(aiList)
raiseOSError(osLastError()) raiseOSError(osLastError())
if server_socket.listen() == -1: if server_socket.listen() == -1:
raiseOSError(osLastError()) raiseOSError(osLastError())
dealloc(aiList) freeAddrInfo(aiList)
aiList = getAddrInfo("127.0.0.1", Port(13337)) aiList = getAddrInfo("127.0.0.1", Port(13337))
discard posix.connect(client_socket, aiList.ai_addr, discard posix.connect(client_socket, aiList.ai_addr,
@ -58,7 +58,7 @@ when not defined(windows):
registerHandle(selector, server_socket, {Event.Read}, 0) registerHandle(selector, server_socket, {Event.Read}, 0)
registerHandle(selector, client_socket, {Event.Write}, 0) registerHandle(selector, client_socket, {Event.Write}, 0)
dealloc(aiList) freeAddrInfo(aiList)
discard selector.select(100) discard selector.select(100)
var sockAddress: SockAddr var sockAddress: SockAddr
@ -497,15 +497,15 @@ else:
var aiList = getAddrInfo("0.0.0.0", Port(13337)) var aiList = getAddrInfo("0.0.0.0", Port(13337))
if bindAddr(server_socket, aiList.ai_addr, if bindAddr(server_socket, aiList.ai_addr,
aiList.ai_addrlen.Socklen) < 0'i32: aiList.ai_addrlen.Socklen) < 0'i32:
dealloc(aiList) freeAddrInfo(aiList)
raiseOSError(osLastError()) raiseOSError(osLastError())
discard server_socket.listen() discard server_socket.listen()
dealloc(aiList) freeAddrInfo(aiList)
aiList = getAddrInfo("127.0.0.1", Port(13337)) aiList = getAddrInfo("127.0.0.1", Port(13337))
discard connect(client_socket, aiList.ai_addr, discard connect(client_socket, aiList.ai_addr,
aiList.ai_addrlen.Socklen) aiList.ai_addrlen.Socklen)
dealloc(aiList) freeAddrInfo(aiList)
# for some reason Windows select doesn't return both # for some reason Windows select doesn't return both
# descriptors from first call, so we need to make 2 calls # descriptors from first call, so we need to make 2 calls
discard selector.select(100) discard selector.select(100)

View file

@ -1,5 +1,7 @@
discard """ discard """
disabled: windows disabled: windows
disabled: bsd
disabled: macosx
""" """
import unittest import unittest