Fix order of tincd's initialization.
[tinc] / src / net_setup.c
index 64d2515..39fd1e5 100644 (file)
@@ -828,22 +828,6 @@ static bool setup_myself(void) {
        if(device_fd >= 0)
                io_add(&device_io, handle_device_data, NULL, device_fd, IO_READ);
 
-       /* Run tinc-up script to further initialize the tap interface */
-       char *envp[5] = {NULL};
-       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
-       xasprintf(&envp[1], "DEVICE=%s", device ? : "");
-       xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
-       xasprintf(&envp[3], "NAME=%s", myself->name);
-
-       execute_script("tinc-up", envp);
-
-       for(int i = 0; i < 4; i++)
-               free(envp[i]);
-
-       /* Run subnet-up scripts for our own subnets */
-
-       subnet_update(myself, NULL, true);
-
        /* Open sockets */
 
        if(!do_detach && getenv("LISTEN_FDS")) {
@@ -957,9 +941,7 @@ static bool setup_myself(void) {
                } while(cfg);
        }
 
-       if(listen_sockets)
-               logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready");
-       else {
+       if(!listen_sockets) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Unable to create any listening socket!");
                return false;
        }
@@ -997,6 +979,26 @@ bool setup_network(void) {
        if(!setup_myself())
                return false;
 
+       if(!init_control())
+               return false;
+
+       /* Run tinc-up script to further initialize the tap interface */
+
+       char *envp[5] = {NULL};
+       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
+       xasprintf(&envp[1], "DEVICE=%s", device ? : "");
+       xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
+       xasprintf(&envp[3], "NAME=%s", myself->name);
+
+       execute_script("tinc-up", envp);
+
+       for(int i = 0; i < 4; i++)
+               free(envp[i]);
+
+       /* Run subnet-up scripts for our own subnets */
+
+       subnet_update(myself, NULL, true);
+
        return true;
 }
 
@@ -1050,5 +1052,7 @@ void close_network_connections(void) {
 
        devops.close();
 
+       exit_control();
+
        return;
 }