+bool tinc_start(const char* confbaseapi) {
+ pthread_t tincThread;
+ confbase = confbaseapi;
+ pthread_create(&tincThread,NULL,tinc_main_thread,confbaseapi);
+ pthread_detach(tincThread);
+return true;
+}
+
+bool tinc_main_thread(void * in) {
+ static bool status = false;
+
+ /* If nonzero, write log entries to a separate file. */
+ bool use_logfile = false;
+
+ confbase = (char*) in;
+
+ openlogger("tinc", LOGMODE_STDERR);
+
+ init_configuration(&config_tree);
+
+ /* Slllluuuuuuurrrrp! */
+
+ gettimeofday(&now, NULL);
+ srand(now.tv_sec + now.tv_usec);
+ crypto_init();
+
+ if(!read_server_config())
+ return false;
+
+#ifdef HAVE_LZO
+ if(lzo_init() != LZO_E_OK) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Error initializing LZO compressor!");
+ return false;
+ }
+#endif
+
+ //char *priority = NULL; //shoud be not needed in libmeshlink
+
+#ifdef HAVE_MLOCKALL
+ /* Lock all pages into memory if requested.
+ * This has to be done after daemon()/fork() so it works for child.
+ * No need to do that in parent as it's very short-lived. */
+ if(do_mlock && mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "mlockall",
+ strerror(errno));
+ return 1;
+ }
+#endif
+
+ /* Setup sockets and open device. */
+
+ if(!setup_meshlink_network())
+ goto end;
+
+ /* Change process priority */
+ //should be not needed in libmeshlink
+ //if(get_config_string(lookup_config(config_tree, "ProcessPriority"), &priority)) {
+ // if(!strcasecmp(priority, "Normal")) {
+ // if (setpriority(NORMAL_PRIORITY_CLASS) != 0) {
+ // logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
+ // goto end;
+ // }
+ // } else if(!strcasecmp(priority, "Low")) {
+ // if (setpriority(BELOW_NORMAL_PRIORITY_CLASS) != 0) {
+ // logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
+ // goto end;
+ // }
+ // } else if(!strcasecmp(priority, "High")) {
+ // if (setpriority(HIGH_PRIORITY_CLASS) != 0) {
+ // logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
+ // goto end;
+ // }
+ // } else {
+ // logger(DEBUG_ALWAYS, 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. */
+
+ logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready");
+
+ try_outgoing_connections();
+
+ status = main_loop();
+
+ /* Shutdown properly. */
+
+end:
+ close_network_connections();
+
+ logger(DEBUG_ALWAYS, LOG_NOTICE, "Terminating");
+
+ //free(priority);
+
+ crypto_exit();
+
+ exit_configuration(&config_tree);
+ free(cmdline_conf);
+
+ return status;
+
+}