Skip to content

Commit e5257da

Browse files
thibaultchaagentzh
authored andcommitted
bugfix: io module: read("*a") fails to automatically resume the read() system call upon EINTR. thanks Michal Cichra for the report in openresty/resty-cli#35.
Signed-off-by: Yichun Zhang (agentzh) <[email protected]>
1 parent 8b51016 commit e5257da

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/lib_io.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,14 @@ static void io_file_readall(lua_State *L, FILE *fp)
164164
MSize m, n;
165165
for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) {
166166
char *buf = lj_buf_tmp(L, m);
167-
n += (MSize)fread(buf+n, 1, m-n, fp);
168-
if (n != m) {
169-
setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
167+
for (;;) {
168+
n += (MSize)fread(buf+n, 1, m-n, fp);
169+
if (n == m) break;
170+
if (ferror(fp)) {
171+
if (errno == EINTR) { clearerr(fp); continue; }
172+
} else {
173+
setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
174+
}
170175
lj_gc_check(L);
171176
return;
172177
}

0 commit comments

Comments
 (0)