If infinite loop protection is what you're after, as Kylotan suggested Smaug has a set_alarm function. Using that, the following little tidbits will do the trick:
Top of game_loop, with other signal stuff:
signal( SIGALRM, caught_alarm );
In game_loop, after the new_descriptor call:
set_alarm( 30 );
And again at the bottom of game_loop, to reset it ( not sure if this is needed ):
set_alarm( 0 );
The set_alarm function itself, which is just a wrapper:
[code]
void set_alarm( long seconds )
{
alarm( seconds );
}
[/quote]
And caught_alarm:
[code]
/*
* LAG alarm! -Thoric
*/
static void caught_alarm( int signum )
{
bug( 'ALARM CLOCK! In section %s', alarm_section );
echo_to_all( AT_IMMORT, 'Alas, the hideous malevalent entity known only as 'Lag' rises once more!', ECHOTAR_IMM );
if( newdesc )
{
FD_CLR( newdesc, &in_set );
FD_CLR( newdesc, &out_set );
FD_CLR( newdesc, &exc_set );
log_string( 'clearing newdesc' );
}
game_loop();
/* Clean up the loose ends. */
close_mud( );
/*
* That's all, folks.
*/
log_string( 'Normal termination of game.' );
log_string( 'Cleaning up Memory.&d' );
cleanup_memory();
exit( 0 );
}
[/quote]
I've tested this out with a deliberate infinite loop command, it caught it and was able to restart game_loop. Smaug does not handle this use of the alarm stock, I added that part, but they were already using it in new_descriptor to break up connection problems. So I figured why not?
|