Make signal handling async-signal-safe