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 <cadence@disroot.org>
This commit is contained in:
Cadence Ember 2024-04-26 01:33:04 +00:00
parent b9d6e6e348
commit 9df3689416

View file

@ -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;