I'm implementing a telnet server and a kernel message ring buffer (#7446) with a shell command like dmesg to read and clear it. I want to add dmesg -w (works like tail -f) which mustn't return until the user interrupts it.
I'm not sure of the best way to do this without dedicating a thread to block on reading stdin.
I don't think we can fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK) but even if we could we'd then be polling and that's not ideal either.
I think it would be appropriate to use select() to have a single thread block simultaneously on both stdin and the file that produces dmesg output (via vfs_bind()), but I don't think select() and friends are implemented either.
The main thread will normally be blocked (via getc() or something else) waiting for new kernel messages to be printed. The goal is to allow the user to interrupt this with ^C to get a prompt back, and to do it in a resource-friendly way.