+#endif
+
+ /* Setup sockets and open device. */
+
+ if(!setup_network())
+ goto end;
+
+ /* Initiate all outgoing connections. */
+
+ try_outgoing_connections();
+
+ /* Change process priority */
+
+ char *priority = 0;
+
+ if(get_config_string(lookup_config(config_tree, "ProcessPriority"), &priority)) {
+ if(!strcasecmp(priority, "Normal"))
+ setpriority(NORMAL_PRIORITY_CLASS);
+ else if(!strcasecmp(priority, "Low"))
+ setpriority(BELOW_NORMAL_PRIORITY_CLASS);
+ else if(!strcasecmp(priority, "High"))
+ setpriority(HIGH_PRIORITY_CLASS);
+ else {
+ logger(LOG_ERR, _("Invalid priority `%s`!"), priority);
+ goto end;
+ }
+ }
+
+ /* drop privileges */
+ if (!drop_privs())
+ goto end;
+
+ /* Start main loop. It only exits when tinc is killed. */
+
+ status = main_loop();
+
+ /* Shutdown properly. */
+
+ ifdebug(CONNECTIONS)
+ dump_device_stats();
+
+ close_network_connections();
+
+end:
+ logger(LOG_NOTICE, _("Terminating"));
+
+#ifndef HAVE_MINGW
+ exit_control();
+#endif
+
+ crypto_exit();
+
+ exit_configuration(&config_tree);
+ free_names();
+
+ return status;