Retry read() syscall on EINTR (#21188)

The read() syscall can get interrupted by a signal, in which case
you can just retry the read call instead of failing with an error.
This is most noticeable if you run the compiler in a debugger.
This commit is contained in:
drpriver 2025-04-09 16:18:49 -07:00 committed by GitHub
parent 74cdfed9d6
commit 93b0317cc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,6 +39,7 @@ version (Posix)
import core.sys.posix.stdio;
import core.sys.posix.stdlib;
import core.sys.posix.unistd;
import core.stdc.errno;
extern (C)
{
@ -1229,13 +1230,19 @@ public int runPreprocessor(Loc loc, const(char)[] cpp, const(char)[] filename, c
OutBuffer buffer;
ubyte[1024] tmp = void;
ptrdiff_t nread;
while ((nread = read(pipefd[0], tmp.ptr, tmp.length)) > 0)
buffer.write(tmp[0 .. nread]);
if (nread == -1)
for(;;)
{
perror("read");
return STATUS_FAILED;
while ((nread = read(pipefd[0], tmp.ptr, tmp.length)) > 0)
buffer.write(tmp[0 .. nread]);
if (nread == -1)
{
if(errno == EINTR) continue;
perror("read");
return STATUS_FAILED;
}
break;
}
int status;