From 536701ed140f716713b4ebeb3f8273fc3b676869 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 13 Apr 2014 13:14:38 +0200 Subject: [PATCH] Call srand() and crypto_init() from a constructor. This ensures these routines are always called when the library is loaded. --- src/libmeshlink.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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; -- 2.39.5