Factor out register/unregister of signal handlers.