Closed KalilDev closed 4 years ago
That's a good catch. I think it can be reproduced by deleting the named pipe.
I think it would be better to remove the if
check before reading and let the fgets == NULL
check do that for us (maybe only handle POLLERR
). If I'm reading man page for poll correctly, there can be both POLLIN
and POLLHUP
flags set at the same time so it's should be more correct to move the POLLHUP
check at the end of the default switch case.
Okayy, did it as you sugested. Sorry for the sloppy code, im not too familiar with C.
The test case is an simple program that outputs some values and then exits. When piping it to wob it got stuck on the for
loop as expected, and after the commit, wob exits gracefully.
I subscribed to POLLERR
events and handled them so the user is notified of the problem.
The case where both POLLIN
and POLLHUP
should be handled now, but i couldn't recreate this case, if you have any suggestions.
Decided to write my own fix for this b144c3cceb09b22483b0f66ea420d677d3dc425d
Unexpectedly closed fd can be simulated via sleep 1 | wob
.
Previously, wob would ignore POLLHUP and get stuck on the for(;;) loop in main, using 100% cpu. Do you want me to add tests or an minimal repro?