FS#62506 - glibc 2.29.1 fails to block on fgets() reading stdin

Attached to Project: Arch Linux
Opened by Jim B (d3x0r) - Tuesday, 30 April 2019, 01:40 GMT
Last edited by Eli Schwartz (eschwartz) - Tuesday, 30 April 2019, 03:26 GMT
Task Type Bug Report
Category Upstream Bugs
Status Closed
Assigned To No-one
Architecture All
Severity Critical
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
I have a simple program that runs as 'journalctl -f | myProgram'
myProgram.c
int main(void) {
char buffer[256];
while( fges( buffer, 256, stdin ) ) {
}
printf( "stdin pipe closed?" );
}

and when running a program with stdin redirected, fgets returns NULL when there is no more data. (Jounralctl manages to put data in stdout before the program loads, but not sure what the threshold is).

I manually updated back to 2.28-5 ( and lib32-2.28-5 ) and the problem went away.

Although; it still doesn't tail a file... shouldn't fgets wait if there's someone writing to a file? Doesn't matter, tail -f can fix it...

journalctl -f > somefile & tail -f somefile | program

works with 2.28-5 and fails (ends at end of journal data) on 2.29-1


Additional info:
* package version(s)
2.29-1
2.28-5
* config and/or log files etc.
* link to upstream bug report, if any
(should be one; but am posting here as an advisory)
Steps to reproduce:
compile above program, and pipe something that shouldn't end... like tail -f /var/log/messages | program.

This task depends upon

Closed by  Eli Schwartz (eschwartz)
Tuesday, 30 April 2019, 03:26 GMT
Reason for closing:  Works for me
Comment by Eli Schwartz (eschwartz) - Tuesday, 30 April 2019, 01:51 GMT
> pipe something that shouldn't end

Unless there are isatty checks here, your interactive terminal is something that does not end?

Also, this works for me, even after I fix the missing #include <stdio.h> and the typoed "fges" => "fgets". I find it unlikely the glibc developers would break this.
Comment by Jim B (d3x0r) - Tuesday, 30 April 2019, 01:57 GMT
stdin works yes
but not piping a program as the input
which shouldn't be any different.
also 5.0.[0|7] kernel...
Comment by Jim B (d3x0r) - Tuesday, 30 April 2019, 02:15 GMT
I honestly don't know what happened.
1) it was not working
I had 5.0.0 kernel and knew there was an update so I rebooted
and it worked
I reverted my code changes that were debug/workaround.
and then I ran the script it belongs in and it failed
I reapplied the changes
and then it failed.

and then I reverted the glibc library, and it worked.

And then I bug reported it

and I put the glibc library forward and it's working

and... so now it's working; but the reboot 'fixed' it too.
I don't get it.

Loading...