Ver Fonte

* srandom() is now called first thing

svn: 1595
Bryan Drewery há 21 anos atrás
pai
commit
5eb8fdb8f0
2 ficheiros alterados com 9 adições e 6 exclusões
  1. 3 1
      src/eggdrop.h
  2. 6 5
      src/main.c

+ 3 - 1
src/eggdrop.h

@@ -104,7 +104,9 @@
  * modulo would probably be sufficient but on systems lacking random(),
  * modulo would probably be sufficient but on systems lacking random(),
  * the function will be just renamed rand().
  * the function will be just renamed rand().
  */
  */
-#define randint(n) (unsigned long) (random() / (RANDOM_MAX + 1.0) * n)
+//#define randint(n) (unsigned long) (random() / (RANDOM_MAX + 1.0) * n)
+#define randint(n) (unsigned long) (random() / (RANDOM_MAX + 1.0) * ((signed) (n) < 0 ? (signed) (-(n)) : (signed) (n)))
+
 
 
 /***********************************************************************/
 /***********************************************************************/
 
 

+ 6 - 5
src/main.c

@@ -688,6 +688,12 @@ int main(int argc, char **argv)
 {
 {
   egg_timeval_t egg_timeval_now;
   egg_timeval_t egg_timeval_now;
 
 
+  /* Initialize variables and stuff */
+  timer_update_now(&egg_timeval_now);
+  now = egg_timeval_now.sec;
+
+  srandom(now % (getpid() + getppid()) * randint(1000));
+
   Context;		/* FIXME: wtf is this here for?, probably some old hack to fix a corrupt heap */
   Context;		/* FIXME: wtf is this here for?, probably some old hack to fix a corrupt heap */
 /*
 /*
   char *out = NULL;
   char *out = NULL;
@@ -730,13 +736,8 @@ printf("out: %s\n", out);
   egg_snprintf(version, sizeof version, "[%s] Wraith %s (%lu)", settings.packname, egg_version, buildts);
   egg_snprintf(version, sizeof version, "[%s] Wraith %s (%lu)", settings.packname, egg_version, buildts);
 
 
   Context;
   Context;
-  /* Initialize variables and stuff */
-  timer_update_now(&egg_timeval_now);
-  now = egg_timeval_now.sec;
-
   egg_memcpy(&nowtm, gmtime(&now), sizeof(struct tm));
   egg_memcpy(&nowtm, gmtime(&now), sizeof(struct tm));
   lastmin = nowtm.tm_min;
   lastmin = nowtm.tm_min;
-  srandom(now % (getpid() + getppid()) * randint(1000));
   myuid = geteuid();
   myuid = geteuid();
 
 
 #ifdef HUB
 #ifdef HUB