Sigterm signal handler ---------------------- Written by Samson of Alsherok Terms of Use ------------ 1. You may use this snippet in your code provided that any included comment headers in the code are left intact. You may add your own, but do not take mine out. 2. This snippet may not be posted for redistribution on any site without obtaining prior written consent from the Alsherok team. 3. ( optional ) Register with the forums at http://forums.alsherok.net Registration is not required to make use of the snippet, but since I no longer provide email support for any of the code I release, forum posts are your only avenue for direct support. This may seem overly stupid, but you can blame the continuing abuse I suffer from spammers for this. Don't post stuff to TMC or TMS asking about my code. I'm highly unlikely to ever notice it there on the rare ocassions I skim posts in either place. If forum registration doesn't appeal to you, then you can try to get ahold of me via IMC on the code channel. If you can't agree to these terms, don't use this code, and don't expect me to help if something breaks while installing it. Harsh? Hardly. I'm tired of people who come crawling to whine and complain when they haven't bothered to comply with the terms first. What this code does ------------------- This will give your mud the ability to intercept a SIGTERM from the server it is being hosted on. Most often generated by someone using the kill command, SIGTERM is also sent by the server during a reboot to all its running processes. Under normal conditions, this would mean your mud would just drop and your players get annoyed. This code at least affords some level of protection for them since it stops a running auction and then saves each of them to disk. It then also shuts down IMC, Intermud-3, and the DNS Slave code if you have those installed before then letting the mud go down in a normal fashion. Installation Instructions ------------------------- 1. Open comm.c, and locate the following code: /* * LAG alarm! -Thoric */ void caught_alarm() { char buf[MAX_STRING_LENGTH]; sprintf( buf, "ALARM CLOCK! In section %s", alarm_section ); bug( buf ); strcpy( buf, "Alas, the hideous malevalent entity known only as 'Lag' rises once more!\r\n" ); echo_to_all( AT_IMMORT, buf, ECHOTAR_IMM ); if ( newdesc ) { FD_CLR( newdesc, &in_set ); FD_CLR( newdesc, &out_set ); FD_CLR( newdesc, &exc_set ); log_string( "clearing newdesc" ); } } Place the following function directly above that: static void SigTerm( int signum ) { CHAR_DATA *vch; echo_to_all( AT_RED, "&RATTENTION!! Message from game server: &YEmergency shutdown called.\a", ECHOTAR_ALL ); echo_to_all( AT_YELLOW, "Executing emergency shutdown proceedure.", ECHOTAR_ALL ); log_string( "Message from server: Executing emergency shutdown proceedure." ); shutdown_mud( "Emergency Shutdown" ); if( auction->item ) do_auction( supermob, "stop" ); log_string( "Saving players...." ); for( vch = first_char; vch; vch = vch->next ) { if( !IS_NPC( vch ) ) { char lbuf[MAX_STRING_LENGTH]; save_char_obj( vch ); snprintf( lbuf, MAX_STRING_LENGTH, "%s saved.", vch->name ); log_string( lbuf ); if( vch->desc ) write_to_descriptor( vch->desc, "You have been saved to disk.\r\n", 0 ); } } /* Save morphs so can sort later. --Shaddai */ if( sysdata.morph_opt ) save_morphs( ); fflush( stderr ); /* make sure strerr is flushed */ close( control ); #ifdef IMC imc_shutdown(); /* shut down IMC */ #endif #ifdef I3 I3_shutdown( 0 ); #endif log_string( "Emergency shutdown complete." ); /* Using exit here instead of mud_down because the thing sometimes failed to kill when asked!! */ exit( 0 ); } Then locate function game_loop and find the following code: signal( SIGPIPE, SIG_IGN ); signal( SIGALRM, caught_alarm ); /* signal( SIGSEGV, SegVio ); */ Add the following line directly below that: signal( SIGTERM, SigTerm ); /* Catch kill signals */ 2. Compile and reboot. That's it, your done :) If there are any problems with this installation, feel free to post your question to the forums at http://forums.alsherok.net This code has been installed and tested on Smaug 1.6 FUSS, which is a bugfixed and cleaned up version of the base Smaug 1.4a code. The Smaug FUSS Project is maintained on servers which run the Redhat and Fedora family of Linux. Limited testing has also been done on the Cygwin package under WindowsXP SP1 and SP2. Users of BSD, MSVC, MSVC++, or Macintosh platforms are on their own as The Smaug FUSS Project does not have access to these development environments for testing. The Smaug FUSS Project can be found at: http://www.smaugfuss.org No guarantees are made that this code will be compatible with your codebase and any modifications you may have made to it. No warranty of any kind is expressed or implied by the use of this code, and we are not responsible for any damages which may result from the application of this snippet to your codebase. Adventure beckons in the lands of mystique.... Samson, Implementor of Alsherok http://www.alsherok.net telnet://alsherok.net:5500 IMC2 contact: Samson@Alsherok