]> git.meshlink.io Git - meshlink/commitdiff
Call srand() and crypto_init() from a constructor.
authorGuus Sliepen <guus@meshlink.io>
Sun, 13 Apr 2014 11:14:38 +0000 (13:14 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 13 Apr 2014 11:14:38 +0000 (13:14 +0200)
This ensures these routines are always called when the library is loaded.

src/libmeshlink.c

index 761b3a4137b76202986deaf039d9b2ce07830575..1799ead0d7144c414f5d5b51de93a8bfde54be67 100644 (file)
@@ -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;