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:
parent
580855d2eb
commit
a9f114cf13
1 changed files with 38 additions and 37 deletions
|
|
@ -614,9 +614,12 @@ elif not defined(useNimRtl):
|
||||||
optionPoStdErrToStdOut: bool
|
optionPoStdErrToStdOut: bool
|
||||||
{.deprecated: [TStartProcessData: StartProcessData].}
|
{.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 {.
|
proc startProcessAuxSpawn(data: StartProcessData): Pid {.
|
||||||
tags: [ExecIOEffect, ReadEnvEffect], gcsafe.}
|
tags: [ExecIOEffect, ReadEnvEffect], gcsafe.}
|
||||||
|
else:
|
||||||
proc startProcessAuxFork(data: StartProcessData): Pid {.
|
proc startProcessAuxFork(data: StartProcessData): Pid {.
|
||||||
tags: [ExecIOEffect, ReadEnvEffect], gcsafe.}
|
tags: [ExecIOEffect, ReadEnvEffect], gcsafe.}
|
||||||
{.push stacktrace: off, profiler: off.}
|
{.push stacktrace: off, profiler: off.}
|
||||||
|
|
@ -674,9 +677,7 @@ elif not defined(useNimRtl):
|
||||||
data.optionPoStdErrToStdOut = poStdErrToStdOut in options
|
data.optionPoStdErrToStdOut = poStdErrToStdOut in options
|
||||||
data.workingDir = workingDir
|
data.workingDir = workingDir
|
||||||
|
|
||||||
|
when useProcessAuxSpawn:
|
||||||
when declared(posix_spawn) and not defined(useFork) and
|
|
||||||
not defined(useClone) and not defined(linux):
|
|
||||||
pid = startProcessAuxSpawn(data)
|
pid = startProcessAuxSpawn(data)
|
||||||
else:
|
else:
|
||||||
pid = startProcessAuxFork(data)
|
pid = startProcessAuxFork(data)
|
||||||
|
|
@ -706,7 +707,7 @@ elif not defined(useNimRtl):
|
||||||
discard close(pStdin[readIdx])
|
discard close(pStdin[readIdx])
|
||||||
discard close(pStdout[writeIdx])
|
discard close(pStdout[writeIdx])
|
||||||
|
|
||||||
when not defined(useFork):
|
when useProcessAuxSpawn:
|
||||||
proc startProcessAuxSpawn(data: StartProcessData): Pid =
|
proc startProcessAuxSpawn(data: StartProcessData): Pid =
|
||||||
var attr: Tposix_spawnattr
|
var attr: Tposix_spawnattr
|
||||||
var fops: Tposix_spawn_file_actions
|
var fops: Tposix_spawn_file_actions
|
||||||
|
|
@ -752,7 +753,7 @@ elif not defined(useNimRtl):
|
||||||
discard posix_spawnattr_destroy(attr)
|
discard posix_spawnattr_destroy(attr)
|
||||||
chck res
|
chck res
|
||||||
return pid
|
return pid
|
||||||
|
else:
|
||||||
proc startProcessAuxFork(data: StartProcessData): Pid =
|
proc startProcessAuxFork(data: StartProcessData): Pid =
|
||||||
if pipe(data.pErrorPipe) != 0:
|
if pipe(data.pErrorPipe) != 0:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue