Esempio n. 1
0
int
master_exit(int retval)
{
	cleanup_memory();

#ifdef WIN32
	if ( NT_ServiceFlag == TRUE ) {
		terminate(retval);
	}
#endif

#if defined(WANT_CONTRIB) && defined(WITH_MANAGEMENT)
#if defined(HAVE_DLOPEN) || defined(WIN32)
	MasterPluginManager::Shutdown();
#endif
#endif

		// If we're positive that we are going to shut down,
		// we should clean out the shared port directory if
		// we created it.
	std::string dirname;
	if ( SharedPortEndpoint::CreatedSharedPortDirectory() &&
		 SharedPortEndpoint::GetDaemonSocketDir(dirname) ) {

		TemporaryPrivSentry tps(PRIV_CONDOR);
		Directory d(dirname.c_str());
		d.Remove_Entire_Directory();
		if (-1 == rmdir(dirname.c_str())) {
			dprintf(D_ALWAYS, "ERROR: failed to remove shared port temporary directory: %s (errno=%d).\n", strerror(errno), errno);
		}
	}

	DC_Exit(retval, shutdown_program );
	return 1;	// just to satisfy vc++
}
Esempio n. 2
0
/* use for successful exit */
void cleanup(void)
{
    /* No longer write settings here, because we only */
    /* want to save settings from certain types of games. */
    //write_user_config_file();
    cleanup_memory();
    //  exit(0);
}
Esempio n. 3
0
/*
 * LAG alarm!							-Thoric
 */
static void caught_alarm( int signum )
{
   echo_to_all( "&[immortal]Alas, the hideous malevalent entity known only as 'Lag' rises once more!", ECHOTAR_ALL );
   bug( "&RALARM CLOCK! In section %s", alarm_section );

   if( newdesc )
   {
      FD_CLR( newdesc, &in_set );
      FD_CLR( newdesc, &out_set );
      FD_CLR( newdesc, &exc_set );
      log_string( "clearing newdesc" );
   }

   if( fBootDb )
   {
      log_string( "Terminating program. Infinite loop detected during bootup." );
      shutdown_mud( "Infinite loop detected during bootup." );
      abort(  );
   }

   log_string( "&RPossible infinite loop detected during game operation. Restarting game_loop()." );
   signal( SIGALRM, caught_alarm ); // Have to reset the signal handler or the next hit will deadlock
   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 );
}
Esempio n. 4
0
static void SegVio( int signum )
{
   bug( "%s", "}RSEGMENTATION FAULT: Invalid Memory Access&D" );
   log_string( lastplayercmd );

   if( !pclist.empty(  ) )
   {
      list < char_data * >::iterator ich;
      for( ich = pclist.begin(  ); ich != pclist.end(  ); ++ich )
      {
         char_data *ch = *ich;

         if( ch && ch->name && ch->in_room )
            log_printf( "%-20s in room: %d", ch->name, ch->in_room->vnum );
      }
   }

   if( sigsegv == true )
      abort(  );
   else
      sigsegv = true;

   ++crash_count;

   signal( SIGSEGV, SegVio ); // Have to reset the signal handler or the next one raised will crash
   game_loop(  );

   // Clean up the loose ends... hey wait... why is this here? Because: When game_loop returns now, it will come here instead of main()
   close_mud(  );

   // That's all, folks.
   log_string( "Normal termination of game." );
   log_string( "Cleaning up Memory.&d" );
   cleanup_memory(  );
   exit( 0 );
}
int
main(void)
{
  Simulation_Run_Ptr simulation_run;
  Simulation_Run_Data_Ptr data;

  /*
   * Declare and initialize our random number generator seeds defined in
   * simparameters.h
   */

  unsigned RANDOM_SEEDS[] = {RANDOM_SEED_LIST, 0};
  unsigned random_seed;
  int j=0;

  /* 
   * Loop for each random number generator seed, doing a separate
   * simulation_run run for each.
   */

  while ((random_seed = RANDOM_SEEDS[j++]) != 0) {

    simulation_run = simulation_run_new(); /* Create a new simulation run. */

    /*
     * Create a Simulation_Run_Data object. This will hold all of our user
     * defined data (declared in main.h). Set the simulation_run data pointer
     * to our new object.
     */

    data = (Simulation_Run_Data_Ptr) xmalloc(sizeof(Simulation_Run_Data));
    simulation_run_set_data(simulation_run, (void*) data);

    /* 
     * Initialize the simulation_run data variables, declared in main.h.
     */
    
    data->blip_counter = 0;
    data->arrival_count = 0;
    data->number_of_packets_processed = 0;
    data->accumulated_delay = 0.0;
    data->random_seed = random_seed;
 
    /* 
     * Create the packet buffer and transmission link, declared in main.h.
     */

    data->buffer = fifoqueue_new();
    data->link   = server_new();

    /* 
     * Set the random number generator seed for this run.
     */

    random_generator_initialize(random_seed);

    /* 
     * Schedule the initial packet arrival for the current clock time (= 0).
     */

    schedule_packet_arrival_event(simulation_run, 
				  simulation_run_get_time(simulation_run));

    /* 
     * Execute events until we are finished. 
     */

    while(data->number_of_packets_processed < RUNLENGTH) {
      simulation_run_execute_event(simulation_run);
    }

    /*
     * Output results and clean up after ourselves.
     */

    output_results(simulation_run);
    cleanup_memory(simulation_run);
  }

  getchar();   /* Pause before finishing. */
  return 0;
}
Esempio n. 6
0
/* use for fail exit */
void cleanup_on_error(void)
{
    cleanup_memory();
    exit(1);
}
Esempio n. 7
0
int main( int argc, char **argv )
#endif
{
   struct timeval now_time;
   int temp = -1, temp2 = -1;
   bool fCopyOver = false;

#if !defined(WIN32)
   moron_check(  );  // Debatable weather or not this is true in WIN32 anyway :)
#endif

   DONT_UPPER = false;
   num_descriptors = 0;
   num_logins = 0;
   dlist.clear(  );
   mudstrlcpy( lastplayercmd, "No commands issued yet", MIL * 2 );

   // Init time.
   tzset(  );
   gettimeofday( &now_time, NULL );
   current_time = now_time.tv_sec;
   mudstrlcpy( str_boot_time, c_time( current_time, -1 ), MIL );  /* Records when the mud was last rebooted */

   new_pfile_time_t = current_time + 86400;
   mud_start_time = current_time;

   // Get the port number.
   mud_port = 9500;
   if( argc > 1 )
   {
      if( !is_number( argv[1] ) )
      {
         fprintf( stderr, "Usage: %s [port #]\n", argv[0] );
         exit( 1 );
      }
      else if( ( mud_port = atoi( argv[1] ) ) <= 1024 )
      {
         fprintf( stderr, "%s", "Port number must be above 1024.\n" );
         exit( 1 );
      }

      if( argv[2] && argv[2][0] )
      {
         fCopyOver = true;
         control = atoi( argv[3] );
#ifdef IMC
         temp2 = atoi( argv[4] );
#endif
      }
      else
         fCopyOver = false;
   }

#if defined(WIN32)
   {
      /*
       * Initialise Windows sockets library 
       */
      unsigned short wVersionRequested = MAKEWORD( 1, 1 );
      WSADATA wsadata;
      int err;

      /*
       * Need to include library: wsock32.lib for Windows Sockets 
       */
      err = WSAStartup( wVersionRequested, &wsadata );
      if( err )
      {
         fprintf( stderr, "Error %i on WSAStartup\n", err );
         exit( 1 );
      }

      /*
       * standard termination signals 
       */
      signal( SIGINT, bailout );
      signal( SIGTERM, bailout );
   }
#endif /* WIN32 */

   // Initialize all startup functions of the mud. 
   init_mud( fCopyOver, mud_port, temp, temp2 );

#if !defined(WIN32)
   /*
    * Set various signal traps, waiting until after completing all bootup operations
    * before doing so because crashes during bootup should not be intercepted. Samson 3-11-04
    */
   signal( SIGTERM, SigTerm );   /* Catch kill signals */
   signal( SIGPIPE, SIG_IGN );
   signal( SIGALRM, caught_alarm );
   signal( SIGUSR1, SigUser1 );  /* Catch user defined signals */
   signal( SIGUSR2, SigUser2 );
#endif
#ifdef MULTIPORT
   signal( SIGCHLD, SigChld );
#endif

   /*
    * If this setting is active, intercept SIGSEGV and keep the mud running.
    * Doing so sets a flag variable which if true will cause SegVio to abort()
    * If game_loop is restarted and makes it through once without crashing again,
    * then the flag is unset and SIGSEGV will continue to be intercepted. Samson 3-11-04
    */
   if( sysdata->crashhandler == true )
      set_chandler(  );

   log_string( "No people online yet. Suspending autonomous update handlers." );

   // Sick isn't it? The whole game being run inside of one little statement..... :P 
   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 );
}