I haven't looked at the relevant snippets, so I'll just post what mine
does. I'm sure it's similar.
I set the signal to SIG_DFL as soon as it's caught, fork a new process,
then raise the signal again in the parent. The new process goes on to
save everything and do a soft boot, the parent just dies, leaving a core
file.
If it crashes while saving, the signal has already set to default, so
it'll go ahead and crash (unfortunately this often overwrites the
parent's core file.. anybody know how to alter the filename a core is
saved to?).
Anyway, the crash_copyover function is basically just a copy of
do_copyover without the send_to_char's, etc.
I also save some debugging information to another file in
crash_copyover, such as the last command processed, who gave it, etc.
The number of times it's crashed is sent to the command line (would be
just as easy to save it to the copyover file though), and once it gets
big, the mud just exits and shuts up. This avoids problems where the
mud crashes before it gets running, but after the signal handler has
been initialized, and there's a sort of execution loop, and I always
forget about the killall program and end up chasing pid's for a few
minutes.
Haven't had any real problems with it, seems to be a good scheme.
The only thing I've seen people do that might add to it is saving pfiles
to a different name before the copyober so either the old one or the new
one is hopefully right.
void sig_handler(int sig)
{
signal(sig, SIG_DFL);
switch(fork())
{
case 0:
crash_copyover();
case -1:
perror("signal_handler: fork");
default:
raise(sig);
}
}
That turned out longer than I thought..
--Palrich.