fixes #1734, fixes #3138, fixes #3759

This commit is contained in:
araq 2017-09-01 19:25:08 +02:00
commit 85dc40c121

View file

@ -119,7 +119,8 @@ proc execProcess*(command: string,
poUsePath, poUsePath,
poEvalCommand}): TaintedString {. poEvalCommand}): TaintedString {.
rtl, extern: "nosp$1", rtl, extern: "nosp$1",
tags: [ExecIOEffect, ReadIOEffect].} tags: [ExecIOEffect, ReadIOEffect,
RootEffect].}
## A convenience procedure that executes ``command`` with ``startProcess`` ## A convenience procedure that executes ``command`` with ``startProcess``
## and returns its output as a string. ## and returns its output as a string.
## WARNING: this function uses poEvalCommand by default for backward compatibility. ## WARNING: this function uses poEvalCommand by default for backward compatibility.
@ -131,7 +132,8 @@ proc execProcess*(command: string,
## # Note: outp may have an interleave of text from the nim compile ## # Note: outp may have an interleave of text from the nim compile
## # and any output from mytestfile when it runs ## # and any output from mytestfile when it runs
proc execCmd*(command: string): int {.rtl, extern: "nosp$1", tags: [ExecIOEffect].} proc execCmd*(command: string): int {.rtl, extern: "nosp$1", tags: [ExecIOEffect,
ReadIOEffect, RootEffect].}
## Executes ``command`` and returns its error code. Standard input, output, ## Executes ``command`` and returns its error code. Standard input, output,
## error streams are inherited from the calling process. This operation ## error streams are inherited from the calling process. This operation
## is also often called `system`:idx:. ## is also often called `system`:idx:.
@ -145,7 +147,8 @@ proc startProcess*(command: string,
args: openArray[string] = [], args: openArray[string] = [],
env: StringTableRef = nil, env: StringTableRef = nil,
options: set[ProcessOption] = {poStdErrToStdOut}): options: set[ProcessOption] = {poStdErrToStdOut}):
Process {.rtl, extern: "nosp$1", tags: [ExecIOEffect, ReadEnvEffect].} Process {.rtl, extern: "nosp$1", tags: [ExecIOEffect, ReadEnvEffect,
RootEffect].}
## Starts a process. `Command` is the executable file, `workingDir` is the ## Starts a process. `Command` is the executable file, `workingDir` is the
## process's working directory. If ``workingDir == ""`` the current directory ## process's working directory. If ``workingDir == ""`` the current directory
## is used. `args` are the command line arguments that are passed to the ## is used. `args` are the command line arguments that are passed to the
@ -170,7 +173,7 @@ proc startProcess*(command: string,
proc startCmd*(command: string, options: set[ProcessOption] = { proc startCmd*(command: string, options: set[ProcessOption] = {
poStdErrToStdOut, poUsePath}): Process {. poStdErrToStdOut, poUsePath}): Process {.
tags: [ExecIOEffect, ReadEnvEffect], deprecated.} = tags: [ExecIOEffect, ReadEnvEffect, RootEffect], deprecated.} =
## Deprecated - use `startProcess` directly. ## Deprecated - use `startProcess` directly.
result = startProcess(command=command, options=options + {poEvalCommand}) result = startProcess(command=command, options=options + {poEvalCommand})
@ -721,7 +724,7 @@ elif not defined(useNimRtl):
inc(i) inc(i)
type StartProcessData = object type StartProcessData = object
sysCommand: cstring sysCommand: string
sysArgs: cstringArray sysArgs: cstringArray
sysEnv: cstringArray sysEnv: cstringArray
workingDir: cstring workingDir: cstring
@ -735,13 +738,13 @@ elif not defined(useNimRtl):
not defined(useClone) and not defined(linux) not defined(useClone) and not defined(linux)
when useProcessAuxSpawn: when useProcessAuxSpawn:
proc startProcessAuxSpawn(data: StartProcessData): Pid {. proc startProcessAuxSpawn(data: StartProcessData): Pid {.
tags: [ExecIOEffect, ReadEnvEffect], gcsafe.} tags: [ExecIOEffect, ReadEnvEffect, ReadDirEffect, RootEffect], gcsafe.}
else: else:
proc startProcessAuxFork(data: StartProcessData): Pid {. proc startProcessAuxFork(data: StartProcessData): Pid {.
tags: [ExecIOEffect, ReadEnvEffect], gcsafe.} tags: [ExecIOEffect, ReadEnvEffect, ReadDirEffect, RootEffect], gcsafe.}
{.push stacktrace: off, profiler: off.} {.push stacktrace: off, profiler: off.}
proc startProcessAfterFork(data: ptr StartProcessData) {. proc startProcessAfterFork(data: ptr StartProcessData) {.
tags: [ExecIOEffect, ReadEnvEffect], cdecl, gcsafe.} tags: [ExecIOEffect, ReadEnvEffect, ReadDirEffect, RootEffect], cdecl, gcsafe.}
{.pop.} {.pop.}
proc startProcess(command: string, proc startProcess(command: string,
@ -785,7 +788,7 @@ elif not defined(useNimRtl):
defer: deallocCStringArray(sysEnv) defer: deallocCStringArray(sysEnv)
var data: StartProcessData var data: StartProcessData
data.sysCommand = sysCommand shallowCopy(data.sysCommand, sysCommand)
data.sysArgs = sysArgs data.sysArgs = sysArgs
data.sysEnv = sysEnv data.sysEnv = sysEnv
data.pStdin = pStdin data.pStdin = pStdin
@ -950,11 +953,10 @@ elif not defined(useNimRtl):
discard fcntl(data.pErrorPipe[writeIdx], F_SETFD, FD_CLOEXEC) discard fcntl(data.pErrorPipe[writeIdx], F_SETFD, FD_CLOEXEC)
if data.optionPoUsePath: if data.optionPoUsePath:
when defined(uClibc): when defined(uClibc) or defined(linux):
# uClibc environment (OpenWrt included) doesn't have the full execvpe # uClibc environment (OpenWrt included) doesn't have the full execvpe
discard execve(data.sysCommand, data.sysArgs, data.sysEnv) let exe = findExe(data.sysCommand)
elif defined(linux) and not defined(android): discard execve(exe, data.sysArgs, data.sysEnv)
discard execvpe(data.sysCommand, data.sysArgs, data.sysEnv)
else: else:
# MacOSX doesn't have execvpe, so we need workaround. # MacOSX doesn't have execvpe, so we need workaround.
# On MacOSX we can arrive here only from fork, so this is safe: # On MacOSX we can arrive here only from fork, so this is safe:
@ -1265,7 +1267,8 @@ elif not defined(useNimRtl):
proc execCmdEx*(command: string, options: set[ProcessOption] = { proc execCmdEx*(command: string, options: set[ProcessOption] = {
poStdErrToStdOut, poUsePath}): tuple[ poStdErrToStdOut, poUsePath}): tuple[
output: TaintedString, output: TaintedString,
exitCode: int] {.tags: [ExecIOEffect, ReadIOEffect], gcsafe.} = exitCode: int] {.tags:
[ExecIOEffect, ReadIOEffect, RootEffect], gcsafe.} =
## a convenience proc that runs the `command`, grabs all its output and ## a convenience proc that runs the `command`, grabs all its output and
## exit code and returns both. ## exit code and returns both.
## ##