Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions std/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -1247,8 +1247,19 @@ private Pid spawnProcessPosix(scope const(char[])[] args,
else
{
closePipeWriteEnds();

T retryInterrupted(T)(scope T delegate() syscall)
{
import core.stdc.errno : errno, EINTR;
T result;
do
result = syscall();
while (result == -1 && .errno == EINTR);
return result;
}

auto status = InternalError.noerror;
auto readExecResult = core.sys.posix.unistd.read(forkPipe[0], &status, status.sizeof);
auto readExecResult = retryInterrupted(() => core.sys.posix.unistd.read(forkPipe[0], &status, status.sizeof));
// Save error number just in case if subsequent "waitpid" fails and overrides errno
immutable lastError = .errno;

Expand All @@ -1257,7 +1268,7 @@ private Pid spawnProcessPosix(scope const(char[])[] args,
// Forked child exits right after creating second fork. So it should be safe to wait here.
import core.sys.posix.sys.wait : waitpid;
int waitResult;
waitpid(id, &waitResult, 0);
retryInterrupted(() => waitpid(id, &waitResult, 0));
}

if (readExecResult == -1)
Expand All @@ -1267,7 +1278,7 @@ private Pid spawnProcessPosix(scope const(char[])[] args,
if (status != InternalError.noerror)
{
int error;
readExecResult = read(forkPipe[0], &error, error.sizeof);
readExecResult = retryInterrupted(() => read(forkPipe[0], &error, error.sizeof));
string errorMsg;
final switch (status)
{
Expand Down
Loading