Merge branch 'develop' into binlog_server_mariadb_master_encryption

This commit is contained in:
MassimilianoPinto
2016-10-17 12:20:23 +02:00
26 changed files with 77 additions and 162 deletions

View File

@ -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 <maxscale/cdefs.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/epoll.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdbool.h>
#include <maxscale/gwdirs.h>
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

View File

@ -33,7 +33,7 @@ MXS_BEGIN_DECLS
#define MXS_BACKEND_SO_RCVBUF (128 * 1024) #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. * The value used when setting SO_SNDBUF of backend sockets.
*/ */
@ -53,6 +53,16 @@ MXS_BEGIN_DECLS
*/ */
#define MXS_CLIENT_SO_SNDBUF (128 * 1024) #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 * MXS_MAX_THREADS
* *

View File

@ -63,7 +63,6 @@
#include <maxscale/version.h> #include <maxscale/version.h>
#include <maxscale/housekeeper.h> #include <maxscale/housekeeper.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>
#include <maxscale/gw.h>
#include <mysql.h> #include <mysql.h>
MXS_BEGIN_DECLS MXS_BEGIN_DECLS

View File

@ -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++) 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++)

View File

@ -73,7 +73,6 @@
#include <string.h> #include <string.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <maxscale/dbusers.h> #include <maxscale/dbusers.h>
#include <maxscale/gw.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/limits.h> #include <maxscale/limits.h>
#define PCRE2_CODE_UNIT_WIDTH 8 #define PCRE2_CODE_UNIT_WIDTH 8

View File

@ -78,7 +78,6 @@
#include <maxscale/modules.h> #include <maxscale/modules.h>
#include <maxscale/router.h> #include <maxscale/router.h>
#include <errno.h> #include <errno.h>
#include <maxscale/gw.h>
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/atomic.h> #include <maxscale/atomic.h>
#include <maxscale/log_manager.h> #include <maxscale/log_manager.h>
@ -86,6 +85,8 @@
#include <maxscale/listener.h> #include <maxscale/listener.h>
#include <maxscale/hk_heartbeat.h> #include <maxscale/hk_heartbeat.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
@ -1069,7 +1070,7 @@ dcb_basic_read(DCB *dcb, int bytesavailable, int maxbytes, int nreadtotal, int *
{ {
GWBUF *buffer; GWBUF *buffer;
int bufsize = MXS_MIN(bytesavailable, MAX_BUFFER_SIZE); int bufsize = MXS_MIN(bytesavailable, MXS_MAX_NW_READ_BUFFER_SIZE);
if (maxbytes) if (maxbytes)
{ {
bufsize = MXS_MIN(bufsize, maxbytes - nreadtotal); bufsize = MXS_MIN(bufsize, maxbytes - nreadtotal);
@ -1187,10 +1188,10 @@ dcb_read_SSL(DCB *dcb, GWBUF **head)
static GWBUF * static GWBUF *
dcb_basic_read_SSL(DCB *dcb, int *nsingleread) 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; 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++; dcb->stats.n_reads++;
switch (SSL_get_error(dcb->ssl, *nsingleread)) switch (SSL_get_error(dcb->ssl, *nsingleread))

View File

@ -48,10 +48,10 @@
#include <ftw.h> #include <ftw.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <maxscale/gw.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <getopt.h> #include <getopt.h>
#include <pwd.h>
#include <maxscale/service.h> #include <maxscale/service.h>
#include <maxscale/server.h> #include <maxscale/server.h>
#include <maxscale/dcb.h> #include <maxscale/dcb.h>
@ -86,6 +86,7 @@
#include <sys/file.h> #include <sys/file.h>
#include <maxscale/statistics.h> #include <maxscale/statistics.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/gwdirs.h>
#define STRING_BUFFER_SIZE 1024 #define STRING_BUFFER_SIZE 1024
#define PIDFD_CLOSED -1 #define PIDFD_CLOSED -1
@ -190,6 +191,7 @@ void write_child_exit_code(int fd, int code);
static bool change_cwd(); static bool change_cwd();
void shutdown_server(); void shutdown_server();
static void log_exit_status(); static void log_exit_status();
static bool daemonize();
/** SSL multi-threading functions and structures */ /** SSL multi-threading functions and structures */
@ -416,25 +418,30 @@ sigfatal_handler(int i)
*/ */
static int signal_set(int sig, void (*handler)(int)) static int signal_set(int sig, void (*handler)(int))
{ {
static struct sigaction sigact;
static int err;
int rc = 0; int rc = 0;
memset(&sigact, 0, sizeof(struct sigaction)); struct sigaction sigact = {};
sigact.sa_handler = handler; 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) if (err < 0)
{ {
int eno = errno;
errno = 0;
char errbuf[MXS_STRERROR_BUFLEN]; char errbuf[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed call sigaction() in %s due to %d, %s.", MXS_ERROR("Failed call sigaction() in %s due to %d, %s.",
program_invocation_short_name, program_invocation_short_name,
eno, errno,
strerror_r(eno, errbuf, sizeof(errbuf))); strerror_r(errno, errbuf, sizeof(errbuf)));
rc = 1; rc = 1;
} }
return rc; return rc;
} }
@ -1573,7 +1580,7 @@ int main(int argc, char **argv)
/** Daemonize the process and wait for the child process to notify /** Daemonize the process and wait for the child process to notify
* the parent process of its exit status. */ * the parent process of its exit status. */
parent_process = gw_daemonize(); parent_process = daemonize();
if (parent_process) if (parent_process)
{ {
@ -2658,3 +2665,38 @@ static void log_exit_status()
break; 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;
}

View File

@ -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 <maxscale/gw.h>
#include <maxscale/dcb.h>
#include <maxscale/session.h>
#include <maxscale/log_manager.h>
/**
* 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;
}

View File

@ -42,7 +42,6 @@
#include <curl/curl.h> #include <curl/curl.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <openssl/sha.h> #include <openssl/sha.h>
#include <maxscale/gw.h>
#include <maxscale/gwdirs.h> #include <maxscale/gwdirs.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>

View File

@ -25,7 +25,6 @@
#include <maxscale/atomic.h> #include <maxscale/atomic.h>
#include <maxscale/gwbitmask.h> #include <maxscale/gwbitmask.h>
#include <maxscale/log_manager.h> #include <maxscale/log_manager.h>
#include <maxscale/gw.h>
#include <maxscale/housekeeper.h> #include <maxscale/housekeeper.h>
#include <maxscale/config.h> #include <maxscale/config.h>
#include <mysql.h> #include <mysql.h>

View File

@ -20,8 +20,6 @@
#include <maxscale/random_jkiss.h> #include <maxscale/random_jkiss.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/gw.h>
/** /**
* Generate a random printable character * Generate a random printable character
* *

View File

@ -60,7 +60,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <maxscale/housekeeper.h> #include <maxscale/housekeeper.h>
#include <maxscale/resultset.h> #include <maxscale/resultset.h>
#include <maxscale/gw.h>
#include <maxscale/gwdirs.h> #include <maxscale/gwdirs.h>
#include <math.h> #include <math.h>
#include <maxscale/version.h> #include <maxscale/version.h>

View File

@ -26,11 +26,12 @@
*/ */
#include <maxscale/gw_authenticator.h> #include <maxscale/gw_authenticator.h>
#include <sys/stat.h>
#include <cdc.h> #include <cdc.h>
#include <maxscale/alloc.h>
#include <maxscale/gwdirs.h>
#include <maxscale/modutil.h> #include <maxscale/modutil.h>
#include <maxscale/users.h> #include <maxscale/users.h>
#include <sys/stat.h>
#include <maxscale/alloc.h>
/* Allowed time interval (in seconds) after last update*/ /* Allowed time interval (in seconds) after last update*/
#define CDC_USERS_REFRESH_TIME 30 #define CDC_USERS_REFRESH_TIME 30

View File

@ -32,7 +32,6 @@
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/dbusers.h> #include <maxscale/dbusers.h>
#include <maxscale/gwdirs.h> #include <maxscale/gwdirs.h>
#include <maxscale/gw.h>
#include <maxscale/secrets.h> #include <maxscale/secrets.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>

View File

@ -37,7 +37,6 @@
#include <maxscale/router.h> #include <maxscale/router.h>
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/atomic.h> #include <maxscale/atomic.h>
#include <maxscale/gw.h>
MXS_BEGIN_DECLS MXS_BEGIN_DECLS

View File

@ -32,7 +32,6 @@
#include <cdc.h> #include <cdc.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/gw.h>
#include <maxscale/modinfo.h> #include <maxscale/modinfo.h>
#include <maxscale/log_manager.h> #include <maxscale/log_manager.h>
#include <maxscale/gw_protocol.h> #include <maxscale/gw_protocol.h>

View File

@ -33,9 +33,9 @@
*/ */
#include "httpd.h" #include "httpd.h"
#include <ctype.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/gw_protocol.h> #include <maxscale/gw_protocol.h>
#include <maxscale/gw.h>
#include <maxscale/modinfo.h> #include <maxscale/modinfo.h>
#include <maxscale/log_manager.h> #include <maxscale/log_manager.h>
#include <maxscale/resultset.h> #include <maxscale/resultset.h>

View File

@ -37,7 +37,6 @@
#include <maxscale/router.h> #include <maxscale/router.h>
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/atomic.h> #include <maxscale/atomic.h>
#include <maxscale/gw.h>
MXS_BEGIN_DECLS MXS_BEGIN_DECLS

View File

@ -16,7 +16,6 @@
#include <maxscale/modutil.h> #include <maxscale/modutil.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <maxscale/gw.h>
#include <mysqld_error.h> #include <mysqld_error.h>
/* /*

View File

@ -52,7 +52,6 @@
#include <mysql_auth.h> #include <mysql_auth.h>
#include <maxscale/gw_ssl.h> #include <maxscale/gw_ssl.h>
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/gw.h>
#include <maxscale/modinfo.h> #include <maxscale/modinfo.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <maxscale/modutil.h> #include <maxscale/modutil.h>

View File

@ -42,7 +42,6 @@
* *
*/ */
#include <maxscale/gw.h>
#include <maxscale/utils.h> #include <maxscale/utils.h>
#include <maxscale/protocol/mysql.h> #include <maxscale/protocol/mysql.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>

View File

@ -21,14 +21,15 @@
#include <maxscale/session.h> #include <maxscale/session.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <errno.h> #include <errno.h>
#include <pwd.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h> #include <sys/un.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <maxscale/router.h> #include <maxscale/router.h>
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/atomic.h> #include <maxscale/atomic.h>
#include <maxscale/gw.h>
#include <maxscale/adminusers.h> #include <maxscale/adminusers.h>
#include <maxscale/log_manager.h> #include <maxscale/log_manager.h>
#include <maxscale/modinfo.h> #include <maxscale/modinfo.h>

View File

@ -28,7 +28,6 @@
#include <maxscale/router.h> #include <maxscale/router.h>
#include <maxscale/poll.h> #include <maxscale/poll.h>
#include <maxscale/atomic.h> #include <maxscale/atomic.h>
#include <maxscale/gw.h>
#include <telnetd.h> #include <telnetd.h>
#include <maxscale/adminusers.h> #include <maxscale/adminusers.h>
#include <maxscale/log_manager.h> #include <maxscale/log_manager.h>

View File

@ -22,7 +22,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <blr_constants.h> #include <blr_constants.h>
#include <maxscale/gw.h>
#include <maxscale/dcb.h> #include <maxscale/dcb.h>
#include <maxscale/service.h> #include <maxscale/service.h>
#include <maxscale/spinlock.h> #include <maxscale/spinlock.h>
@ -108,7 +107,7 @@ typedef enum avro_binlog_end
#define TABLE_MAP_MAX_NAME_LEN 64 #define TABLE_MAP_MAX_NAME_LEN 64
/** How many bytes each thread tries to send */ /** 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 */ /** A CREATE TABLE abstraction */
typedef struct table_create typedef struct table_create

View File

@ -79,7 +79,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/gw.h>
static char *version_str = "V2.1.0"; static char *version_str = "V2.1.0";

View File

@ -85,7 +85,6 @@
#include <maxscale/version.h> #include <maxscale/version.h>
#include <zlib.h> #include <zlib.h>
#include <maxscale/alloc.h> #include <maxscale/alloc.h>
#include <maxscale/gw.h>
extern int load_mysql_users(SERV_LISTENER *listener); extern int load_mysql_users(SERV_LISTENER *listener);
extern void blr_master_close(ROUTER_INSTANCE* router); 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: case COM_QUIT:
MXS_DEBUG("COM_QUIT received from slave with server_id %d", MXS_DEBUG("COM_QUIT received from slave with server_id %d",
slave->serverid); slave->serverid);
break; return 1;
default: default:
blr_send_custom_error(slave->dcb, 1, 0, blr_send_custom_error(slave->dcb, 1, 0,
"You have an error in your SQL syntax; Check the " "You have an error in your SQL syntax; Check the "