extern int handle_signal(void) { time_t now; char const * levels; char * temp; char const * tok; if (signal_data.cancel_quit) { signal_data.cancel_quit=0; if (!signal_data.exit_time) { log_info("there is no previous shutdown to be canceled"); } else { signal_data.exit_time=0; log_info("shutdown was canceled due to signal"); } } if (signal_data.do_quit) { signal_data.do_quit=0; now=time(NULL); if (!signal_data.exit_time) { signal_data.exit_time=now+prefs_get_shutdown_delay(); } else { signal_data.exit_time-=prefs_get_shutdown_decr(); } if (now >= signal_data.exit_time) { log_info("shutdown server due to signal"); return -1; } log_info("the server is going to shutdown in %lu minutes",(signal_data.exit_time-now)/60); } if (signal_data.reload_config) { signal_data.reload_config=0; log_info("reloading configuartion file due to signal"); if (prefs_reload(cmdline_get_prefs_file())<0) { log_error("error reload configuration file,exitting"); return -1; } if (d2gslist_reload(prefs_get_d2gs_list())<0) { log_error("error reloading game server list,exitting"); return -1; } eventlog_clear_level(); if ((levels = prefs_get_loglevels())) { if (!(temp = strdup(levels))) { eventlog(eventlog_level_fatal,"handle_signal","could not allocate memory for temp (exiting)"); return -1; } tok = strtok(temp,","); /* strtok modifies the string it is passed */ while (tok) { if (eventlog_add_level(tok)<0) eventlog(eventlog_level_error,"handle_signal","could not add log level \"%s\"",tok); tok = strtok(NULL,","); } free(temp); } if (!cmdline_get_logstderr()) eventlog_open(prefs_get_logfile()); } if (signal_data.reload_ladder) { signal_data.reload_ladder=0; log_info("reloading ladder data due to signal"); d2ladder_refresh(); } return 0; }
extern int handle_signal(void) { std::time_t now; char const * levels; char * temp; char const * tok; if (signal_data.cancel_quit) { signal_data.cancel_quit=0; if (!signal_data.exit_time) { eventlog(eventlog_level_info,__FUNCTION__,"there is no previous shutdown to be canceled"); } else { signal_data.exit_time=0; eventlog(eventlog_level_info,__FUNCTION__,"shutdown was canceled due to std::signal"); } } if (signal_data.do_quit) { signal_data.do_quit=0; now=std::time(NULL); if (!signal_data.exit_time) { signal_data.exit_time=now+d2cs_prefs_get_shutdown_delay(); } else { signal_data.exit_time-=d2cs_prefs_get_shutdown_decr(); } eventlog(eventlog_level_info,__FUNCTION__,"the server is going to shutdown in {} minutes",(signal_data.exit_time-now)/60); } if (signal_data.exit_time) { now=std::time(NULL); if (now >= (signed)signal_data.exit_time) { signal_data.exit_time=0; eventlog(eventlog_level_info,__FUNCTION__,"shutdown server due to std::signal"); return -1; } } if (signal_data.reload_config) { signal_data.reload_config=0; eventlog(eventlog_level_info,__FUNCTION__,"reloading configuartion file due to std::signal"); if (prefs_reload(cmdline_get_preffile())<0) { eventlog(eventlog_level_error,__FUNCTION__,"error reload configuration file,exitting"); return -1; } if (d2gslist_reload(prefs_get_d2gs_list())<0) { eventlog(eventlog_level_error,__FUNCTION__,"error reloading game server list,exitting"); return -1; } if (trans_reload(d2cs_prefs_get_transfile(),TRANS_D2CS)<0) { eventlog(eventlog_level_error,__FUNCTION__,"could not reload trans list"); } eventlog_clear_level(); if ((levels = d2cs_prefs_get_loglevels())) { temp = xstrdup(levels); tok = std::strtok(temp,","); /* std::strtok modifies the string it is passed */ while (tok) { if (eventlog_add_level(tok)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not add std::log level \"{}\"",tok); tok = std::strtok(NULL,","); } xfree(temp); } #ifdef DO_DAEMONIZE if (!cmdline_get_foreground()) #endif eventlog_open(d2cs_prefs_get_logfile()); } if (signal_data.reload_ladder) { signal_data.reload_ladder=0; eventlog(eventlog_level_info,__FUNCTION__,"reloading ladder data due to std::signal"); d2ladder_refresh(); } if (signal_data.restart_d2gs) { signal_data.restart_d2gs=0; eventlog(eventlog_level_info,__FUNCTION__,"restarting all game servers due to std::signal"); d2gs_restart_all_gs(); } return 0; }