tincd on Windows: call srand() after main2()
authorKirill Isakov <is-kir@ya.ru>
Sun, 15 Aug 2021 12:43:14 +0000 (18:43 +0600)
committerKirill Isakov <is-kir@ya.ru>
Sun, 15 Aug 2021 12:43:14 +0000 (18:43 +0600)
On Windows, rand() was returning the same sequence on every service
execution, because srand() was initializing its state only for the
short-lived process.

src/tincd.c

index dff420a..560609c 100644 (file)
@@ -491,8 +491,6 @@ int main(int argc, char **argv) {
 
        /* Slllluuuuuuurrrrp! */
 
-       gettimeofday(&now, NULL);
-       srand(now.tv_sec + now.tv_usec);
        crypto_init();
 
        if(!read_server_config(&config_tree)) {
@@ -546,6 +544,9 @@ int main2(int argc, char **argv) {
 #endif
        char *priority = NULL;
 
+       gettimeofday(&now, NULL);
+       srand(now.tv_sec + now.tv_usec);
+
        if(!detach()) {
                return 1;
        }