summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2020-05-15 10:21:51 +0200
committerantirez <antirez@gmail.com>2020-05-15 10:21:51 +0200
commit3cd92e87d19b7731d9d6f893bbcc861de60d4933 (patch)
tree9db7886972134d64a9b0aeaaa61c2a369c5c8f87
parent1a7cd2c0e25bd4488dd2c28f0ffea1b62dc0b3ad (diff)
parent8f5c2bc8aa79985f6767e4847cc5a5d9606b1b5c (diff)
downloadredis-3cd92e87d19b7731d9d6f893bbcc861de60d4933.tar.gz
Merge branch 'unstable' of github.com:/antirez/redis into unstable
-rw-r--r--src/Makefile10
-rw-r--r--src/ae.c10
-rw-r--r--src/ae.h2
-rw-r--r--src/config.h2
-rw-r--r--src/setcpuaffinity.c19
-rw-r--r--src/tls.c45
-rw-r--r--tests/unit/tls.tcl20
7 files changed, 87 insertions, 21 deletions
diff --git a/src/Makefile b/src/Makefile
index 55f862cfc..b8c05c32b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -129,6 +129,14 @@ ifeq ($(uname_S),DragonFly)
# FreeBSD
FINAL_LIBS+= -lpthread -lexecinfo
else
+ifeq ($(uname_S),OpenBSD)
+ # OpenBSD
+ FINAL_LIBS+= -lpthread -lexecinfo
+else
+ifeq ($(uname_S),NetBSD)
+ # NetBSD
+ FINAL_LIBS+= -lpthread -lexecinfo
+else
# All the other OSes (notably Linux)
FINAL_LDFLAGS+= -rdynamic
FINAL_LIBS+=-ldl -pthread -lrt
@@ -138,6 +146,8 @@ endif
endif
endif
endif
+endif
+endif
# Include paths to dependencies
FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
diff --git a/src/ae.c b/src/ae.c
index 379cfd1e6..689a27d16 100644
--- a/src/ae.c
+++ b/src/ae.c
@@ -238,6 +238,7 @@ long long aeCreateTimeEvent(aeEventLoop *eventLoop, long long milliseconds,
te->clientData = clientData;
te->prev = NULL;
te->next = eventLoop->timeEventHead;
+ te->refcount = 0;
if (te->next)
te->next->prev = te;
eventLoop->timeEventHead = te;
@@ -316,6 +317,13 @@ static int processTimeEvents(aeEventLoop *eventLoop) {
/* Remove events scheduled for deletion. */
if (te->id == AE_DELETED_EVENT_ID) {
aeTimeEvent *next = te->next;
+ /* If a reference exists for this timer event,
+ * don't free it. This is currently incremented
+ * for recursive timerProc calls */
+ if (te->refcount) {
+ te = next;
+ continue;
+ }
if (te->prev)
te->prev->next = te->next;
else
@@ -345,7 +353,9 @@ static int processTimeEvents(aeEventLoop *eventLoop) {
int retval;
id = te->id;
+ te->refcount++;
retval = te->timeProc(eventLoop, id, te->clientData);
+ te->refcount--;
processed++;
if (retval != AE_NOMORE) {
aeAddMillisecondsToNow(retval,&te->when_sec,&te->when_ms);
diff --git a/src/ae.h b/src/ae.h
index 63b306615..d1b7f34bf 100644
--- a/src/ae.h
+++ b/src/ae.h
@@ -86,6 +86,8 @@ typedef struct aeTimeEvent {
void *clientData;
struct aeTimeEvent *prev;
struct aeTimeEvent *next;
+ int refcount; /* refcount to prevent timer events from being
+ * freed in recursive time event calls. */
} aeTimeEvent;
/* A fired event */
diff --git a/src/config.h b/src/config.h
index 6025d4e96..0fcc42972 100644
--- a/src/config.h
+++ b/src/config.h
@@ -248,7 +248,7 @@ int pthread_setname_np(const char *name);
#endif
/* Check if we can use setcpuaffinity(). */
-#if (defined __linux || defined __NetBSD__ || defined __FreeBSD__ || defined __OpenBSD__)
+#if (defined __linux || defined __NetBSD__ || defined __FreeBSD__)
#define USE_SETCPUAFFINITY
void setcpuaffinity(const char *cpulist);
#endif
diff --git a/src/setcpuaffinity.c b/src/setcpuaffinity.c
index dcae81c71..13594113c 100644
--- a/src/setcpuaffinity.c
+++ b/src/setcpuaffinity.c
@@ -36,6 +36,10 @@
#include <sys/param.h>
#include <sys/cpuset.h>
#endif
+#ifdef __NetBSD__
+#include <pthread.h>
+#include <sched.h>
+#endif
#include "config.h"
#ifdef USE_SETCPUAFFINITY
@@ -71,11 +75,18 @@ void setcpuaffinity(const char *cpulist) {
#ifdef __FreeBSD__
cpuset_t cpuset;
#endif
+#ifdef __NetBSD__
+ cpuset_t *cpuset;
+#endif
if (!cpulist)
return;
+#ifndef __NetBSD__
CPU_ZERO(&cpuset);
+#else
+ cpuset = cpuset_create();
+#endif
q = cpulist;
while (p = q, q = next_token(q, ','), p) {
@@ -110,7 +121,11 @@ void setcpuaffinity(const char *cpulist) {
return;
while (a <= b) {
+#ifndef __NetBSD__
CPU_SET(a, &cpuset);
+#else
+ cpuset_set(a, cpuset);
+#endif
a += s;
}
}
@@ -124,6 +139,10 @@ void setcpuaffinity(const char *cpulist) {
#ifdef __FreeBSD__
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset), &cpuset);
#endif
+#ifdef __NetBSD__
+ pthread_setaffinity_np(pthread_self(), cpuset_size(cpuset), cpuset);
+ cpuset_destroy(cpuset);
+#endif
}
#endif /* USE_SETCPUAFFINITY */
diff --git a/src/tls.c b/src/tls.c
index ee85bd302..28a74df9a 100644
--- a/src/tls.c
+++ b/src/tls.c
@@ -93,11 +93,56 @@ static int parseProtocolsConfig(const char *str) {
* served to the reader yet. */
static list *pending_list = NULL;
+/**
+ * OpenSSL global initialization and locking handling callbacks.
+ * Note that this is only required for OpenSSL < 1.1.0.
+ */
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#define USE_CRYPTO_LOCKS
+#endif
+
+#ifdef USE_CRYPTO_LOCKS
+
+static pthread_mutex_t *openssl_locks;
+
+static void sslLockingCallback(int mode, int lock_id, const char *f, int line) {
+ pthread_mutex_t *mt = openssl_locks + lock_id;
+
+ if (mode & CRYPTO_LOCK) {
+ pthread_mutex_lock(mt);
+ } else {
+ pthread_mutex_unlock(mt);
+ }
+
+ (void)f;
+ (void)line;
+}
+
+static void initCryptoLocks(void) {
+ unsigned i, nlocks;
+ if (CRYPTO_get_locking_callback() != NULL) {
+ /* Someone already set the callback before us. Don't destroy it! */
+ return;
+ }
+ nlocks = CRYPTO_num_locks();
+ openssl_locks = zmalloc(sizeof(*openssl_locks) * nlocks);
+ for (i = 0; i < nlocks; i++) {
+ pthread_mutex_init(openssl_locks + i, NULL);
+ }
+ CRYPTO_set_locking_callback(sslLockingCallback);
+}
+#endif /* USE_CRYPTO_LOCKS */
+
void tlsInit(void) {
ERR_load_crypto_strings();
SSL_load_error_strings();
SSL_library_init();
+#ifdef USE_CRYPTO_LOCKS
+ initCryptoLocks();
+#endif
+
if (!RAND_poll()) {
serverLog(LL_WARNING, "OpenSSL: Failed to seed random number generator.");
}
diff --git a/tests/unit/tls.tcl b/tests/unit/tls.tcl
index 950f65557..2b04590cd 100644
--- a/tests/unit/tls.tcl
+++ b/tests/unit/tls.tcl
@@ -25,26 +25,6 @@ start_server {tags {"tls"}} {
}
test {TLS: Verify tls-protocols behaves as expected} {
- r CONFIG SET tls-protocols TLSv1
-
- set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1 0}]
- catch {$s PING} e
- assert_match {*I/O error*} $e
-
- set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1 1}]
- catch {$s PING} e
- assert_match {PONG} $e
-
- r CONFIG SET tls-protocols TLSv1.1
-
- set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1.1 0}]
- catch {$s PING} e
- assert_match {*I/O error*} $e
-
- set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1.1 1}]
- catch {$s PING} e
- assert_match {PONG} $e
-
r CONFIG SET tls-protocols TLSv1.2
set s [redis [srv 0 host] [srv 0 port] 0 1 {-tls1.2 0}]