summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-02 19:20:22 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-03-02 19:20:22 +0000
commit0fed6e67db6104fb6e8ef5183ee4837cd4d9e42a (patch)
treef04bc4bd3884d0f07f63a925f09d9601d2605cec /contrib
parent845460a852f48af2bd506af647c5d3b9ac62622a (diff)
downloadrspamd-0fed6e67db6104fb6e8ef5183ee4837cd4d9e42a.tar.gz
rspamd-0fed6e67db6104fb6e8ef5183ee4837cd4d9e42a.zip
[Minor] Unlink ottery from torch to fix build on some platforms
Diffstat (limited to 'contrib')
-rw-r--r--contrib/torch/torch7/CMakeLists.txt1
-rw-r--r--contrib/torch/torch7/lib/TH/CMakeLists.txt2
-rw-r--r--contrib/torch/torch7/lib/TH/THRandom.c29
3 files changed, 27 insertions, 5 deletions
diff --git a/contrib/torch/torch7/CMakeLists.txt b/contrib/torch/torch7/CMakeLists.txt
index aa848905a..7519e85d7 100644
--- a/contrib/torch/torch7/CMakeLists.txt
+++ b/contrib/torch/torch7/CMakeLists.txt
@@ -63,7 +63,6 @@ SET(luasrc init.lua File.lua Tensor.lua CmdLine.lua FFInterface.lua Tester.lua T
ADD_TORCH_PACKAGE(torch "${src}" "${luasrc}")
TARGET_LINK_LIBRARIES(torch luaT TH)
-TARGET_LINK_LIBRARIES(torch ottery)
IF(LUALIB)
TARGET_LINK_LIBRARIES(torch ${LUALIB})
diff --git a/contrib/torch/torch7/lib/TH/CMakeLists.txt b/contrib/torch/torch7/lib/TH/CMakeLists.txt
index c76d26e06..2b71bc3d0 100644
--- a/contrib/torch/torch7/lib/TH/CMakeLists.txt
+++ b/contrib/torch/torch7/lib/TH/CMakeLists.txt
@@ -291,8 +291,6 @@ IF(NOT MSVC)
TARGET_LINK_LIBRARIES(TH m)
ENDIF(NOT MSVC)
-TARGET_LINK_LIBRARIES(TH ottery)
-
# Is __thread supported?
IF(NOT MSVC)
CHECK_C_SOURCE_COMPILES("static __thread int x = 1; int main() { return x; }" C_HAS_THREAD)
diff --git a/contrib/torch/torch7/lib/TH/THRandom.c b/contrib/torch/torch7/lib/TH/THRandom.c
index 0dca555fd..86d721e7b 100644
--- a/contrib/torch/torch7/lib/TH/THRandom.c
+++ b/contrib/torch/torch7/lib/TH/THRandom.c
@@ -1,6 +1,5 @@
#include "THGeneral.h"
#include "THRandom.h"
-#include "ottery.h"
/* Code for the Mersenne Twister random generator.... */
#define n _MERSENNE_STATE_N
@@ -45,9 +44,35 @@ int THGenerator_isValid(THGenerator *_generator)
return 0;
}
+#ifndef _WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+static unsigned long readURandomLong()
+{
+ int randDev = open("/dev/urandom", O_RDONLY);
+ unsigned long randValue;
+ if (randDev < 0) {
+ THError("Unable to open /dev/urandom");
+ }
+ ssize_t readBytes = read(randDev, &randValue, sizeof(randValue));
+ if (readBytes < sizeof(randValue)) {
+ THError("Unable to read from /dev/urandom");
+ }
+ close(randDev);
+ return randValue;
+}
+#endif // _WIN32
+
unsigned long THRandom_seed(THGenerator *_generator)
{
- unsigned long s = ottery_rand_uint64();
+#ifdef _WIN32
+ unsigned long s = (unsigned long)time(0);
+#else
+ unsigned long s = readURandomLong();
+#endif
THRandom_manualSeed(_generator, s);
return s;
}