fdasd: Fix endless menu loop on EOF

Hitting CTRL-D anywhere will cause fdasd to go into an endless loop
displaying the main menu over and over again. Killing fdasd (e.g.
via CTR-C) is the only way out.
The issue is that read_line() is just ignoring the resulting EOF
condition on stdin. Subsequent invocations of read_line() will return
immediately and thus cause the loop. A simple fix is to reset stdin
after EOF. A caller of read_line() will see the same behavior as for
EOL with no input.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Viktor Mihajlovski
2022-03-24 10:17:50 +01:00
committed by Jan Höppner
parent b4b2202ff5
commit a0a71efde0

View File

@@ -408,8 +408,10 @@ static int read_line(void)
{
bzero(line_buffer, LINE_LENGTH);
line_ptr = line_buffer;
if (!fgets(line_buffer, LINE_LENGTH, stdin))
if (!fgets(line_buffer, LINE_LENGTH, stdin)) {
clearerr(stdin);
return 0;
}
while (*line_ptr && !isgraph(*line_ptr))
line_ptr++;