If a child process sets stdin to non-blocking and does not set it back to
blocking before exiting, other processes may fail to read from stdin.
Reproducer steps :
$ cat set_nonblock.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
char buff[256];
int flags = fcntl (0, F_GETFL);
if (fcntl(0, F_SETFL, flags | O_NONBLOCK)) {
perror("fcntl failed");
}
if (read(0, buff, 256) == -1) {
perror("read failed");
}
}
$ cc -o set_nonblock set_nonblock.c
$ cat test.sh
#!/bin/bash
./set_nonblock
cat
$ ./test.sh
read failed: Resource temporarily unavailable
cat: -: Resource temporarily unavailable
Attached patch sets standard file descriptors to blocking before child process
starts.
--
--
Siteshwar Vashisht