osproc: fix double close on POSIX (#5724)

Calling close() in some cases issued two close() syscalls to one FD, which is incorrect in multithreaded programs.
This commit is contained in:
Michał Zieliński 2018-04-16 20:02:26 +02:00 • committed by Andreas Rumpf
commit b2060acbc4
2 changed files with 38 additions and 6 deletions

View file

@ -1001,13 +1001,21 @@ elif not defined(useNimRtl):
{.pop}
proc close(p: Process) =
if p.inStream != nil: close(p.inStream)
if p.outStream != nil: close(p.outStream)
if p.errStream != nil: close(p.errStream)
if poParentStreams notin p.options:
discard close(p.inHandle)
discard close(p.outHandle)
discard close(p.errHandle)
if p.inStream != nil:
close(p.inStream)
else:
discard close(p.inHandle)
if p.outStream != nil:
close(p.outStream)
else:
discard close(p.outHandle)
if p.errStream != nil:
close(p.errStream)
else:
discard close(p.errHandle)
proc suspend(p: Process) =
if kill(p.id, SIGSTOP) != 0'i32: raiseOsError(osLastError())