osproc: Define and select spawn/fork same way

Previously startProcessAuxFork was defined even when it was unused, also the
compile time condition to select spawn vs fork was not always the same for
definitions and calls.

This change just defines the condition in one place as constant, then in other
places we just check for `when useProcessAuxSpawn`.
This commit is contained in:
Adam Strzelecki 2015-09-03 18:00:15 +02:00
commit a9f114cf13

View file

@ -614,9 +614,12 @@ elif not defined(useNimRtl):
optionPoStdErrToStdOut: bool
{.deprecated: [TStartProcessData: StartProcessData].}
when not defined(useFork):
const useProcessAuxSpawn = declared(posix_spawn) and not defined(useFork) and
not defined(useClone) and not defined(linux)
when useProcessAuxSpawn:
proc startProcessAuxSpawn(data: StartProcessData): Pid {.
tags: [ExecIOEffect, ReadEnvEffect], gcsafe.}
else:
proc startProcessAuxFork(data: StartProcessData): Pid {.
tags: [ExecIOEffect, ReadEnvEffect], gcsafe.}
{.push stacktrace: off, profiler: off.}
@ -674,9 +677,7 @@ elif not defined(useNimRtl):
data.optionPoStdErrToStdOut = poStdErrToStdOut in options
data.workingDir = workingDir
when declared(posix_spawn) and not defined(useFork) and
not defined(useClone) and not defined(linux):
when useProcessAuxSpawn:
pid = startProcessAuxSpawn(data)
else:
pid = startProcessAuxFork(data)
@ -706,7 +707,7 @@ elif not defined(useNimRtl):
discard close(pStdin[readIdx])
discard close(pStdout[writeIdx])
when not defined(useFork):
when useProcessAuxSpawn:
proc startProcessAuxSpawn(data: StartProcessData): Pid =
var attr: Tposix_spawnattr
var fops: Tposix_spawn_file_actions
@ -752,7 +753,7 @@ elif not defined(useNimRtl):
discard posix_spawnattr_destroy(attr)
chck res
return pid
else:
proc startProcessAuxFork(data: StartProcessData): Pid =
if pipe(data.pErrorPipe) != 0:
raiseOSError(osLastError())