Avoid a race condition where log and err both try to close the sigsafe fds

Part of legacy/trac#31594 (moved).

I think we might want a separate ticket and changes file for this.