Merge pull request #2555 from def-/fix-2552

Make peekExitCode on Posix use WIFEXITED to determine exit
This commit is contained in:
Andreas Rumpf 2015-04-15 17:41:01 +02:00
commit 86b37f7fc7

View file

@ -174,7 +174,7 @@ proc terminate*(p: Process) {.rtl, extern: "nosp$1", tags: [].}
proc kill*(p: Process) {.rtl, extern: "nosp$1", tags: [].} proc kill*(p: Process) {.rtl, extern: "nosp$1", tags: [].}
## Kill the process `p`. On Posix OSes the procedure sends ``SIGKILL`` to ## Kill the process `p`. On Posix OSes the procedure sends ``SIGKILL`` to
## the process. On Windows ``kill()`` is simply an alias for ``terminate()``. ## the process. On Windows ``kill()`` is simply an alias for ``terminate()``.
proc running*(p: Process): bool {.rtl, extern: "nosp$1", tags: [].} proc running*(p: Process): bool {.rtl, extern: "nosp$1", tags: [].}
## Returns true iff the process `p` is still running. Returns immediately. ## Returns true iff the process `p` is still running. Returns immediately.
@ -666,7 +666,7 @@ elif not defined(useNimRtl):
data.workingDir = workingDir data.workingDir = workingDir
when declared(posix_spawn) and not defined(useFork) and when declared(posix_spawn) and not defined(useFork) and
not defined(useClone) and not defined(linux): not defined(useClone) and not defined(linux):
pid = startProcessAuxSpawn(data) pid = startProcessAuxSpawn(data)
else: else:
@ -823,7 +823,7 @@ elif not defined(useNimRtl):
discard execvp(data.sysCommand, data.sysArgs) discard execvp(data.sysCommand, data.sysArgs)
else: else:
when defined(uClibc): when defined(uClibc):
# 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) discard execve(data.sysCommand, data.sysArgs, data.sysEnv)
else: else:
discard execvpe(data.sysCommand, data.sysArgs, data.sysEnv) discard execvpe(data.sysCommand, data.sysArgs, data.sysEnv)
@ -864,9 +864,9 @@ elif not defined(useNimRtl):
raiseOsError(osLastError()) raiseOsError(osLastError())
proc kill(p: Process) = proc kill(p: Process) =
if kill(p.id, SIGKILL) != 0'i32: if kill(p.id, SIGKILL) != 0'i32:
raiseOsError(osLastError()) raiseOsError(osLastError())
proc waitForExit(p: Process, timeout: int = -1): int = proc waitForExit(p: Process, timeout: int = -1): int =
#if waitPid(p.id, p.exitCode, 0) == int(p.id): #if waitPid(p.id, p.exitCode, 0) == int(p.id):
# ``waitPid`` fails if the process is not running anymore. But then # ``waitPid`` fails if the process is not running anymore. But then
@ -883,7 +883,7 @@ elif not defined(useNimRtl):
var ret = waitpid(p.id, p.exitCode, WNOHANG) var ret = waitpid(p.id, p.exitCode, WNOHANG)
var b = ret == int(p.id) var b = ret == int(p.id)
if b: result = -1 if b: result = -1
if p.exitCode == -3: result = -1 if not WIFEXITED(p.exitCode): result = -1
else: result = p.exitCode.int shr 8 else: result = p.exitCode.int shr 8
proc createStream(stream: var Stream, handle: var FileHandle, proc createStream(stream: var Stream, handle: var FileHandle,
@ -907,7 +907,7 @@ elif not defined(useNimRtl):
createStream(p.errStream, p.errHandle, fmRead) createStream(p.errStream, p.errHandle, fmRead)
return p.errStream return p.errStream
proc csystem(cmd: cstring): cint {.nodecl, importc: "system", proc csystem(cmd: cstring): cint {.nodecl, importc: "system",
header: "<stdlib.h>".} header: "<stdlib.h>".}
proc execCmd(command: string): int = proc execCmd(command: string): int =