fixed crash management
[NeonServV5.git] / src / main.c
index fbf9ed5806f4b93d9cb0c292c1a07feb4ff32794..f567e93f3e92ec5eaf0cd4b1e54caa1bea401cca 100644 (file)
@@ -1,4 +1,4 @@
-/* main.c - NeonServ v5.3
+/* main.c - NeonServ v5.4
  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -116,11 +116,13 @@ void * thread_main(void *arg) {
         socket_wait = time(0) + SOCKET_SELECT_TIME;
         do {
             if(!socket_loop(SOCKET_SELECT_TIME)) {
-                putlog(LOGLEVEL_ERROR, "No more active Bots... shutting down.");
+                if(!running) break;
+                putlog(LOGLEVEL_ERROR, "No more active Bots... shutting down.\n");
                 cleanup();
                 exit(0);
             }
         } while(time(0) < socket_wait);
+        if(!running) break;
         clearTempUsers();
         destroyEvents();
         mysql_free();
@@ -147,6 +149,7 @@ int getCurrentThreadID() {
 #endif
 
 void exit_daemon() {
+    running = 0;
     if(daemonized) {
         remove(PID_FILE);
     }
@@ -229,8 +232,8 @@ int main(int argc, char *argv[]) {
         atexit(exit_daemon);
         FILE *pidfile = fopen(PID_FILE, "w");
         if (pidfile == NULL) {
-            fprintf(stderr, "Unable to create PID file: %s", strerror(errno));
-            putlog(LOGLEVEL_ERROR, "Unable to create PID file: %s", strerror(errno));
+            fprintf(stderr, "Unable to create PID file: %s\n", strerror(errno));
+            putlog(LOGLEVEL_ERROR, "Unable to create PID file: %s\n", strerror(errno));
         } else {
             fprintf(pidfile, "%i\n", (int)getpid());
             fclose(pidfile);
@@ -326,7 +329,7 @@ main:
         socket_wait = time(0) + SOCKET_SELECT_TIME;
         do {
             if(!socket_loop(SOCKET_SELECT_TIME)) {
-                putlog(LOGLEVEL_ERROR, "No more active Bots... shutting down.");
+                putlog(LOGLEVEL_ERROR, "No more active Bots... shutting down.\n");
                 cleanup();
                 exit(0);
             }