Revert "Revert my hack on SIGALRM and apply f8bf37d."

This reverts commit 18d26eb6dc6ea94150f6e1d6f7cf0cba755d4526.
Revert f8bf37d and try a cleaner fix.