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

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

View file

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

View file

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

View file

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