Gracefully exit through the main thread.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 15 Jan 2011 21:19:11 +0000 (22:19 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 15 Jan 2011 21:19:11 +0000 (22:19 +0100)
src/control.c
src/net.c
src/process.c

index 73d7916..2e6be57 100644 (file)
@@ -54,7 +54,7 @@ bool control_h(connection_t *c, char *request) {
 
        switch (type) {
                case REQ_STOP:
-                       abort();
+                       running = false;
                        return control_ok(c, REQ_STOP);
 
                case REQ_DUMP_NODES:
index 3eec9a6..e52363e 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -199,7 +199,7 @@ static void timeout_handler(void *arg) {
 
                if(rand() % 3 == 0) {
                        logger(LOG_ERR, "Shutting down, check configuration of all nodes for duplicate Names!");
-                       abort();
+                       running = false;
                        return;
                }
 
@@ -259,7 +259,7 @@ int reload_configuration(void) {
 
        if(!read_server_config()) {
                logger(LOG_ERR, "Unable to reread configuration file, exitting.");
-               abort();
+               running = false;
                return EINVAL;
        }
 
@@ -352,8 +352,7 @@ int main_loop(void) {
 
        event_add(&timeout_event);
 
-
-       while(true) {
+       while(running) {
                mutex_unlock(&mutex);
                usleep(1000000);
                mutex_lock(&mutex);
index e6b108f..d88ff97 100644 (file)
@@ -166,7 +166,7 @@ DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
                        return ERROR_CALL_NOT_IMPLEMENTED;
        }
 
-       abort();
+       running = false;
        status.dwWaitHint = 30000; 
        status.dwCurrentState = SERVICE_STOP_PENDING; 
        SetServiceStatus(statushandle, &status);