Fix FreeBSD warnings
Use O_NONBLOCK to avoid blocking on I/O calls
Add debug output for select
Close finished downstream fds on read EOF

This avoids deadlocks caused by some downstream processes
waiting for more output, when no such output will appear.