From: Guus Sliepen Date: Sun, 13 Apr 2014 11:14:38 +0000 (+0200) Subject: Call srand() and crypto_init() from a constructor. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=536701ed140f716713b4ebeb3f8273fc3b676869;p=meshlink Call srand() and crypto_init() from a constructor. This ensures these routines are always called when the library is loaded. --- diff --git a/src/libmeshlink.c b/src/libmeshlink.c index 761b3a41..1799ead0 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -372,6 +372,19 @@ bool tinc_start(const char* confbaseapi) { return true; } +__attribute__((constructor)) static void meshlink_init(void) { + /* Slllluuuuuuurrrrp! */ + + gettimeofday(&now, NULL); + srand(now.tv_sec + now.tv_usec); + crypto_init(); +} + +__attribute__((destructor)) static void meshlink_exit(void) { + crypto_exit(); +} + + bool tinc_main_thread(void * in) { static bool status = false; @@ -384,12 +397,6 @@ bool tinc_main_thread(void * in) { init_configuration(&config_tree); - /* Slllluuuuuuurrrrp! */ - - gettimeofday(&now, NULL); - srand(now.tv_sec + now.tv_usec); - crypto_init(); - if(!read_server_config()) return false; @@ -456,8 +463,6 @@ end: //free(priority); - crypto_exit(); - exit_configuration(&config_tree); return status;