Check the error message from select(). If error, bail out.
Also close all file descriptors in the end. If select happends to fail
and we go to waitpid() and the process is writing content, it might
eventually block because nobody is reading the file descriptor. By
closing the file we ensure the process will not hang and there will be
no deadlock.
Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
maxfd = max(ofd, efd);
error = select(maxfd, &rfds, NULL, NULL, NULL);
+ if (error < 0) {
+ printf("Error with select: %m\n");
+ break;
+ }
+
if (FD_ISSET(ofd, &rfds)) {
typestr = stdoutstr;
bytes = read(ofd, rbuf, BUF_SIZE);
}
}
+ close(ofd);
+ close(efd);
+
harvest_zombies(child);
exit(1);