Fix osproc.peekExitCode() to handle exitcode properly. (#5555)
This commit is contained in:
parent
7ba565258d
commit
d701de5733
1 changed files with 12 additions and 14 deletions
|
|
@ -986,11 +986,11 @@ elif not defined(useNimRtl):
|
||||||
raiseOsError(osLastError())
|
raiseOsError(osLastError())
|
||||||
|
|
||||||
when defined(macosx) or defined(freebsd) or defined(netbsd) or
|
when defined(macosx) or defined(freebsd) or defined(netbsd) or
|
||||||
defined(openbsd):
|
defined(openbsd) or defined(dragonfly):
|
||||||
import kqueue, times
|
import kqueue, times
|
||||||
|
|
||||||
proc waitForExit(p: Process, timeout: int = -1): int =
|
proc waitForExit(p: Process, timeout: int = -1): int =
|
||||||
if p.exitStatus != -3: return ((p.exitStatus and 0xFF00) shr 8)
|
if p.exitStatus != -3: return((p.exitStatus and 0xFF00) shr 8)
|
||||||
if timeout == -1:
|
if timeout == -1:
|
||||||
var status : cint = 1
|
var status : cint = 1
|
||||||
if waitpid(p.id, status, 0) < 0:
|
if waitpid(p.id, status, 0) < 0:
|
||||||
|
|
@ -1041,7 +1041,7 @@ elif not defined(useNimRtl):
|
||||||
finally:
|
finally:
|
||||||
discard posix.close(kqFD)
|
discard posix.close(kqFD)
|
||||||
|
|
||||||
result = int(p.exitStatus) shr 8
|
result = ((p.exitStatus and 0xFF00) shr 8)
|
||||||
else:
|
else:
|
||||||
import times
|
import times
|
||||||
|
|
||||||
|
|
@ -1077,7 +1077,7 @@ elif not defined(useNimRtl):
|
||||||
# ``waitPid`` fails if the process is not running anymore. But then
|
# ``waitPid`` fails if the process is not running anymore. But then
|
||||||
# ``running`` probably set ``p.exitStatus`` for us. Since ``p.exitStatus`` is
|
# ``running`` probably set ``p.exitStatus`` for us. Since ``p.exitStatus`` is
|
||||||
# initialized with -3, wrong success exit codes are prevented.
|
# initialized with -3, wrong success exit codes are prevented.
|
||||||
if p.exitStatus != -3: return int(p.exitStatus) shr 8
|
if p.exitStatus != -3: return((p.exitStatus and 0xFF00) shr 8)
|
||||||
if timeout == -1:
|
if timeout == -1:
|
||||||
var status : cint = 1
|
var status : cint = 1
|
||||||
if waitpid(p.id, status, 0) < 0:
|
if waitpid(p.id, status, 0) < 0:
|
||||||
|
|
@ -1151,19 +1151,17 @@ elif not defined(useNimRtl):
|
||||||
if sigprocmask(SIG_UNBLOCK, nmask, omask) == -1:
|
if sigprocmask(SIG_UNBLOCK, nmask, omask) == -1:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
||||||
result = int(p.exitStatus) shr 8
|
result = ((p.exitStatus and 0xFF00) shr 8)
|
||||||
|
|
||||||
proc peekExitCode(p: Process): int =
|
proc peekExitCode(p: Process): int =
|
||||||
var status : cint = 1
|
var status = cint(0)
|
||||||
if p.exitStatus != -3: return ((p.exitStatus and 0xFF00) shr 8)
|
result = -1
|
||||||
|
if p.exitStatus != -3: return((p.exitStatus and 0xFF00) shr 8)
|
||||||
var ret = waitpid(p.id, status, WNOHANG)
|
var ret = waitpid(p.id, status, WNOHANG)
|
||||||
var b = ret == int(p.id)
|
if ret > 0:
|
||||||
if b: result = -1
|
|
||||||
if WIFEXITED(status):
|
if WIFEXITED(status):
|
||||||
p.exitStatus = status
|
p.exitStatus = status
|
||||||
result = (status and 0xFF00) shr 8
|
result = (status and 0xFF00) shr 8
|
||||||
else:
|
|
||||||
result = -1
|
|
||||||
|
|
||||||
proc createStream(stream: var Stream, handle: var FileHandle,
|
proc createStream(stream: var Stream, handle: var FileHandle,
|
||||||
fileMode: FileMode) =
|
fileMode: FileMode) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue