X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fmain.c;h=23903d93cc26c9ddf4e8804af3887713bd1f244a;hb=88751acefe20e568fc945d7e5f5c11e0a9c7be60;hp=57e4939b8b6d4b185bb624062b725875e30bfdfd;hpb=d5df2d4f914907b38bc20e7c99712eff9b8be69b;p=NeonServV5.git diff --git a/src/main.c b/src/main.c index 57e4939..23903d9 100644 --- a/src/main.c +++ b/src/main.c @@ -47,22 +47,7 @@ #include "IOHandler.h" #include "statistics.h" -static struct { - time_t start_time; - int running : 1; - int restart : 1; - int run_as_daemon : 1; - int daemonized : 1; - int loglevel : 8; - int loaded_config : 1; - int running_threads : 8; - - int argc; - char **argv; - - char config[MAXLEN]; - char pidfile[MAXLEN]; -} process_state; +struct ProcessState process_state; static FILE *log_fptr = NULL; @@ -73,7 +58,7 @@ static pthread_mutex_t log_sync; static pthread_t *current_threads = NULL; #endif -static void main_tread(void *empty); +static void *main_tread(void *empty); static TIMEQ_CALLBACK(clear_cache); static TIMEQ_CALLBACK(main_checkauths); static void check_firstrun(); @@ -168,8 +153,8 @@ static int reload_configuration() { return 3; } free(modulelist); + event_reload(0); } - event_reload(!process_state.loaded_config); process_state.loaded_config = 1; return 0; } @@ -198,9 +183,24 @@ void initialize_subsystems() { } void shutdown_subsystems() { - stop_modules(); free_sockets(1); - usleep(10000); //wait for disconnect (10ms) + //wait 50ms (run iohandler) + { + struct timeval timeout, ctime1, ctime2; + gettimeofday(&ctime1, NULL); + ctime1.tv_usec += 50000; + if(ctime1.tv_usec > 1000000) { + ctime1.tv_usec -= 1000000; + ctime1.tv_sec++; + } + do { + timeout.tv_sec = 0; + timeout.tv_usec = 10000; + iohandler_poll_timeout(timeout); + gettimeofday(&ctime2, NULL); + } while(timeval_is_bigger(ctime1, ctime2)); + } + stop_modules(); free_sockets(0); qserver_free(); free_parser(); @@ -241,10 +241,10 @@ int getRunningThreads() { } static void main_start_threads() { - int tid_id = 0; int worker_threads = get_int_field("General.worker_threads"); if(!worker_threads) worker_threads = 1; #ifdef HAVE_THREADS + int tid_id = 0; { current_threads = calloc(worker_threads, sizeof(*current_threads)); for(tid_id = 0; tid_id < worker_threads; tid_id++) { @@ -266,10 +266,11 @@ static void main_start_threads() { /* MAIN FUNCTION(S) */ -static void main_tread(void *empty) { +static void *main_tread(void *empty) { while(process_state.running) { iohandler_poll(); } + return NULL; } static void main_restart_process() { @@ -312,7 +313,7 @@ int main(int argc, char *argv[]) { //load configuration int errid; - if(errid = reload_configuration()) { + if((errid = reload_configuration())) { fprintf(stderr, "Unable to load configuration file `%s`. (errid: %d)\n", process_state.config, errid); exit(0); }