From fd987fea90384764299ebd55ea80e0fd68f57625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Mon, 17 Apr 2017 08:12:06 +0000 Subject: [PATCH] Automatically detect kernel and set REUSEPORT #997 Conflicts: lib/ProxySQL_GloVars.cpp --- lib/ProxySQL_GloVars.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index f64eb597c..d1f47acd1 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -2,7 +2,7 @@ #include "proxysql.h" #include "cpp.h" #include - +#include static void term_handler(int sig) { @@ -52,12 +52,38 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() { global.nostart=false; global.foreground=false; global.monitor=true; -#ifdef SO_REUSEPORT - global.reuseport=false; -#endif /* SO_REUSEPORT */ #ifdef IDLE_THREADS global.idle_threads=false; #endif /* IDLE_THREADS */ +#ifdef SO_REUSEPORT + global.reuseport=false; +#endif /* SO_REUSEPORT */ + { + struct utsname unameData; + int rc; + rc=uname(&unameData); + if (rc==0) { + proxy_info("Detected OS: %s\n", unameData.release); + //proxy_info("Detected OS: %s %s %s %s %s\n", unameData.sysname, unameData.nodename, unameData.release, unameData.version, unameData.machine); +#ifdef SO_REUSEPORT + if (strcmp(unameData.sysname,"Linux")==0) { + int major=0, minor=0, revision=0; + sscanf(unameData.release, "%d.%d.%d", &major, &minor, &revision); + //fprintf(stderr,"%d %d %d\n",major,minor,revision); + if ( + (major > 3) + || + (major == 3 && minor >= 9) + ) { + proxy_info("Detected Linux Kernel %d.%d >= 3.9 . Enabling the use of SO_REUSEPORT\n", major, minor); + global.reuseport=true; + } + } +#endif /* SO_REUSEPORT */ + } else { + proxy_error("ERROR: unable to get information about current kernel\n"); + } + } // global.use_proxysql_mem=false; pthread_mutex_init(&global.start_mutex,NULL); #ifdef DEBUG