aboutsummaryrefslogtreecommitdiff
path: root/src/libmain
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-09-04 14:06:52 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-09-04 14:06:52 +0200
commit4caeefaf004c1a4fdd67485f0328a6741a9640fb (patch)
treee6d1504de1baa712c5f8704fb383f99a5e491d8c /src/libmain
parente302ba0e65ba875b7bafd6265285e5f06384b617 (diff)
Revert "Remove obsolete OpenSSL locking code"
This reverts commit aeb695c0074b52772057b36f442a054f8d1a856d.
Diffstat (limited to 'src/libmain')
-rw-r--r--src/libmain/shared.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 910549583..0afddfb78 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -15,6 +15,8 @@
#include <unistd.h>
#include <signal.h>
+#include <openssl/crypto.h>
+
namespace nix {
@@ -78,6 +80,20 @@ string getArg(const string & opt,
}
+/* OpenSSL is not thread-safe by default - it will randomly crash
+ unless the user supplies a mutex locking function. So let's do
+ that. */
+static std::vector<std::mutex> opensslLocks;
+
+static void opensslLockCallback(int mode, int type, const char * file, int line)
+{
+ if (mode & CRYPTO_LOCK)
+ opensslLocks[type].lock();
+ else
+ opensslLocks[type].unlock();
+}
+
+
static void sigHandler(int signo) { }
@@ -89,6 +105,10 @@ void initNix()
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
#endif
+ /* Initialise OpenSSL locking. */
+ opensslLocks = std::vector<std::mutex>(CRYPTO_num_locks());
+ CRYPTO_set_locking_callback(opensslLockCallback);
+
loadConfFile();
startSignalHandlerThread();