From 9df36894165624cd588e50ec36c52a4f4a194ab0 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 26 Apr 2024 01:33:04 +0000 Subject: [PATCH] Let signals interrupt fgets unless SA_RESTART set See investigation in #1130. fgets internally calls readv. readv is a @restartable function that understands SA_RESTART. If SA_RESTART is set, readv already handles restarting the system call and eventually the string is transparently returned to the fgets caller. When SA_RESTART is not set, -1 EINTR should bubble up to the fgets caller. However, until this commit, fgets itself would detect EINTR and keep retrying until it read an entire line. This commit fixes this behaviour so that fgets understands SA_RESTART. I hereby assign copyright for this commit to Justine Tunney. Signed-off-by: Cadence Ember --- libc/stdio/fgets_unlocked.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libc/stdio/fgets_unlocked.c b/libc/stdio/fgets_unlocked.c index b910fbc34..411df1ee3 100644 --- a/libc/stdio/fgets_unlocked.c +++ b/libc/stdio/fgets_unlocked.c @@ -55,11 +55,7 @@ char *fgets_unlocked(char *s, int size, FILE *f) { if (t) break; } else { if ((c = fgetc_unlocked(f)) == -1) { - if (ferror_unlocked(f) == EINTR) { - continue; - } else { - break; - } + break; } *p++ = c & 255; if (c == '\n') break;