Просмотр исходного кода

methods/mirror.cc: randomize only based on hostname

Michael Vogt лет назад: 15
Родитель
Сommit
78c8f3cd7e
1 измененных файлов с 15 добавлено и 4 удалено
  1. 15 4
      methods/mirror.cc

+ 15 - 4
methods/mirror.cc

@@ -16,12 +16,15 @@
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/sourcelist.h>
 #include <apt-pkg/sourcelist.h>
 
 
-#include <fstream>
+
 #include <algorithm>
 #include <algorithm>
+#include <fstream>
 #include <iostream>
 #include <iostream>
+
 #include <stdarg.h>
 #include <stdarg.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/types.h>
+#include <sys/utsname.h>
 #include <dirent.h>
 #include <dirent.h>
 
 
 using namespace std;
 using namespace std;
@@ -162,7 +165,17 @@ bool MirrorMethod::RandomizeMirrorFile(string mirror_file)
       content.push_back(line);
       content.push_back(line);
    }
    }
    
    
-   // randomize
+   // we want the file to be random for each different machine, but also
+   // "stable" on the same machine. this is to avoid running into out-of-sync
+   // issues (i.e. Release/Release.gpg different on each mirror)
+   struct utsname buf;
+   int seed=1, i;
+   if(uname(&buf) == 0) {
+      for(i=0,seed=1; buf.nodename[i] != 0; i++) {
+         seed = seed * 31 + buf.nodename[i];
+      }
+   }
+   srand( seed );
    random_shuffle(content.begin(), content.end());
    random_shuffle(content.begin(), content.end());
 
 
    // write
    // write
@@ -403,8 +416,6 @@ int main()
 {
 {
    setlocale(LC_ALL, "");
    setlocale(LC_ALL, "");
 
 
-   srand ( time(NULL) );
-
    MirrorMethod Mth;
    MirrorMethod Mth;
 
 
    return Mth.Loop();
    return Mth.Loop();