More fixes for Haiku (#13774)

* osproc: move fork-based code path under the when conditional

* osproc: avoid using the environ global on Haiku

* osenv: import environ from stdlib.h on Haiku

Haiku's environ is declared in `<stdlib.h>` by default, differing from
POSIX and/or Linux. Import it from there to avoid collision with anyone
importing `<stdlib.h>` from Nim.
This commit is contained in:
alaviss 2020-03-27 08:08:13 +00:00 • committed by GitHub
commit 0eaacbc2c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 46 deletions

View file

@ -81,6 +81,8 @@ else:
# at runtime. # at runtime.
proc NSGetEnviron(): ptr cstringArray {. proc NSGetEnviron(): ptr cstringArray {.
importc: "_NSGetEnviron", header: "<crt_externs.h>".} importc: "_NSGetEnviron", header: "<crt_externs.h>".}
elif defined(haiku):
var gEnv {.importc: "environ", header: "<stdlib.h>".}: cstringArray
else: else:
var gEnv {.importc: "environ".}: cstringArray var gEnv {.importc: "environ".}: cstringArray

View file

@ -1009,7 +1009,8 @@ elif not defined(useNimRtl):
discard write(data.pErrorPipe[writeIdx], addr error, sizeof(error)) discard write(data.pErrorPipe[writeIdx], addr error, sizeof(error))
exitnow(1) exitnow(1)
when not defined(uClibc) and (not defined(linux) or defined(android)): when not defined(uClibc) and (not defined(linux) or defined(android)) and
not defined(haiku):
var environ {.importc.}: cstringArray var environ {.importc.}: cstringArray
proc startProcessAfterFork(data: ptr StartProcessData) = proc startProcessAfterFork(data: ptr StartProcessData) =
@ -1039,7 +1040,7 @@ elif not defined(useNimRtl):
discard fcntl(data.pErrorPipe[writeIdx], F_SETFD, FD_CLOEXEC) discard fcntl(data.pErrorPipe[writeIdx], F_SETFD, FD_CLOEXEC)
if (poUsePath in data.options): if (poUsePath in data.options):
when defined(uClibc) or defined(linux): when defined(uClibc) or defined(linux) or defined(haiku):
# uClibc environment (OpenWrt included) doesn't have the full execvpe # uClibc environment (OpenWrt included) doesn't have the full execvpe
let exe = findExe(data.sysCommand) let exe = findExe(data.sysCommand)
discard execve(exe, data.sysArgs, data.sysEnv) discard execve(exe, data.sysArgs, data.sysEnv)