From 7496789f10cc93bb8fefee9cbd1a59bc06ed1bef Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 31 May 2016 14:24:55 +0200 Subject: [PATCH] Fix openssl sigpipe correctly, move signal handler to openssl.c --- include/mariadb_com.h | 1 + libmariadb/mariadb_lib.c | 18 ------------------ libmariadb/secure/openssl.c | 23 +++++++++++++++++++++++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/mariadb_com.h b/include/mariadb_com.h index 5bf34545..e0bd0e7a 100644 --- a/include/mariadb_com.h +++ b/include/mariadb_com.h @@ -157,6 +157,7 @@ enum enum_server_command #define CLIENT_CONNECT_ATTRS (1UL << 20) #define CLIENT_SESSION_TRACKING (1UL << 23) #define CLIENT_PROGRESS (1UL << 29) /* client supports progress indicator */ +#define CLIENT_PROGRESS_OBSOLETE CLIENT_PROGRESS #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) #define CLIENT_REMEMBER_OPTIONS (1UL << 31) diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index a0b71c48..622b7937 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -3472,13 +3472,6 @@ BOOL CALLBACK win_init_once( } #endif -#if defined(SIGPIPE) && !defined(_WIN32) && defined(WITH_OPENSSL) -static void ma_sigpipe_handler() -{ - return; -} -#endif - int STDCALL mysql_server_init(int argc __attribute__((unused)), char **argv __attribute__((unused)), char **groups __attribute__((unused))) @@ -3489,17 +3482,6 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), return ret? 0: 1; #else static pthread_once_t init_once = PTHREAD_ONCE_INIT; -#if defined(SIGPIPE) && defined(WITH_OPENSSL) - struct sigaction old_handler, new_handler={NULL}; - if (!sigaction (SIGPIPE, NULL, &old_handler) && - !old_handler.sa_handler) - { - new_handler.sa_handler= ma_sigpipe_handler; - new_handler.sa_flags= 0; - if (!sigemptyset(&new_handler.sa_mask)) - sigaction(SIGPIPE, &new_handler, NULL); - } -#endif return pthread_once(&init_once, mysql_once_init); #endif } diff --git a/libmariadb/secure/openssl.c b/libmariadb/secure/openssl.c index 2088d7e3..1bab8135 100644 --- a/libmariadb/secure/openssl.c +++ b/libmariadb/secure/openssl.c @@ -226,6 +226,28 @@ static int ssl_thread_init() } +#ifdef _WIN32 +#define disable_sigpipe() +#else +#include +static void ma_sigpipe_handler() +{ +} + +static void disable_sigpipe() +{ + struct sigaction old_handler, new_handler={NULL}; + if (!sigaction (SIGPIPE, NULL, &old_handler) && + !old_handler.sa_handler) + { + new_handler.sa_handler= ma_sigpipe_handler; + new_handler.sa_flags= 0; + if (!sigemptyset(&new_handler.sa_mask)) + sigaction(SIGPIPE, &new_handler, NULL); + } +} +#endif + /* Initializes SSL and allocate global context SSL_context @@ -276,6 +298,7 @@ int ma_tls_start(char *errmsg, size_t errmsg_len) SSL_CTX_sess_set_new_cb(SSL_context, ma_tls_session_cb); SSL_CTX_sess_set_remove_cb(SSL_context, ma_tls_remove_session_cb); #endif + disable_sigpipe(); rc= 0; ma_tls_initialized= TRUE; end: