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")) {
} 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;
}
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;
}
devops.close();
+ exit_control();
+
return;
}
/* Setup sockets and open device. */
if(!setup_network())
- goto end_nonet;
-
- if(!init_control())
- goto end_nonet;
-
- /* Initiate all outgoing connections. */
-
- try_outgoing_connections();
+ goto end;
/* Change process priority */
/* Start main loop. It only exits when tinc is killed. */
+ logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready");
+
+ try_outgoing_connections();
+
status = main_loop();
/* Shutdown properly. */
if(debug_level >= DEBUG_CONNECTIONS)
devops.dump_stats();
- close_network_connections();
-
end:
- exit_control();
+ close_network_connections();
-end_nonet:
logger(DEBUG_ALWAYS, LOG_NOTICE, "Terminating");
free(priority);