Improve handling of signals in loop, and make poll_fd actually work