diff --git a/include/maxscale/gw.h b/include/maxscale/gw.h deleted file mode 100644 index a560342fa..000000000 --- a/include/maxscale/gw.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once -#ifndef _MAXSCALE_GW_HG -#define _MAXSCALE_GW_HG -/* - * Copyright (c) 2016 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl. - * - * Change Date: 2019-07-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -MXS_BEGIN_DECLS - -// network buffer is 32K -#define MAX_BUFFER_SIZE 32768 - -#define GW_NOINTR_CALL(A) do { errno = 0; A; } while (errno == EINTR) - -bool gw_daemonize(void); - -MXS_END_DECLS - -#endif diff --git a/include/maxscale/limits.h b/include/maxscale/limits.h index ea3bc874c..43eab289f 100644 --- a/include/maxscale/limits.h +++ b/include/maxscale/limits.h @@ -33,7 +33,7 @@ MXS_BEGIN_DECLS #define MXS_BACKEND_SO_RCVBUF (128 * 1024) /** - * MSX_BACKEND_SO_SNDBUF + * MXS_BACKEND_SO_SNDBUF * * The value used when setting SO_SNDBUF of backend sockets. */ @@ -53,6 +53,16 @@ MXS_BEGIN_DECLS */ #define MXS_CLIENT_SO_SNDBUF (128 * 1024) +/** + * MXS_MAX_NW_READ_BUFFER_SIZE + * + * The maximum amount of data read in one gofrom a client DCB. + * + * TODO: Consider removing altogether so that we always read + * whatever is available in the socket. + */ +#define MXS_MAX_NW_READ_BUFFER_SIZE (32 * 1024) + /** * MXS_MAX_THREADS * diff --git a/include/maxscale/protocol/mysql.h b/include/maxscale/protocol/mysql.h index 7a1c0af06..254478e21 100644 --- a/include/maxscale/protocol/mysql.h +++ b/include/maxscale/protocol/mysql.h @@ -63,7 +63,6 @@ #include #include #include -#include #include MXS_BEGIN_DECLS diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 11a616a62..3c7c630b8 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(maxscale-common SHARED adminusers.c alloc.c authenticator.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c gw_utils.c hashtable.c hint.c housekeeper.c listmanager.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c queuemanager.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c gw_ssl.c mysql_utils.c mysql_binlog.c) +add_library(maxscale-common SHARED adminusers.c alloc.c authenticator.c atomic.c buffer.c config.c dbusers.c dcb.c filter.c externcmd.c gwbitmask.c gwdirs.c hashtable.c hint.c housekeeper.c listmanager.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c queuemanager.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c gw_ssl.c mysql_utils.c mysql_binlog.c) target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIBRARIES} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl pthread crypt dl crypto inih z rt m stdc++) diff --git a/server/core/config.c b/server/core/config.c index 4b9bbab2f..ce3fbf2f9 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -73,7 +73,6 @@ #include #include #include -#include #include #include #define PCRE2_CODE_UNIT_WIDTH 8 diff --git a/server/core/dcb.c b/server/core/dcb.c index 9c9c74746..9d3c5cb87 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -78,7 +78,6 @@ #include #include #include -#include #include #include #include @@ -86,6 +85,8 @@ #include #include #include +#include +#include #include #include #include @@ -1069,7 +1070,7 @@ dcb_basic_read(DCB *dcb, int bytesavailable, int maxbytes, int nreadtotal, int * { GWBUF *buffer; - int bufsize = MXS_MIN(bytesavailable, MAX_BUFFER_SIZE); + int bufsize = MXS_MIN(bytesavailable, MXS_MAX_NW_READ_BUFFER_SIZE); if (maxbytes) { bufsize = MXS_MIN(bufsize, maxbytes - nreadtotal); @@ -1187,10 +1188,10 @@ dcb_read_SSL(DCB *dcb, GWBUF **head) static GWBUF * dcb_basic_read_SSL(DCB *dcb, int *nsingleread) { - unsigned char temp_buffer[MAX_BUFFER_SIZE]; + unsigned char temp_buffer[MXS_MAX_NW_READ_BUFFER_SIZE]; GWBUF *buffer = NULL; - *nsingleread = SSL_read(dcb->ssl, (void *)temp_buffer, MAX_BUFFER_SIZE); + *nsingleread = SSL_read(dcb->ssl, (void *)temp_buffer, MXS_MAX_NW_READ_BUFFER_SIZE); dcb->stats.n_reads++; switch (SSL_get_error(dcb->ssl, *nsingleread)) diff --git a/server/core/gateway.c b/server/core/gateway.c index 6435e4b6d..107e68635 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -48,10 +48,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include @@ -86,6 +86,7 @@ #include #include #include +#include #define STRING_BUFFER_SIZE 1024 #define PIDFD_CLOSED -1 @@ -190,6 +191,7 @@ void write_child_exit_code(int fd, int code); static bool change_cwd(); void shutdown_server(); static void log_exit_status(); +static bool daemonize(); /** SSL multi-threading functions and structures */ @@ -416,25 +418,30 @@ sigfatal_handler(int i) */ static int signal_set(int sig, void (*handler)(int)) { - static struct sigaction sigact; - static int err; int rc = 0; - memset(&sigact, 0, sizeof(struct sigaction)); + struct sigaction sigact = {}; sigact.sa_handler = handler; - GW_NOINTR_CALL(err = sigaction(sig, &sigact, NULL)); + + int err; + + do + { + errno = 0; + err = sigaction(sig, &sigact, NULL); + } + while (errno == EINTR); if (err < 0) { - int eno = errno; - errno = 0; char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed call sigaction() in %s due to %d, %s.", program_invocation_short_name, - eno, - strerror_r(eno, errbuf, sizeof(errbuf))); + errno, + strerror_r(errno, errbuf, sizeof(errbuf))); rc = 1; } + return rc; } @@ -1573,7 +1580,7 @@ int main(int argc, char **argv) /** Daemonize the process and wait for the child process to notify * the parent process of its exit status. */ - parent_process = gw_daemonize(); + parent_process = daemonize(); if (parent_process) { @@ -2658,3 +2665,38 @@ static void log_exit_status() break; } } + +/** + * Daemonize the process by forking and putting the process into the + * background. + * + * @return True if context is that of the parent process, false if that of the + * child process. + */ +static bool daemonize(void) +{ + pid_t pid; + + pid = fork(); + + if (pid < 0) + { + char errbuf[MXS_STRERROR_BUFLEN]; + fprintf(stderr, "fork() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf))); + exit(1); + } + + if (pid != 0) + { + /* exit from main */ + return true; + } + + if (setsid() < 0) + { + char errbuf[MXS_STRERROR_BUFLEN]; + fprintf(stderr, "setsid() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf))); + exit(1); + } + return false; +} diff --git a/server/core/gw_utils.c b/server/core/gw_utils.c deleted file mode 100644 index 60cc9bed5..000000000 --- a/server/core/gw_utils.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2016 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl. - * - * Change Date: 2019-07-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ - -/** - * @file gw_utils.c - A set if utility functions useful within the context - * of the gateway. - * - * @verbatim - * Revision History - * - * Date Who Description - * 03-06-2013 Massimiliano Pinto gateway utils - * 12-06-2013 Massimiliano Pinto gw_read_gwbuff - * with error detection - * and its handling - * 01-07-2013 Massimiliano Pinto Removed session->backends - * from gw_read_gwbuff() - * 25-09-2013 Massimiliano Pinto setipaddress uses getaddrinfo - * 06-02-2014 Mark Riddoch Added parse_bindconfig - * 10-02-2014 Massimiliano Pinto Added return code to setipaddress - * 02-09-2014 Martin Brampton Replace C++ comment with C comment - * 02-03-2016 Martin Brampton Remove default from parse_bindconfig - * - *@endverbatim - */ - -#include -#include -#include -#include - -/** - * Daemonize the process by forking and putting the process into the - * background. - */ -bool gw_daemonize(void) -{ - pid_t pid; - - pid = fork(); - - if (pid < 0) - { - char errbuf[MXS_STRERROR_BUFLEN]; - fprintf(stderr, "fork() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf))); - exit(1); - } - - if (pid != 0) - { - /* exit from main */ - return true; - } - - if (setsid() < 0) - { - char errbuf[MXS_STRERROR_BUFLEN]; - fprintf(stderr, "setsid() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf))); - exit(1); - } - return false; -} diff --git a/server/core/load_utils.c b/server/core/load_utils.c index c995ef085..1c7e241bc 100644 --- a/server/core/load_utils.c +++ b/server/core/load_utils.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include diff --git a/server/core/poll.c b/server/core/poll.c index c32661f68..e6abc9856 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/server/core/secrets.c b/server/core/secrets.c index 30570044d..b197ff1e0 100644 --- a/server/core/secrets.c +++ b/server/core/secrets.c @@ -20,8 +20,6 @@ #include #include -#include - /** * Generate a random printable character * diff --git a/server/core/service.c b/server/core/service.c index 643011a31..c6d7b871d 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -60,7 +60,6 @@ #include #include #include -#include #include #include #include diff --git a/server/modules/authenticator/cdc_plain_auth.c b/server/modules/authenticator/cdc_plain_auth.c index 541d22441..1b19d9b20 100644 --- a/server/modules/authenticator/cdc_plain_auth.c +++ b/server/modules/authenticator/cdc_plain_auth.c @@ -26,11 +26,12 @@ */ #include +#include #include +#include +#include #include #include -#include -#include /* Allowed time interval (in seconds) after last update*/ #define CDC_USERS_REFRESH_TIME 30 diff --git a/server/modules/authenticator/mysql_auth.c b/server/modules/authenticator/mysql_auth.c index 90ac2aa7b..e4cc3ffba 100644 --- a/server/modules/authenticator/mysql_auth.c +++ b/server/modules/authenticator/mysql_auth.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include diff --git a/server/modules/include/cdc.h b/server/modules/include/cdc.h index 0785ccbd0..19a8ff477 100644 --- a/server/modules/include/cdc.h +++ b/server/modules/include/cdc.h @@ -37,7 +37,6 @@ #include #include #include -#include MXS_BEGIN_DECLS diff --git a/server/modules/protocol/CDC/cdc.c b/server/modules/protocol/CDC/cdc.c index 43471caad..e4612780e 100644 --- a/server/modules/protocol/CDC/cdc.c +++ b/server/modules/protocol/CDC/cdc.c @@ -32,7 +32,6 @@ #include #include -#include #include #include #include diff --git a/server/modules/protocol/HTTPD/httpd.c b/server/modules/protocol/HTTPD/httpd.c index d3ae66ff9..fc8220ec1 100644 --- a/server/modules/protocol/HTTPD/httpd.c +++ b/server/modules/protocol/HTTPD/httpd.c @@ -33,9 +33,9 @@ */ #include "httpd.h" +#include #include #include -#include #include #include #include diff --git a/server/modules/protocol/HTTPD/httpd.h b/server/modules/protocol/HTTPD/httpd.h index 4131f3ccf..c8ded44c4 100644 --- a/server/modules/protocol/HTTPD/httpd.h +++ b/server/modules/protocol/HTTPD/httpd.h @@ -37,7 +37,6 @@ #include #include #include -#include MXS_BEGIN_DECLS diff --git a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c index c9ba4d89e..5cdf7e7eb 100644 --- a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c +++ b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c @@ -16,7 +16,6 @@ #include #include #include -#include #include /* diff --git a/server/modules/protocol/MySQL/MySQLClient/mysql_client.c b/server/modules/protocol/MySQL/MySQLClient/mysql_client.c index 519da671b..066179748 100644 --- a/server/modules/protocol/MySQL/MySQLClient/mysql_client.c +++ b/server/modules/protocol/MySQL/MySQLClient/mysql_client.c @@ -52,7 +52,6 @@ #include #include #include -#include #include #include #include diff --git a/server/modules/protocol/MySQL/mysql_common.c b/server/modules/protocol/MySQL/mysql_common.c index 7d6958571..9e3636579 100644 --- a/server/modules/protocol/MySQL/mysql_common.c +++ b/server/modules/protocol/MySQL/mysql_common.c @@ -42,7 +42,6 @@ * */ -#include #include #include #include diff --git a/server/modules/protocol/maxscaled/maxscaled.c b/server/modules/protocol/maxscaled/maxscaled.c index d6758604c..d3a7a7eeb 100644 --- a/server/modules/protocol/maxscaled/maxscaled.c +++ b/server/modules/protocol/maxscaled/maxscaled.c @@ -21,14 +21,15 @@ #include #include #include +#include #include +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/server/modules/protocol/telnetd/telnetd.c b/server/modules/protocol/telnetd/telnetd.c index 95a3f96ea..df802bf8e 100644 --- a/server/modules/protocol/telnetd/telnetd.c +++ b/server/modules/protocol/telnetd/telnetd.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/server/modules/routing/avro/avrorouter.h b/server/modules/routing/avro/avrorouter.h index 63147af7d..1b9accbe9 100644 --- a/server/modules/routing/avro/avrorouter.h +++ b/server/modules/routing/avro/avrorouter.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -108,7 +107,7 @@ typedef enum avro_binlog_end #define TABLE_MAP_MAX_NAME_LEN 64 /** How many bytes each thread tries to send */ -#define AVRO_DATA_BURST_SIZE MAX_BUFFER_SIZE +#define AVRO_DATA_BURST_SIZE (32 * 1024) /** A CREATE TABLE abstraction */ typedef struct table_create diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index 254e59f55..b679dd384 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -79,7 +79,6 @@ #include #include #include -#include static char *version_str = "V2.1.0"; diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 2a455f635..accf2f8ee 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -85,7 +85,6 @@ #include #include #include -#include extern int load_mysql_users(SERV_LISTENER *listener); extern void blr_master_close(ROUTER_INSTANCE* router); @@ -263,7 +262,7 @@ blr_slave_request(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) case COM_QUIT: MXS_DEBUG("COM_QUIT received from slave with server_id %d", slave->serverid); - break; + return 1; default: blr_send_custom_error(slave->dcb, 1, 0, "You have an error in your SQL syntax; Check the "