4436: Remove race in write_stats children

We unregister the signal handler in write_stats children, but only
after the fork, so there could be a race if an exception arrives before
the handler is deregistered.

We now unregister right before the fork (and re-register the parent right
after).