static void io_loop(void) { time_t delay; while (ServerRunning) { /* Run pending events, then get the number of seconds to the next * event */ delay = eventNextTime(); if(delay <= CurrentTime) eventRun(); comm_select(250); /* * Check to see whether we have to rehash the configuration .. */ if(dorehash) { rehash(1); dorehash = 0; } if(dorehashbans) { rehash_bans(1); dorehashbans = 0; } if(doremotd) { sendto_realops_flags(UMODE_ALL, L_ALL, "Got signal SIGUSR1, reloading ircd motd file"); free_cachefile(user_motd); user_motd = cache_file(MPATH, "ircd.motd", 0); doremotd = 0; } } }
void set_time(void) { struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 }; if (gettimeofday(&newtime, NULL) == -1) { ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted", strerror(errno)); sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "Clock Failure (%s), TS can be corrupted", strerror(errno)); server_die("Clock Failure", 1); } if (newtime.tv_sec < CurrentTime) { ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)", (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, "System clock is running backwards - (%lu < %lu)", (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime); set_back_events(CurrentTime - newtime.tv_sec); } SystemTime.tv_sec = newtime.tv_sec; SystemTime.tv_usec = newtime.tv_usec; } static void io_loop(void) { while (1) { if (listing_client_list.head) { dlink_node *node = NULL, *node_next = NULL; DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head) safe_list_channels(node->data, 0); } /* Run pending events */ event_run(); comm_select(); exit_aborted_clients(); free_exited_clients(); /* Check to see whether we have to rehash the configuration .. */ if (dorehash) { conf_rehash(1); dorehash = 0; } if (doremotd) { motd_recache(); sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, "Got signal SIGUSR1, reloading motd file(s)"); doremotd = 0; } } } /* initalialize_global_set_options() * * inputs - none * output - none * side effects - This sets all global set options needed */ static void initialize_global_set_options(void) { GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients; GlobalSetOptions.autoconn = 1; GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME; GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT; GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount; GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count; GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time; split_servers = ConfigChannel.default_split_server_count; split_users = ConfigChannel.default_split_user_count; if (split_users && split_servers && (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split)) { splitmode = 1; splitchecking = 1; } GlobalSetOptions.ident_timeout = IDENT_TIMEOUT; }
int main(int argc, char *argv[]) { #ifndef _WIN32 if (geteuid() == 0) { fprintf(stderr, "Running IRC services is root is not recommended."); return 1; } setup_corefile(); #endif memset(&ServicesInfo, 0, sizeof(ServicesInfo)); memset(&ServicesState, 0, sizeof(ServicesState)); ServicesState.configfile = CPATH; ServicesState.logfile = LPATH; ServicesState.pidfile = PPATH; ServicesState.fully_connected = 0; parseargs(&argc, &argv, myopts); if(ServicesState.printversion) { printf("oftc-ircservices: version: %s\n", VERSION); exit(EXIT_SUCCESS); } if(chdir(DPATH)) { perror("chdir"); exit(EXIT_FAILURE); } #ifndef _WIN32 if(!ServicesState.foreground) make_daemon(); else print_startup(getpid()); #endif setup_signals(); memset(&me, 0, sizeof(me)); libio_init(!ServicesState.foreground); init_events(); iorecv_cb = register_callback("iorecv", iorecv_default); connected_cb = register_callback("server connected", server_connected); iosend_cb = register_callback("iosend", iosend_default); OpenSSL_add_all_digests(); init_interface(); check_pidfile(ServicesState.pidfile); init_log(ServicesState.logfile); #ifdef HAVE_RUBY init_ruby(); signal(SIGSEGV, SIG_DFL); #endif init_channel(); init_conf(); init_client(); init_parser(); init_channel_modes(); init_mqueue(); init_tor(); me.from = me.servptr = &me; SetServer(&me); SetMe(&me); dlinkAdd(&me, &me.node, &global_client_list); read_services_conf(TRUE); init_db(); init_uid(); #ifdef HAVE_PYTHON init_python(); #endif init_kill(); write_pidfile(ServicesState.pidfile); ilog(L_NOTICE, "Services Ready"); db_load_driver(); #ifdef USE_SHARED_MODULES if(chdir(MODPATH)) { ilog(L_ERROR, "Could not load core modules from %s: %s", MODPATH, strerror(errno)); exit(EXIT_FAILURE); } /* Go back to DPATH after checking to see if we can chdir to MODPATH */ chdir(DPATH); #else load_all_modules(1); #endif boot_modules(1); connect_server(); for(;;) { while (eventNextTime() <= CurrentTime) eventRun(); execute_callback(do_event_cb); if(events_loop() == -1) { ilog(L_CRIT, "libevent returned error %d", errno); services_die("Libevent returned some sort of error", NO); break; } comm_select(); send_queued_all(); if(dorehash) { ilog(L_INFO, "Got SIGHUP, reloading configuration"); read_services_conf(NO); dorehash = 0; } } return 0; }