diff --git a/avro/maxavro_record.c b/avro/maxavro_record.c index 961bc2add..07a6de119 100644 --- a/avro/maxavro_record.c +++ b/avro/maxavro_record.c @@ -11,10 +11,10 @@ * Public License. */ +#include #include "maxavro.h" -#include #include -#include +#include #include #include @@ -324,7 +324,7 @@ GWBUF* maxavro_record_read_binary(MAXAVRO_FILE *file) { if (ferror(file->file)) { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to read %ld bytes: %d, %s", data_size, errno, strerror_r(errno, err, sizeof(err))); file->last_error = MAXAVRO_ERR_IO; diff --git a/avro/maxavro_schema.c b/avro/maxavro_schema.c index e133b03c5..4b5b3fa60 100644 --- a/avro/maxavro_schema.c +++ b/avro/maxavro_schema.c @@ -14,7 +14,7 @@ #include "maxavro.h" #include #include -#include +#include #include static const MAXAVRO_SCHEMA_FIELD types[MAXAVRO_TYPE_MAX] = diff --git a/avro/maxavrocheck.c b/avro/maxavrocheck.c index 23655be56..9a55e1559 100644 --- a/avro/maxavrocheck.c +++ b/avro/maxavrocheck.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include static int verbose = 0; static uint64_t seekto = 0; diff --git a/include/maxscale/adminusers.h.in b/include/maxscale/adminusers.h.in index 25e6acbe2..bc9302b13 100644 --- a/include/maxscale/adminusers.h.in +++ b/include/maxscale/adminusers.h.in @@ -1,5 +1,6 @@ -#ifndef _ADMINUSERS_H -#define _ADMINUSERS_H +#pragma once +#ifndef _MAXSCALE_ADMINUSERS_H +#define _MAXSCALE_ADMINUSERS_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -24,8 +25,12 @@ * * @endverbatim */ + +#include #include +MXS_BEGIN_DECLS + #define ADMIN_SALT "$1$MXS" /* Max length of fields in for admin users */ @@ -63,4 +68,6 @@ extern bool admin_verify_inet_user(const char *uname, const char *passwor extern void dcb_PrintAdminUsers(DCB *dcb); +MXS_END_DECLS + #endif diff --git a/include/maxscale/alloc.h b/include/maxscale/alloc.h index e138d3af3..49cd04a29 100644 --- a/include/maxscale/alloc.h +++ b/include/maxscale/alloc.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MAXSCALE_ALLOC_H #define _MAXSCALE_ALLOC_H /* @@ -13,11 +14,11 @@ * Public License. */ +#include #include #include -#include -EXTERN_C_BLOCK_BEGIN +MXS_BEGIN_DECLS /* * NOTE: Do not use these functions directly, use the macros below. @@ -77,6 +78,6 @@ char *mxs_strndup_a(const char *s, size_t n/*, const char *caller*/); */ #define MXS_ABORT_IF_FALSE(b) do { if (!b) { abort(); } } while (false) -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/include/maxscale/atomic.h b/include/maxscale/atomic.h index bcd76f9a4..71127ee7c 100644 --- a/include/maxscale/atomic.h +++ b/include/maxscale/atomic.h @@ -1,5 +1,6 @@ -#ifndef _ATOMIC_H -#define _ATOMIC_H +#pragma once +#ifndef _MAXSCALE_ATOMIC_H +#define _MAXSCALE_ATOMIC_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -26,9 +27,13 @@ * @endverbatim */ -#ifdef __cplusplus -extern "C" int atomic_add(int *variable, int value); -#else -extern int atomic_add(int *variable, int value); -#endif +#include + +MXS_BEGIN_DECLS + +int atomic_add(int *variable, int value); +int atomic_add(int *variable, int value); + +MXS_END_DECLS + #endif diff --git a/include/maxscale/buffer.h b/include/maxscale/buffer.h index 935652671..f963167a0 100644 --- a/include/maxscale/buffer.h +++ b/include/maxscale/buffer.h @@ -1,5 +1,6 @@ -#ifndef _BUFFER_H -#define _BUFFER_H +#pragma once +#ifndef _MAXSCALE_BUFFER_H +#define _MAXSCALE_BUFFER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -42,13 +43,15 @@ * * @endverbatim */ + +#include #include -#include +#include #include #include #include -EXTERN_C_BLOCK_BEGIN +MXS_BEGIN_DECLS /** * Buffer properties - used to store properties related to the buffer @@ -214,7 +217,7 @@ void* gwbuf_get_buffer_object_data(GWBUF* buf, bufobj_id_t id) #if defined(BUFFER_TRACE) extern void dprintAllBuffers(void *pdcb); #endif -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/include/maxscale/cdefs.h b/include/maxscale/cdefs.h new file mode 100644 index 000000000..62c28b328 --- /dev/null +++ b/include/maxscale/cdefs.h @@ -0,0 +1,76 @@ +#pragma once +#ifndef _MAXSCALE_CDEFS_H +#define _MAXSCALE_CDEFS_H +/* + * 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 cdefs.h + * + * This file has several purposes. + * + * - Its purpose is the same as that of x86_64-linux-gnu/sys/cdefs.h, that is, + * it defines things that are dependent upon the compilation environment. + * - Since this *must* be included as the very first header by all other MaxScale + * headers, it allows you to redfine things globally, should that be necessary, + * for instance, when debugging something. + * - Global constants applicable across the line can be defined here. + */ + +#ifdef __cplusplus +# define MXS_BEGIN_DECLS extern "C" { +# define MXS_END_DECLS } +#else +# define MXS_BEGIN_DECLS +# define MXS_END_DECLS +#endif + +/** + * Define intended for use with strerror. + * + * char errbuf[MXS_STRERROR_BUFLEN]; + * strerror_r(errno, errbuf, sizeof(errbuf)) + */ +#define MXS_STRERROR_BUFLEN 512 + +/** + * Returns the smaller of two items. + * + * @param a A value. + * @param b Another value. + * + * @return a if a is smaller than b, b otherwise. + * + * @note This a macro, so the arguments will be evaluated more than once. + */ +#define MXS_MIN(a,b) ((a)<(b) ? (a) : (b)) + +/** + * Returns the larger of two items. + * + * @param a A value. + * @param b Another value. + * + * @return a if a is larger than b, b otherwise. + * + * @note This a macro, so the arguments will be evaluated more than once. + */ +#define MXS_MAX(a,b) ((a)>(b) ? (a) : (b)) + +/** + * COMMON INCLUDE FILES + */ +#include +#include + +#endif diff --git a/include/maxscale/config.h b/include/maxscale/config.h index 2bf3c650b..128a906eb 100644 --- a/include/maxscale/config.h +++ b/include/maxscale/config.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MAXSCALE_CONFIG_H #define _MAXSCALE_CONFIG_H /* @@ -12,11 +13,7 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#include -#include -#include -#include -#include + /** * @file config.h The configuration handling elements * @@ -33,6 +30,14 @@ * @endverbatim */ +#include +#include +#include +#include +#include + +MXS_BEGIN_DECLS + #define DEFAULT_NBPOLLS 3 /**< Default number of non block polls before we block */ #define DEFAULT_POLLSLEEP 1000 /**< Default poll wait time (milliseconds) */ #define _RELEASE_STR_LENGTH 256 /**< release len */ @@ -160,4 +165,6 @@ int config_truth_value(char *); void free_config_parameter(CONFIG_PARAMETER* p1); bool is_internal_service(const char *router); +MXS_END_DECLS + #endif diff --git a/include/maxscale/dbusers.h b/include/maxscale/dbusers.h index ea669b4df..22b7bc2d0 100644 --- a/include/maxscale/dbusers.h +++ b/include/maxscale/dbusers.h @@ -1,5 +1,6 @@ -#ifndef _DBUSERS_H -#define _DBUSERS_H +#pragma once +#ifndef _MAXSCALE_DBUSERS_H +#define _MAXSCALE_DBUSERS_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,10 +14,6 @@ * Public License. */ -#include -#include - - /** * @file dbusers.h Extarct user information form the backend database * @@ -33,6 +30,12 @@ * @endverbatim */ +#include +#include +#include + +MXS_BEGIN_DECLS + /* Refresh rate limits for load users from database */ #define USERS_REFRESH_TIME 30 /* Allowed time interval (in seconds) after last update*/ #define USERS_REFRESH_MAX_PER_TIME 4 /* Max number of load calls within the time interval */ @@ -77,4 +80,6 @@ extern char *mysql_users_fetch(USERS *users, MYSQL_USER_HOST *key); extern int reload_mysql_users(SERV_LISTENER *listener); extern int replace_mysql_users(SERV_LISTENER *listener); +MXS_END_DECLS + #endif diff --git a/include/maxscale/dcb.h b/include/maxscale/dcb.h index 3a6020003..5b08e377c 100644 --- a/include/maxscale/dcb.h +++ b/include/maxscale/dcb.h @@ -1,5 +1,6 @@ -#ifndef _DCB_H -#define _DCB_H +#pragma once +#ifndef _MAXSCALE_DCB_H +#define _MAXSCALE_DCB_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -12,23 +13,6 @@ * 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 - -#define ERRHANDLE - -struct session; -struct server; -struct service; -struct servlistener; /** * @file dcb.h The Descriptor Control Block @@ -63,6 +47,26 @@ struct servlistener; * @endverbatim */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MXS_BEGIN_DECLS + +#define ERRHANDLE + +struct session; +struct server; +struct service; +struct servlistener; + struct dcb; /** @@ -369,4 +373,7 @@ void dcb_append_readqueue(DCB *dcb, GWBUF *buffer); #define DCB_IS_CLONE(d) ((d)->flags & DCBF_CLONE) #define DCB_REPLIED(d) ((d)->flags & DCBF_REPLIED) + +MXS_END_DECLS + #endif /* _DCB_H */ diff --git a/include/maxscale/skygw_debug.h b/include/maxscale/debug.h similarity index 98% rename from include/maxscale/skygw_debug.h rename to include/maxscale/debug.h index da75fc057..69d0d7367 100644 --- a/include/maxscale/skygw_debug.h +++ b/include/maxscale/debug.h @@ -1,3 +1,6 @@ +#pragma once +#ifndef _MAXSCALE_DEBUG_H +#define _MAXSCALE_DEBUG_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -11,29 +14,15 @@ * Public License. */ -#include -#include +#include #include #include - -#define __USE_UNIX98 1 +#include +#include #include -#include -#include +#include -#if !defined(SKYGW_DEBUG_H) -#define SKYGW_DEBUG_H - - -#ifdef __cplusplus -#define EXTERN_C_BLOCK_BEGIN extern "C" { -#define EXTERN_C_BLOCK_END } -#define EXTERN_C_FUNC extern "C" -#else -#define EXTERN_C_BLOCK_BEGIN -#define EXTERN_C_BLOCK_END -#define EXTERN_C_FUNC -#endif +MXS_BEGIN_DECLS #if defined(SS_DEBUG) # define SS_PROF @@ -578,4 +567,6 @@ typedef enum skygw_chk_t static bool conn_open[10240]; #endif /* FAKE_CODE */ -#endif /* SKYGW_DEBUG_H */ +MXS_END_DECLS + +#endif diff --git a/include/maxscale/externcmd.h b/include/maxscale/externcmd.h index eed094fdc..36efeb544 100644 --- a/include/maxscale/externcmd.h +++ b/include/maxscale/externcmd.h @@ -1,5 +1,6 @@ -#ifndef _EXTERN_CMD_HG -#define _EXTERN_CMD_HG +#pragma once +#ifndef _MAXSCALE_EXTERN_CMD_HG +#define _MAXSCALE_EXTERN_CMD_HG /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,13 +14,15 @@ * Public License. */ +#include #include #include #include -#include #include #include +MXS_BEGIN_DECLS + #define MAXSCALE_EXTCMD_ARG_MAX 256 typedef struct extern_cmd_t @@ -38,4 +41,6 @@ bool externcmd_substitute_arg(EXTERNCMD* cmd, const char* re, const char* replac bool externcmd_can_execute(const char* argstr); bool externcmd_matches(const EXTERNCMD* cmd, const char* match); +MXS_END_DECLS + #endif diff --git a/include/maxscale/filter.h b/include/maxscale/filter.h index 3ccb8ac4c..780ed06f2 100644 --- a/include/maxscale/filter.h +++ b/include/maxscale/filter.h @@ -1,5 +1,6 @@ -#ifndef _FILTER_H -#define _FILTER_H +#pragma once +#ifndef _MAXSCALE_FILTER_H +#define _MAXSCALE_FILTER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -22,11 +23,15 @@ * 27/05/2014 Mark Riddoch Initial implementation * */ + +#include #include #include #include #include +MXS_BEGIN_DECLS + /** * The FILTER handle points to module specific data, so the best we can do * is to make it a void * externally. @@ -116,4 +121,6 @@ void dprintAllFilters(DCB *); void dprintFilter(DCB *, FILTER_DEF *); void dListFilters(DCB *); +MXS_END_DECLS + #endif diff --git a/include/maxscale/gw.h b/include/maxscale/gw.h index 17b011a28..085c73e58 100644 --- a/include/maxscale/gw.h +++ b/include/maxscale/gw.h @@ -1,5 +1,6 @@ -#ifndef _GW_HG -#define _GW_HG +#pragma once +#ifndef _MAXSCALE_GW_HG +#define _MAXSCALE_GW_HG /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,7 +14,7 @@ * Public License. */ - +#include #include #include #include @@ -35,6 +36,8 @@ #include #include +MXS_BEGIN_DECLS + #define EXIT_FAILURE 1 // network buffer is 32K @@ -83,4 +86,7 @@ char* get_libdir(); long get_processor_count(); void clean_up_pathname(char *path); bool mxs_mkdir_all(const char *path, int mask); + +MXS_END_DECLS + #endif diff --git a/include/maxscale/gw_authenticator.h b/include/maxscale/gw_authenticator.h index 5e999fb02..a78523ff3 100644 --- a/include/maxscale/gw_authenticator.h +++ b/include/maxscale/gw_authenticator.h @@ -1,5 +1,6 @@ -#ifndef GW_AUTHENTICATOR_H -#define GW_AUTHENTICATOR_H +#pragma once +#ifndef _MAXSCALE_GW_AUTHENTICATOR_H +#define _MAXSCALE_GW_AUTHENTICATOR_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -14,7 +15,7 @@ */ /** - * @file protocol.h + * @file gw_authenticator.h * * The authenticator module interface definitions for MaxScale * @@ -27,12 +28,15 @@ * @endverbatim */ +#include #include #include #include #include #include +MXS_BEGIN_DECLS + /** Maximum number of authenticator options */ #define AUTHENTICATOR_MAX_OPTIONS 256 @@ -134,5 +138,7 @@ typedef enum bool authenticator_init(void **instance, const char *authenticator, const char *options); char* get_default_authenticator(const char *protocol); +MXS_END_DECLS + #endif /* GW_AUTHENTICATOR_H */ diff --git a/include/maxscale/gw_protocol.h b/include/maxscale/gw_protocol.h index e2a3295da..aa5ad2abf 100644 --- a/include/maxscale/gw_protocol.h +++ b/include/maxscale/gw_protocol.h @@ -1,5 +1,6 @@ -#ifndef GW_PROTOCOL_H -#define GW_PROTOCOL_H +#pragma once +#ifndef _MAXSCALE_GW_PROTOCOL_H +#define _MAXSCALE_GW_PROTOCOL_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -28,8 +29,11 @@ * @endverbatim */ +#include #include +MXS_BEGIN_DECLS + struct dcb; struct server; struct session; @@ -81,6 +85,7 @@ typedef struct gw_protocol */ #define GWPROTOCOL_VERSION {1, 1, 0} +MXS_END_DECLS #endif /* GW_PROTOCOL_H */ diff --git a/include/maxscale/gw_ssl.h b/include/maxscale/gw_ssl.h index bfcc387cf..65ac9ca82 100644 --- a/include/maxscale/gw_ssl.h +++ b/include/maxscale/gw_ssl.h @@ -1,5 +1,6 @@ -#ifndef _GW_SSL_H -#define _GW_SSL_H +#pragma once +#ifndef _MAXSCALE_GW_SSL_H +#define _MAXSCALE_GW_SSL_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -27,12 +28,15 @@ * @endverbatim */ +#include #include #include #include #include #include +MXS_BEGIN_DECLS + struct dcb; typedef enum ssl_method_type @@ -78,4 +82,6 @@ bool ssl_required_by_dcb(struct dcb *dcb); bool ssl_required_but_not_negotiated(struct dcb *dcb); const char* ssl_method_type_to_string(ssl_method_type_t method_type); +MXS_END_DECLS + #endif /* _GW_SSL_H */ diff --git a/include/maxscale/gwbitmask.h b/include/maxscale/gwbitmask.h index 31ee13655..d5d041eea 100644 --- a/include/maxscale/gwbitmask.h +++ b/include/maxscale/gwbitmask.h @@ -1,5 +1,6 @@ -#ifndef _GWBITMASK_H -#define _GWBITMASK_H +#pragma once +#ifndef _MAXSCALE_GWBITMASK_H +#define _MAXSCALE_GWBITMASK_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,9 +14,6 @@ * Public License. */ -#include -#include - /** * @file gwbitmask.h An implementation of an arbitrarily long bitmask * @@ -29,6 +27,12 @@ * @endverbatim */ +#include +#include +#include + +MXS_BEGIN_DECLS + /* This number MUST an be exact multiple of 8 */ #define MXS_BITMASK_LENGTH (MXS_MAX_THREADS + 1) /**< Number of bits in the bitmask */ @@ -55,4 +59,6 @@ extern int bitmask_isallclear(GWBITMASK *); extern void bitmask_copy(GWBITMASK *, GWBITMASK *); extern char *bitmask_render_readable(GWBITMASK *); +MXS_END_DECLS + #endif diff --git a/include/maxscale/gwdirs.h.in b/include/maxscale/gwdirs.h.in index 14592698c..a782c30d2 100644 --- a/include/maxscale/gwdirs.h.in +++ b/include/maxscale/gwdirs.h.in @@ -1,5 +1,6 @@ -#ifndef _GW_DIRS_HG -#define _GW_DIRS_HG +#pragma once +#ifndef _MAXSCALE_GW_DIRS_HG +#define _MAXSCALE_GW_DIRS_HG /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -15,11 +16,12 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE 1 #endif + +#include #include #include -#include -EXTERN_C_BLOCK_BEGIN +MXS_BEGIN_DECLS /** * All of the following DEFAULT_* variables are defined in cmake/install_layout.cmake @@ -76,6 +78,6 @@ char* get_logdir(); char* get_langdir(); char* get_execdir(); -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/include/maxscale/hashtable.h b/include/maxscale/hashtable.h index 0b271d731..185b195ab 100644 --- a/include/maxscale/hashtable.h +++ b/include/maxscale/hashtable.h @@ -1,5 +1,6 @@ -#ifndef _HASTABLE_H -#define _HASTABLE_H +#pragma once +#ifndef _MAXSCALE_HASTABLE_H +#define _MAXSCALE_HASTABLE_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -28,10 +29,11 @@ * * @endverbatim */ -#include +#include +#include #include -EXTERN_C_BLOCK_BEGIN +MXS_BEGIN_DECLS /** * The entries within a hashtable. @@ -150,6 +152,6 @@ extern int hashtable_item_strcmp(const void* str1, const void* str2); extern void* hashtable_item_strdup(const void *str); extern int hashtable_item_strhash(const void *str); -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/include/maxscale/hint.h b/include/maxscale/hint.h index ea073292f..d1943b900 100644 --- a/include/maxscale/hint.h +++ b/include/maxscale/hint.h @@ -1,5 +1,6 @@ -#ifndef _HINT_H -#define _HINT_H +#pragma once +#ifndef _MAXSCALE_HINT_H +#define _MAXSCALE_HINT_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -25,8 +26,10 @@ * @endverbatim */ -#include +#include +#include +MXS_BEGIN_DECLS /** * The types of hint that are supported by the generic hinting mechanism. @@ -63,4 +66,7 @@ extern HINT *hint_create_route(HINT *, HINT_TYPE, char *); extern void hint_free(HINT *); extern HINT *hint_dup(HINT *); bool hint_exists(HINT **, HINT_TYPE); + +MXS_END_DECLS + #endif diff --git a/include/maxscale/hk_heartbeat.h b/include/maxscale/hk_heartbeat.h index ab9172074..bdc2567ef 100644 --- a/include/maxscale/hk_heartbeat.h +++ b/include/maxscale/hk_heartbeat.h @@ -1,5 +1,6 @@ -#ifndef _HK_HEARTBEAT_H -#define _HK_HEARTBEAT_H +#pragma once +#ifndef _MAXSCALE_HK_HEARTBEAT_H +#define _MAXSCALE_HK_HEARTBEAT_H /* * Copyright (c) 2016 MariaDB Corporation Ab @@ -14,6 +15,10 @@ * Public License. */ +#include + +MXS_BEGIN_DECLS + /** * The global housekeeper heartbeat value. This value is incremented * every 100 milliseconds and may be used for crude timing etc. @@ -21,4 +26,6 @@ extern long hkheartbeat; +MXS_END_DECLS + #endif diff --git a/include/maxscale/housekeeper.h b/include/maxscale/housekeeper.h index 6f0bea8db..131a0fbae 100644 --- a/include/maxscale/housekeeper.h +++ b/include/maxscale/housekeeper.h @@ -1,5 +1,6 @@ -#ifndef _HOUSEKEEPER_H -#define _HOUSEKEEPER_H +#pragma once +#ifndef _MAXSCALE_HOUSEKEEPER_H +#define _MAXSCALE_HOUSEKEEPER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -12,9 +13,14 @@ * of this software will be governed by version 2 or later of the General * Public License. */ + +#include #include #include #include + +MXS_BEGIN_DECLS + /** * @file housekeeper.h A mechanism to have task run periodically * @@ -54,4 +60,6 @@ extern int hktask_remove(const char *name); extern void hkshutdown(); extern void hkshow_tasks(DCB *pdcb); +MXS_END_DECLS + #endif diff --git a/include/maxscale/limits.h b/include/maxscale/limits.h index 083a255dc..6847683d9 100644 --- a/include/maxscale/limits.h +++ b/include/maxscale/limits.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MAXSCALE_LIMITS_H #define _MAXSCALE_LIMITS_H /* @@ -13,6 +14,10 @@ * Public License. */ +#include + +MXS_BEGIN_DECLS + // This file defines hard limits of MaxScale. // Thread information is stored in a bitmask whose size must be a @@ -21,4 +26,6 @@ // multiple of 8 minus 1. #define MXS_MAX_THREADS 255 +MXS_END_DECLS + #endif diff --git a/include/maxscale/listener.h b/include/maxscale/listener.h index b2a2dbde5..0e8cb6097 100644 --- a/include/maxscale/listener.h +++ b/include/maxscale/listener.h @@ -1,5 +1,6 @@ -#ifndef _LISTENER_H -#define _LISTENER_H +#pragma once +#ifndef _MAXSCALE_LISTENER_H +#define _MAXSCALE_LISTENER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -27,10 +28,13 @@ * @endverbatim */ +#include #include #include #include +MXS_BEGIN_DECLS + struct dcb; struct service; @@ -65,4 +69,6 @@ int listener_set_ssl_version(SSL_LISTENER *ssl_listener, char* version); void listener_set_certificates(SSL_LISTENER *ssl_listener, char* cert, char* key, char* ca_cert); int listener_init_SSL(SSL_LISTENER *ssl_listener); +MXS_END_DECLS + #endif diff --git a/include/maxscale/listmanager.h b/include/maxscale/listmanager.h index 5afd28375..b35733847 100644 --- a/include/maxscale/listmanager.h +++ b/include/maxscale/listmanager.h @@ -1,5 +1,6 @@ -#ifndef _LISTMANAGER_H -#define _LISTMANAGER_H +#pragma once +#ifndef _MAXSCALE_LISTMANAGER_H +#define _MAXSCALE_LISTMANAGER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -26,8 +27,11 @@ * @endverbatim */ +#include #include -#include +#include + +MXS_BEGIN_DECLS struct dcb; @@ -115,5 +119,6 @@ void list_map(LIST_CONFIG *list_config, bool (*callback)(void *, ...)); list_entry_t *list_remove_first(LIST_CONFIG *list_config); list_entry_t *list_remove_last(LIST_CONFIG *list_config); +MXS_END_DECLS #endif /* LISTMANAGER_H */ diff --git a/include/maxscale/log_manager.h b/include/maxscale/log_manager.h index 127d3e985..e47d37509 100644 --- a/include/maxscale/log_manager.h +++ b/include/maxscale/log_manager.h @@ -1,3 +1,6 @@ +#pragma once +#ifndef _MAXSCALE_LOG_MANAGER_H +#define _MAXSCALE_LOG_MANAGER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -10,23 +13,13 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#if !defined(LOG_MANAGER_H) -#define LOG_MANAGER_H +#include #include #include #include -#if defined(__cplusplus) -extern "C" { -#endif - -/* - * We need a common.h file that is included by every component. - */ -#if !defined(STRERROR_BUFLEN) -#define STRERROR_BUFLEN 512 -#endif +MXS_BEGIN_DECLS /** * If MXS_MODULE_NAME is defined before log_manager.h is included, then all @@ -195,8 +188,6 @@ enum trailing NULL. If longer, it will be cut. */ }; -#if defined(__cplusplus) -} -#endif +MXS_END_DECLS #endif /** LOG_MANAGER_H */ diff --git a/include/maxscale/maxadmin.h b/include/maxscale/maxadmin.h index bef05a20d..8eb577b6d 100644 --- a/include/maxscale/maxadmin.h +++ b/include/maxscale/maxadmin.h @@ -1,5 +1,6 @@ -#ifndef _MAXADMIN_H -#define _MAXADMIN_H +#pragma once +#ifndef _MAXSCALE_MAXADMIN_H +#define _MAXSCALE_MAXADMIN_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,6 +14,10 @@ * Public License. */ +#include + +MXS_BEGIN_DECLS + #define MAXADMIN_DEFAULT_SOCKET "/tmp/maxadmin.sock" #define MAXADMIN_CONFIG_DEFAULT_SOCKET_TAG_LEN 7 @@ -28,4 +33,6 @@ #define MAXADMIN_AUTH_PASSWORD_PROMPT "PASSWORD" #define MAXADMIN_AUTH_PASSWORD_PROMPT_LEN 8 +MXS_END_DECLS + #endif diff --git a/include/maxscale/maxscale.h b/include/maxscale/maxscale.h index 020e858d0..5263409cf 100644 --- a/include/maxscale/maxscale.h +++ b/include/maxscale/maxscale.h @@ -1,5 +1,6 @@ -#ifndef _MAXSCALE_H -#define _MAXSCALE_H +#pragma once +#ifndef _MAXSCALE_MAXSCALE_H +#define _MAXSCALE_MAXSCALE_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -27,8 +28,10 @@ * @endverbatim */ +#include #include +MXS_BEGIN_DECLS /* Exit status for MaxScale */ #define MAXSCALE_SHUTDOWN 0 /* Good shutdown */ @@ -43,4 +46,6 @@ void maxscale_reset_starttime(void); time_t maxscale_started(void); int maxscale_uptime(void); +MXS_END_DECLS + #endif diff --git a/include/maxscale/memlog.h b/include/maxscale/memlog.h index ef832b673..5c6fdfa6c 100644 --- a/include/maxscale/memlog.h +++ b/include/maxscale/memlog.h @@ -1,5 +1,6 @@ -#ifndef _MEMLOG_H -#define _MEMLOG_H +#pragma once +#ifndef _MAXSCALE_MEMLOG_H +#define _MAXSCALE_MEMLOG_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -24,8 +25,12 @@ * * @endverbatim */ + +#include #include +MXS_BEGIN_DECLS + typedef enum { ML_INT, ML_LONG, ML_LONGLONG, ML_STRING } MEMLOGTYPE; typedef struct memlog @@ -59,4 +64,6 @@ extern void memlog_log(MEMLOG *, void *); extern void memlog_flush_all(); extern void memlog_flush(MEMLOG *); +MXS_END_DECLS + #endif diff --git a/include/maxscale/modinfo.h b/include/maxscale/modinfo.h index 686ac9d45..99d68a37f 100644 --- a/include/maxscale/modinfo.h +++ b/include/maxscale/modinfo.h @@ -1,5 +1,6 @@ -#ifndef _MODINFO_H -#define _MODINFO_H +#pragma once +#ifndef _MAXSCALE_MODINFO_H +#define _MAXSCALE_MODINFO_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -25,6 +26,10 @@ * @endverbatim */ +#include + +MXS_BEGIN_DECLS + /** * The status of the module. This gives some idea of the module * maturity. @@ -83,4 +88,7 @@ typedef struct MODULE_VERSION api_version; char *description; } MODULE_INFO; + +MXS_END_DECLS + #endif diff --git a/include/maxscale/modules.h b/include/maxscale/modules.h index 49abc562c..eb21810c9 100644 --- a/include/maxscale/modules.h +++ b/include/maxscale/modules.h @@ -1,5 +1,6 @@ -#ifndef _MODULES_H -#define _MODULES_H +#pragma once +#ifndef _MAXSCALE_MODULES_H +#define _MAXSCALE_MODULES_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -12,12 +13,6 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#include -#include -#include -#include - -EXTERN_C_BLOCK_BEGIN /** * @file modules.h Utilities for loading modules @@ -38,6 +33,14 @@ EXTERN_C_BLOCK_BEGIN * @endverbatim */ +#include +#include +#include +#include +#include + +MXS_BEGIN_DECLS + typedef struct modules { char *module; /**< The name of the module */ @@ -71,6 +74,6 @@ extern RESULTSET *moduleGetList(); extern void module_feedback_send(void*); extern void moduleShowFeedbackReport(DCB *dcb); -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/include/maxscale/modutil.h b/include/maxscale/modutil.h index 9ccc38345..9f609f795 100644 --- a/include/maxscale/modutil.h +++ b/include/maxscale/modutil.h @@ -1,5 +1,6 @@ -#ifndef _MODUTIL_H -#define _MODUTIL_H +#pragma once +#ifndef _MAXSCALE_MODUTIL_H +#define _MAXSCALE_MODUTIL_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -26,11 +27,15 @@ * * @endverbatim */ + +#include #include #include #include #include +MXS_BEGIN_DECLS + #define PTR_IS_RESULTSET(b) (b[0] == 0x01 && b[1] == 0x0 && b[2] == 0x0 && b[3] == 0x01) #define PTR_IS_EOF(b) (b[0] == 0x05 && b[1] == 0x0 && b[2] == 0x0 && b[4] == 0xfe) #define PTR_IS_OK(b) (b[4] == 0x00) @@ -70,4 +75,6 @@ bool is_mysql_statement_end(const char* start, int len); bool is_mysql_sp_end(const char* start, int len); char* modutil_get_canonical(GWBUF* querybuf); +MXS_END_DECLS + #endif diff --git a/include/maxscale/monitor.h b/include/maxscale/monitor.h index a5dac0abb..9d0b9269b 100644 --- a/include/maxscale/monitor.h +++ b/include/maxscale/monitor.h @@ -1,5 +1,6 @@ -#ifndef _MONITOR_H -#define _MONITOR_H +#pragma once +#ifndef _MAXSCALE_MONITOR_H +#define _MAXSCALE_MONITOR_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -12,14 +13,6 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#include -#include -#include -#include -#include -#include -#include -#include /** * @file monitor.h The interface to the monitor module @@ -43,6 +36,18 @@ * @endverbatim */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MXS_BEGIN_DECLS + /** * The "Module Object" for a monitor module. * @@ -226,4 +231,6 @@ connect_result_t mon_connect_to_db(MONITOR* mon, MONITOR_SERVERS *database); void mon_log_connect_error(MONITOR_SERVERS* database, connect_result_t rval); void mon_log_state_change(MONITOR_SERVERS *ptr); +MXS_END_DECLS + #endif diff --git a/include/maxscale/mysql_binlog.h b/include/maxscale/mysql_binlog.h index 62b981d64..2e7f4c5de 100644 --- a/include/maxscale/mysql_binlog.h +++ b/include/maxscale/mysql_binlog.h @@ -1,5 +1,6 @@ -#ifndef MYSQL_BINLOG_H -#define MYSQL_BINLOG_H +#pragma once +#ifndef _MAXSCALE_MYSQL_BINLOG_H +#define _MAXSCALE_MYSQL_BINLOG_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -17,10 +18,13 @@ * @file mysql_binlog.h - Extracting information from binary logs */ +#include #include #include #include +MXS_BEGIN_DECLS + /** Maximum GTID string length */ #define GTID_MAX_LEN 64 @@ -91,4 +95,6 @@ uint64_t unpack_bit(uint8_t *ptr, uint8_t *null_mask, uint32_t col_count, void format_temporal_value(char *str, size_t size, uint8_t type, struct tm *tm); +MXS_END_DECLS + #endif /* MYSQL_BINLOG_H */ diff --git a/include/maxscale/mysql_utils.h b/include/maxscale/mysql_utils.h index 329dfd6f8..f5b4d79ce 100644 --- a/include/maxscale/mysql_utils.h +++ b/include/maxscale/mysql_utils.h @@ -1,5 +1,6 @@ -#ifndef _MYSQL_UTILS_H -#define _MYSQL_UTILS_H +#pragma once +#ifndef _MAXSCALE_MYSQL_UTILS_H +#define _MAXSCALE_MYSQL_UTILS_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,11 +14,14 @@ * Public License. */ +#include #include #include #include #include +MXS_BEGIN_DECLS + /** Length-encoded integers */ size_t leint_bytes(uint8_t* ptr); uint64_t leint_value(uint8_t* c); @@ -27,7 +31,8 @@ uint64_t leint_consume(uint8_t ** c); char* lestr_consume_dup(uint8_t** c); char* lestr_consume(uint8_t** c, size_t *size); - MYSQL *mxs_mysql_real_connect(MYSQL *mysql, SERVER *server, const char *user, const char *passwd); +MXS_END_DECLS + #endif diff --git a/include/maxscale/notification.h b/include/maxscale/notification.h index 1014f84a1..db410910f 100644 --- a/include/maxscale/notification.h +++ b/include/maxscale/notification.h @@ -1,5 +1,6 @@ -#ifndef _NOTIFICATION_SERVICE_H -#define _NOTIFICATION_SERVICE_H +#pragma once +#ifndef _MAXSCALE_NOTIFICATION_H +#define _MAXSCALE_NOTIFICATION_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -27,6 +28,10 @@ * @endverbatim */ +#include + +MXS_BEGIN_DECLS + #define _NOTIFICATION_CONNECT_TIMEOUT 30 #define _NOTIFICATION_OPERATION_TIMEOUT 30 #define _NOTIFICATION_SEND_PENDING 0 @@ -57,4 +62,7 @@ typedef struct extern char *gw_bin2hex(char *out, const uint8_t *in, unsigned int len); extern void gw_sha1_str(const uint8_t *in, int in_len, uint8_t *out); extern FEEDBACK_CONF * config_get_feedback_data(); + +MXS_END_DECLS + #endif diff --git a/include/maxscale/pcre2.h b/include/maxscale/pcre2.h index 08c8e2b58..e2373cca4 100644 --- a/include/maxscale/pcre2.h +++ b/include/maxscale/pcre2.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MAXSCALE_PCRE2_H #define _MAXSCALE_PCRE2_H /* @@ -14,12 +15,6 @@ * */ -#ifndef PCRE2_CODE_UNIT_WIDTH -#define PCRE2_CODE_UNIT_WIDTH 8 -#endif - -#include - /** * @file pcre2.h - Utility functions for regular expression matching * with the bundled PCRE2 library. @@ -32,6 +27,16 @@ * @endverbatim */ +#include + +#ifndef PCRE2_CODE_UNIT_WIDTH +#define PCRE2_CODE_UNIT_WIDTH 8 +#endif + +#include + +MXS_BEGIN_DECLS + typedef enum { MXS_PCRE2_MATCH, @@ -44,4 +49,6 @@ mxs_pcre2_result_t mxs_pcre2_substitute(pcre2_code *re, const char *subject, mxs_pcre2_result_t mxs_pcre2_simple_match(const char* pattern, const char* subject, int options, int* error); +MXS_END_DECLS + #endif diff --git a/include/maxscale/platform.h b/include/maxscale/platform.h index 69011f3d4..486898d0b 100644 --- a/include/maxscale/platform.h +++ b/include/maxscale/platform.h @@ -1,5 +1,6 @@ -#ifndef _PLATFORM_H -#define _PLATFORM_H +#pragma once +#ifndef _MAXSCALE_PLATFORM_H +#define _MAXSCALE_PLATFORM_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,6 +14,10 @@ * Public License. */ +#include + +MXS_BEGIN_DECLS + #if !defined(__cplusplus) #if __STDC_VERSION__ >= 201112 @@ -48,4 +53,6 @@ #endif // __cplusplus +MXS_END_DECLS + #endif // _PLATFORM_H diff --git a/include/maxscale/poll.h b/include/maxscale/poll.h index 2e9a1ec20..ab0e6e385 100644 --- a/include/maxscale/poll.h +++ b/include/maxscale/poll.h @@ -1,5 +1,6 @@ -#ifndef _POLL_H -#define _POLL_H +#pragma once +#ifndef _MAXSCALE_POLL_H +#define _MAXSCALE_POLL_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -12,10 +13,6 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#include -#include -#include -#include /** * @file poll.h The poll related functionality @@ -29,6 +26,15 @@ * * @endverbatim */ + +#include +#include +#include +#include +#include + +MXS_BEGIN_DECLS + #define MAX_EVENTS 1000 /** @@ -67,4 +73,7 @@ extern void poll_fake_event(DCB *dcb, enum EPOLL_EVENTS ev); extern void poll_fake_hangup_event(DCB *dcb); extern void poll_fake_write_event(DCB *dcb); extern void poll_fake_read_event(DCB *dcb); + +MXS_END_DECLS + #endif diff --git a/include/maxscale/protocol/mysql.h b/include/maxscale/protocol/mysql.h index f19230e89..568e520c1 100644 --- a/include/maxscale/protocol/mysql.h +++ b/include/maxscale/protocol/mysql.h @@ -36,6 +36,7 @@ * */ +#include #include #include #include @@ -65,6 +66,8 @@ #include #include +MXS_BEGIN_DECLS + #define GW_MYSQL_VERSION "5.5.5-10.0.0 " MAXSCALE_VERSION "-maxscale" #define GW_MYSQL_LOOP_TIMEOUT 300000000 #define GW_MYSQL_READ 0 @@ -373,4 +376,6 @@ int mxs_mysql_send_ok(DCB *dcb, int sequence, int affected_rows, const char* mes /** Check for OK packet */ bool mxs_mysql_is_ok_packet(GWBUF *buffer); +MXS_END_DECLS + #endif /** _MYSQL_PROTOCOL_H */ diff --git a/include/maxscale/query_classifier.h b/include/maxscale/query_classifier.h index dbbc01fcb..f53b6a1ca 100644 --- a/include/maxscale/query_classifier.h +++ b/include/maxscale/query_classifier.h @@ -1,5 +1,6 @@ -#ifndef QUERY_CLASSIFIER_HG -#define QUERY_CLASSIFIER_HG +#pragma once +#ifndef _MAXSCALE_QUERY_CLASSIFIER_HG +#define _MAXSCALE_QUERY_CLASSIFIER_HG /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,10 +14,10 @@ * Public License. */ -#include +#include #include -EXTERN_C_BLOCK_BEGIN +MXS_BEGIN_DECLS typedef enum { @@ -130,6 +131,6 @@ struct query_classifier #define QUERY_CLASSIFIER_VERSION {1, 0, 0} -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/include/maxscale/queuemanager.h b/include/maxscale/queuemanager.h index 462dd10e4..15f9ac39f 100644 --- a/include/maxscale/queuemanager.h +++ b/include/maxscale/queuemanager.h @@ -1,5 +1,6 @@ -#ifndef _QUEUEMANAGER_H -#define _QUEUEMANAGER_H +#pragma once +#ifndef _MAXSCALE_QUEUEMANAGER_H +#define _MAXSCALE_QUEUEMANAGER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -26,9 +27,12 @@ * @endverbatim */ +#include #include #include +MXS_BEGIN_DECLS + #define CONNECTION_QUEUE_LIMIT 1000 typedef struct queue_entry @@ -67,4 +71,6 @@ mxs_queue_count(QUEUE_CONFIG *queue_config) return count < 0 ? (count + queue_config->queue_limit + 1): count; } +MXS_END_DECLS + #endif /* QUEUEMANAGER_H */ diff --git a/include/maxscale/random_jkiss.h b/include/maxscale/random_jkiss.h index baf9be28a..c1041ea8f 100644 --- a/include/maxscale/random_jkiss.h +++ b/include/maxscale/random_jkiss.h @@ -1,5 +1,6 @@ -#ifndef RANDOM_JKISS_H -#define RANDOM_JKISS_H +#pragma once +#ifndef _MAXSCALE_RANDOM_JKISS_H +#define _MAXSCALE_RANDOM_JKISS_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -20,14 +21,12 @@ * Created on 26 August 2015, 15:34 */ -#ifdef __cplusplus -extern "C" { -#endif +#include + +MXS_BEGIN_DECLS extern unsigned int random_jkiss(void); -#ifdef __cplusplus -} -#endif +MXS_END_DECLS #endif /* RANDOM_H */ diff --git a/include/maxscale/rdtsc.h b/include/maxscale/rdtsc.h index 213d73b7f..f928fd85b 100644 --- a/include/maxscale/rdtsc.h +++ b/include/maxscale/rdtsc.h @@ -1,5 +1,6 @@ -#ifndef _RDTSC_H -#define _RDTSC_H +#pragma once +#ifndef _MAXSCALE_RDTSC_H +#define _MAXSCALE_RDTSC_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -31,6 +32,10 @@ * @endverbatim */ +#include + +MXS_BEGIN_DECLS + typedef unsigned long long CYCLES; /** @@ -53,4 +58,7 @@ static __inline__ CYCLES rdtsc(void) __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } + +MXS_END_DECLS + #endif diff --git a/include/maxscale/resultset.h b/include/maxscale/resultset.h index 58b4f7a35..90e9c8042 100644 --- a/include/maxscale/resultset.h +++ b/include/maxscale/resultset.h @@ -1,5 +1,6 @@ -#ifndef _RESULTSET_H -#define _RESULTSET_H +#pragma once +#ifndef _MAXSCALE_RESULTSET_H +#define _MAXSCALE_RESULTSET_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -24,8 +25,11 @@ * * @endverbatim */ + +#include #include +MXS_BEGIN_DECLS /** * Column types @@ -85,4 +89,6 @@ extern int resultset_row_set(RESULT_ROW *, int, const char *); extern void resultset_stream_mysql(RESULTSET *, DCB *); extern void resultset_stream_json(RESULTSET *, DCB *); +MXS_END_DECLS + #endif diff --git a/include/maxscale/router.h b/include/maxscale/router.h index 9dafcc9aa..9172074b4 100644 --- a/include/maxscale/router.h +++ b/include/maxscale/router.h @@ -1,5 +1,6 @@ -#ifndef _ROUTER_H -#define _ROUTER_H +#pragma once +#ifndef _MAXSCALE_ROUTER_H +#define _MAXSCALE_ROUTER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -27,11 +28,15 @@ * 27/10/2015 Martin Brampton Add RCAP_TYPE_NO_RSESSION * */ + +#include #include #include #include #include +MXS_BEGIN_DECLS + /** * The ROUTER handle points to module specific data, so the best we can do * is to make it a void * externally. @@ -100,6 +105,6 @@ typedef enum router_capability_t users when the service is started */ } router_capability_t; - +MXS_END_DECLS #endif diff --git a/include/maxscale/secrets.h b/include/maxscale/secrets.h index 09286c00b..257718c6a 100644 --- a/include/maxscale/secrets.h +++ b/include/maxscale/secrets.h @@ -1,5 +1,6 @@ -#ifndef _SECRETS_H -#define _SECRETS_H +#pragma once +#ifndef _MAXSCALE_SECRETS_H +#define _MAXSCALE_SECRETS_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -25,6 +26,7 @@ * @endverbatim */ +#include #include #include #include @@ -32,9 +34,10 @@ #include #include #include - #include +MXS_BEGIN_DECLS + #define MAXSCALE_KEYLEN 32 #define MAXSCALE_IV_LEN 16 @@ -56,4 +59,6 @@ extern int secrets_writeKeys(const char *directory); extern char *decryptPassword(const char *); extern char *encryptPassword(const char*, const char *); +MXS_END_DECLS + #endif diff --git a/include/maxscale/server.h b/include/maxscale/server.h index 3daaa10dd..f06167568 100644 --- a/include/maxscale/server.h +++ b/include/maxscale/server.h @@ -1,5 +1,6 @@ -#ifndef _SERVER_H -#define _SERVER_H +#pragma once +#ifndef _MAXSCALE_SERVER_H +#define _MAXSCALE_SERVER_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -12,8 +13,6 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#include -#include /** * @file service.h @@ -44,6 +43,12 @@ * @endverbatim */ +#include +#include +#include + +MXS_BEGIN_DECLS + #define MAX_SERVER_NAME_LEN 1024 #define MAX_NUM_SLAVES 128 /**< Maximum number of slaves under a single server*/ @@ -222,4 +227,6 @@ extern RESULTSET *serverGetList(); extern unsigned int server_map_status(char *str); extern bool server_set_version_string(SERVER* server, const char* string); +MXS_END_DECLS + #endif diff --git a/include/maxscale/service.h b/include/maxscale/service.h index eae46c1a7..fa401628d 100644 --- a/include/maxscale/service.h +++ b/include/maxscale/service.h @@ -1,5 +1,6 @@ -#ifndef _SERVICE_H -#define _SERVICE_H +#pragma once +#ifndef _MAXSCALE_SERVICE_H +#define _MAXSCALE_SERVICE_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,21 +14,6 @@ * Public License. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /** * @file service.h * @@ -53,6 +39,26 @@ * * @endverbatim */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MXS_BEGIN_DECLS + struct server; struct router; struct router_object; @@ -222,4 +228,6 @@ extern RESULTSET *serviceGetList(); extern RESULTSET *serviceGetListenerList(); extern bool service_all_services_have_listeners(); +MXS_END_DECLS + #endif diff --git a/include/maxscale/session.h b/include/maxscale/session.h index 87497ad31..c688e6149 100644 --- a/include/maxscale/session.h +++ b/include/maxscale/session.h @@ -1,5 +1,6 @@ -#ifndef _SESSION_H -#define _SESSION_H +#pragma once +#ifndef _MAXSCALE_SESSION_H +#define _MAXSCALE_SESSION_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -33,15 +34,18 @@ * * @endverbatim */ + +#include #include #include #include #include #include #include -#include #include +MXS_BEGIN_DECLS + struct dcb; struct service; struct filter_def; @@ -201,4 +205,7 @@ void session_disable_log_priority(SESSION* ses, int priority); RESULTSET *sessionGetList(SESSIONLISTFILTER); void process_idle_sessions(); void enable_session_timeouts(); + +MXS_END_DECLS + #endif diff --git a/include/maxscale/skygw_types.h b/include/maxscale/skygw_types.h deleted file mode 100644 index 0c8247eeb..000000000 --- a/include/maxscale/skygw_types.h +++ /dev/null @@ -1,47 +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. - */ - -#if !defined(SKYGW_TYPES_H) -#define SKYGW_TYPES_H - -#include -#include -#include - -#define SECOND_USEC (1024*1024L) -#define MSEC_USEC (1024L) - -#define KILOBYTE_BYTE (1024L) -#define MEGABYTE_BYTE (1024*1024L) -#define GIGABYTE_BYTE (1024*1024*1024L) - -#define KB KILOBYTE_BYTE -#define MB MEGABYTE_BYTE -#define GB GIGABYTE_BYTE - -#define CALCLEN(i) ((size_t)(floor(log10(abs(i))) + 1)) - -#define UINTLEN(i) (i<10 ? 1 : (i<100 ? 2 : (i<1000 ? 3 : CALCLEN(i)))) - -#if !defined(PATH_MAX) -# if defined(__USE_POSIX) -# define PATH_MAX _POSIX_PATH_MAX -# else -# define PATH_MAX 256 -# endif -#endif - -#define MAX_ERROR_MSG PATH_MAX -#define array_nelems(a) ((uint)(sizeof(a)/sizeof(a[0]))) - -#endif /* SKYGW_TYPES_H */ diff --git a/include/maxscale/skygw_utils.h b/include/maxscale/skygw_utils.h index a903466c3..e21a41afa 100644 --- a/include/maxscale/skygw_utils.h +++ b/include/maxscale/skygw_utils.h @@ -1,5 +1,6 @@ -#ifndef _SKYGW_UTILS_H -#define _SKYGW_UTILS_H +#pragma once +#ifndef _MAXSCALE_SKYGW_UTILS_H +#define _MAXSCALE_SKYGW_UTILS_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,23 +14,13 @@ * Public License. */ -/* - * We need a common.h file that is included by every component. - */ -#if !defined(STRERROR_BUFLEN) -#define STRERROR_BUFLEN 512 -#endif +#include + +MXS_BEGIN_DECLS -#ifndef MIN -#define MIN(a,b) (ab ? a : b) -#endif #define FSYNCLIMIT 10 -#include -#include +#include #define DISKWRITE_LATENCY (5*MSEC_USEC) @@ -105,13 +96,9 @@ struct skygw_file_st skygw_chk_t sf_chk_tail; }; -EXTERN_C_BLOCK_BEGIN - bool utils_init(); /*< Call this first before using any other function */ void utils_end(); -EXTERN_C_BLOCK_END - /** Skygw thread routines */ skygw_thread_t* skygw_thread_init(const char* name, void* (*sth_thrfun)(void* data), @@ -126,8 +113,6 @@ size_t get_timestamp_len_hp(void); size_t snprint_timestamp(char* p_ts, size_t tslen); size_t snprint_timestamp_hp(char* p_ts, size_t tslen); -EXTERN_C_BLOCK_BEGIN - void skygw_thread_set_state(skygw_thread_t* thr, skygw_thr_state_t state); void* skygw_thread_get_data(skygw_thread_t* thr); @@ -136,8 +121,6 @@ bool skygw_thread_set_exitflag(skygw_thread_t* thr, skygw_message_t* sendmes, skygw_message_t* recmes); -EXTERN_C_BLOCK_END - /** Skygw thread routines */ /** Skygw file routines */ @@ -159,8 +142,6 @@ int skygw_file_write(skygw_file_t* file, bool flush); /** Skygw file routines */ -EXTERN_C_BLOCK_BEGIN - void acquire_lock(int* l); void release_lock(int* l); @@ -179,15 +160,11 @@ void skygw_message_reset(skygw_message_t* mes); /** Skygw message routines */ -EXTERN_C_BLOCK_END - int skygw_rwlock_wrlock(skygw_rwlock_t* rwlock); int skygw_rwlock_rdlock(skygw_rwlock_t* rwlock); int skygw_rwlock_unlock(skygw_rwlock_t* rwlock); int skygw_rwlock_init(skygw_rwlock_t** rwlock); -EXTERN_C_BLOCK_BEGIN - size_t get_decimal_len(size_t s); char* remove_mysql_comments(const char** src, const size_t* srcsize, char** dest, @@ -203,6 +180,6 @@ bool strip_escape_chars(char*); char* trim(char *str); char* squeeze_whitespace(char* str); -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif /* SKYGW_UTILS_H */ diff --git a/include/maxscale/slist.h b/include/maxscale/slist.h deleted file mode 100644 index 725023b6d..000000000 --- a/include/maxscale/slist.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef _SLIST_H -#define _SLIST_H -/* - * 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 - -EXTERN_C_BLOCK_BEGIN - -typedef struct slist_node_st slist_node_t; -typedef struct slist_st slist_t; -typedef struct slist_cursor_st slist_cursor_t; - -/** Single-linked list */ - -struct slist_node_st -{ - skygw_chk_t slnode_chk_top; - slist_t* slnode_list; - slist_node_t* slnode_next; - void* slnode_data; - size_t slnode_cursor_refcount; - skygw_chk_t slnode_chk_tail; -}; - -struct slist_st -{ - skygw_chk_t slist_chk_top; - slist_node_t* slist_head; - slist_node_t* slist_tail; - int slist_nelems; - slist_t* slist_cursors_list; - skygw_chk_t slist_chk_tail; -}; - -struct slist_cursor_st -{ - skygw_chk_t slcursor_chk_top; - slist_t* slcursor_list; - slist_node_t* slcursor_pos; - skygw_chk_t slcursor_chk_tail; -}; - -slist_cursor_t* slist_init(void); -void slist_done(slist_cursor_t* c); -size_t slist_size(slist_cursor_t* c); - -void slcursor_add_data(slist_cursor_t* c, void* data); -void* slcursor_get_data(slist_cursor_t* c); -void slcursor_remove_data(slist_cursor_t* c); -bool slcursor_move_to_begin(slist_cursor_t* c); -bool slcursor_step_ahead(slist_cursor_t* c); - -EXTERN_C_BLOCK_END - -#endif diff --git a/include/maxscale/spinlock.h b/include/maxscale/spinlock.h index 7df6064b7..72650f268 100644 --- a/include/maxscale/spinlock.h +++ b/include/maxscale/spinlock.h @@ -1,5 +1,6 @@ -#ifndef _SPINLOCK_H -#define _SPINLOCK_H +#pragma once +#ifndef _MAXSCALE_SPINLOCK_H +#define _MAXSCALE_SPINLOCK_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -23,9 +24,11 @@ * for the lock to be released. However they are useful in that they do not involve * system calls and are light weight when the expected wait time for a lock is low. */ -#include -EXTERN_C_BLOCK_BEGIN +#include +#include + +MXS_BEGIN_DECLS #define SPINLOCK_PROFILE 0 @@ -74,6 +77,6 @@ extern int spinlock_acquire_nowait(const SPINLOCK *lock); extern void spinlock_release(const SPINLOCK *lock); extern void spinlock_stats(const SPINLOCK *lock, void (*reporter)(void *, char *, int), void *hdl); -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/include/maxscale/statistics.h b/include/maxscale/statistics.h index 3ba4d2f30..ffb70e808 100644 --- a/include/maxscale/statistics.h +++ b/include/maxscale/statistics.h @@ -1,5 +1,6 @@ -#ifndef _STATISTICS_HG -#define _STATISTICS_HG +#pragma once +#ifndef _MAXSCALE_STATISTICS_HG +#define _MAXSCALE_STATISTICS_HG /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -25,8 +26,11 @@ * @endverbatim */ +#include #include +MXS_BEGIN_DECLS + typedef void* ts_stats_t; /** stats_init should be called only once */ @@ -68,4 +72,6 @@ ts_stats_set(ts_stats_t stats, int value, int thread_id) ((int64_t*)stats)[thread_id] = value; } +MXS_END_DECLS + #endif diff --git a/include/maxscale/thread.h b/include/maxscale/thread.h index 3defe9f90..d775cfec2 100644 --- a/include/maxscale/thread.h +++ b/include/maxscale/thread.h @@ -1,5 +1,6 @@ -#ifndef _THREAD_H -#define _THREAD_H +#pragma once +#ifndef _MAXSCALE_THREAD_H +#define _MAXSCALE_THREAD_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -22,6 +23,10 @@ * of changes. */ +#include + +MXS_BEGIN_DECLS + /** * Thread type and thread identifier function macros */ @@ -33,4 +38,6 @@ extern THREAD *thread_start(THREAD *thd, void (*entry)(void *), void *arg); extern void thread_wait(THREAD thd); extern void thread_millisleep(int ms); +MXS_END_DECLS + #endif diff --git a/include/maxscale/users.h b/include/maxscale/users.h index 78a4b3731..1d95016cd 100644 --- a/include/maxscale/users.h +++ b/include/maxscale/users.h @@ -1,5 +1,6 @@ -#ifndef _USERS_H -#define _USERS_H +#pragma once +#ifndef _MAXSCALE_USERS_H +#define _MAXSCALE_USERS_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -12,10 +13,6 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#include -#include -#include -#include /** * @file users.h The functions to manipulate the table of users maintained @@ -33,6 +30,14 @@ * @endverbatim */ +#include +#include +#include +#include +#include + +MXS_BEGIN_DECLS + #define USERS_HASHTABLE_DEFAULT_SIZE 52 /** @@ -70,4 +75,6 @@ extern int users_default_loadusers(SERV_LISTENER *port); /**< A generic implemen extern void usersPrint(USERS *); /**< Print data about the users loaded */ extern void dcb_usersPrint(DCB *, USERS *); /**< Print data about the users loaded */ +MXS_END_DECLS + #endif diff --git a/include/maxscale/utils.h b/include/maxscale/utils.h index 273f352ca..bca259700 100644 --- a/include/maxscale/utils.h +++ b/include/maxscale/utils.h @@ -1,5 +1,6 @@ -#ifndef _UTILS_H -#define _UTILS_H +#pragma once +#ifndef _MAXSCALE_UTILS_H +#define _MAXSCALE_UTILS_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -25,6 +26,17 @@ * @endverbatim */ +#include +#include +#include + +MXS_BEGIN_DECLS + +#define CALCLEN(i) ((size_t)(floor(log10(abs(i))) + 1)) +#define UINTLEN(i) (i<10 ? 1 : (i<100 ? 2 : (i<1000 ? 3 : CALCLEN(i)))) + +#define MXS_ARRAY_NELEMS(array) ((size_t)(sizeof(array)/sizeof(array[0]))) + int setnonblocking(int fd); char *gw_strend(register const char *s); static char gw_randomchar(); @@ -37,4 +49,6 @@ void gw_sha1_2_str(const uint8_t *in, int in_len, const uint8_t *in2, int in2_le int gw_getsockerrno(int fd); char *create_hex_sha1_sha1_passwd(char *passwd); +MXS_END_DECLS + #endif diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index 23dd508fc..9baaee794 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -55,8 +55,7 @@ #include #include -#include -#include +#include #include #include #include diff --git a/query_classifier/qc_sqlite/builtin_functions.c b/query_classifier/qc_sqlite/builtin_functions.c index 2cb2ed797..b719ef195 100644 --- a/query_classifier/qc_sqlite/builtin_functions.c +++ b/query_classifier/qc_sqlite/builtin_functions.c @@ -5,7 +5,7 @@ #include "builtin_functions.h" #include #include -#include +#include static struct { diff --git a/query_classifier/test/canonical_tests/canonizer.c b/query_classifier/test/canonical_tests/canonizer.c index 9dc4a5c49..fc95105e2 100644 --- a/query_classifier/test/canonical_tests/canonizer.c +++ b/query_classifier/test/canonical_tests/canonizer.c @@ -18,6 +18,7 @@ #include #include #include +#include int main(int argc, char** argv) { diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 06302df63..11a616a62 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 slist.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 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) 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/buffer.c b/server/core/buffer.c index 9d55aaff9..cf25bdb08 100644 --- a/server/core/buffer.c +++ b/server/core/buffer.c @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include @@ -121,7 +121,7 @@ gwbuf_alloc(unsigned int size) retblock: if (rval == NULL) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Memory allocation failed due to %s.", strerror_r(errno, errbuf, sizeof(errbuf))); } @@ -964,7 +964,7 @@ size_t gwbuf_copy_data(GWBUF *buffer, size_t offset, size_t bytes, uint8_t* dest if (buffer) { - bytes_left = MIN(GWBUF_LENGTH(buffer), bytes); + bytes_left = MXS_MIN(GWBUF_LENGTH(buffer), bytes); ptr = (uint8_t*) GWBUF_DATA(buffer); } } diff --git a/server/core/config.c b/server/core/config.c index e1cb5b747..7cda0ed0a 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -233,7 +233,7 @@ char* config_clean_string_list(char* str) PCRE2_ZERO_TERMINATED, 0, &re_err, &err_offset, NULL)) == NULL || (data = pcre2_match_data_create_from_pattern(re, NULL)) == NULL) { - PCRE2_UCHAR errbuf[STRERROR_BUFLEN]; + PCRE2_UCHAR errbuf[MXS_STRERROR_BUFLEN]; pcre2_get_error_message(re_err, errbuf, sizeof(errbuf)); MXS_ERROR("[%s] Regular expression compilation failed at %d: %s", __FUNCTION__, (int)err_offset, errbuf); @@ -2145,7 +2145,7 @@ bool config_has_duplicate_sections(const char* config) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to open file '%s': %s", config, strerror_r(errno, errbuf, sizeof(errbuf))); rval = true; diff --git a/server/core/dcb.c b/server/core/dcb.c index 27e324d37..acf811c7f 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -672,7 +672,7 @@ dcb_process_victim_queue(DCB *listofdcb) { int eno = errno; errno = 0; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("%lu [dcb_process_victim_queue] Error : Failed to close " "socket %d on dcb %p due error %d, %s.", pthread_self(), @@ -1003,7 +1003,7 @@ dcb_bytes_readable(DCB *dcb) if (-1 == ioctl(dcb->fd, FIONREAD, &bytesavailable)) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; /* */ MXS_ERROR("%lu [dcb_read] Error : ioctl FIONREAD for dcb %p in " "state %s fd %d failed due error %d, %s.", @@ -1069,10 +1069,10 @@ dcb_basic_read(DCB *dcb, int bytesavailable, int maxbytes, int nreadtotal, int * { GWBUF *buffer; - int bufsize = MIN(bytesavailable, MAX_BUFFER_SIZE); + int bufsize = MXS_MIN(bytesavailable, MAX_BUFFER_SIZE); if (maxbytes) { - bufsize = MIN(bufsize, maxbytes - nreadtotal); + bufsize = MXS_MIN(bufsize, maxbytes - nreadtotal); } if ((buffer = gwbuf_alloc(bufsize)) == NULL) @@ -1081,7 +1081,7 @@ dcb_basic_read(DCB *dcb, int bytesavailable, int maxbytes, int nreadtotal, int * * This is a fatal error which should cause shutdown. * Todo shutdown if memory allocation fails. */ - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; /* */ MXS_ERROR("%lu [dcb_read] Error : Failed to allocate read buffer " "for dcb %p fd %d, due %d, %s.", @@ -1102,7 +1102,7 @@ dcb_basic_read(DCB *dcb, int bytesavailable, int maxbytes, int nreadtotal, int * { if (errno != 0 && errno != EAGAIN && errno != EWOULDBLOCK) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; /* */ MXS_ERROR("%lu [dcb_read] Error : Read failed, dcb %p in state " "%s fd %d, due %d, %s.", @@ -1211,7 +1211,7 @@ dcb_basic_read_SSL(DCB *dcb, int *nsingleread) * This is a fatal error which should cause shutdown. * Todo shutdown if memory allocation fails. */ - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; /* */ MXS_ERROR("%lu [dcb_read] Error : Failed to allocate read buffer " "for dcb %p fd %d, due %d, %s.", @@ -1297,7 +1297,7 @@ dcb_basic_read_SSL(DCB *dcb, int *nsingleread) static int dcb_log_errors_SSL (DCB *dcb, const char *called_by, int ret) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; unsigned long ssl_errno; ssl_errno = ERR_get_error(); @@ -1327,7 +1327,7 @@ dcb_log_errors_SSL (DCB *dcb, const char *called_by, int ret) { while (ssl_errno != 0) { - ERR_error_string_n(ssl_errno, errbuf, STRERROR_BUFLEN); + ERR_error_string_n(ssl_errno, errbuf, MXS_STRERROR_BUFLEN); MXS_ERROR("%s", errbuf); ssl_errno = ERR_get_error(); } @@ -1475,7 +1475,7 @@ dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno) { if (eno == EPIPE) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_DEBUG("%lu [dcb_write] Write to dcb " "%p in state %s fd %d failed " "due errno %d, %s", @@ -1494,7 +1494,7 @@ dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno) eno != EAGAIN && eno != EWOULDBLOCK) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Write to dcb %p in " "state %s fd %d failed due " "errno %d, %s", @@ -1528,7 +1528,7 @@ dcb_log_write_failure(DCB *dcb, GWBUF *queue, int eno) } if (dolog) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_DEBUG("%lu [dcb_write] Writing to %s socket failed due %d, %s.", pthread_self(), DCB_ROLE_CLIENT_HANDLER == dcb->dcb_role ? "client" : "backend server", @@ -2458,7 +2458,7 @@ gw_write(DCB *dcb, GWBUF *writeq, bool *stop_writing) saved_errno != EPIPE) #endif { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Write to %s %s in state %s failed due errno %d, %s", DCB_STRTYPE(dcb), dcb->remote, STRDCBSTATE(dcb->state), saved_errno, strerror_r(saved_errno, errbuf, sizeof(errbuf))); @@ -2802,7 +2802,7 @@ dcb_persistent_clean_count(DCB *dcb, bool cleanall) } persistentdcb = nextdcb; } - server->persistmax = MAX(server->persistmax, count); + server->persistmax = MXS_MAX(server->persistmax, count); spinlock_release(&server->persistlock); /** Call possible callback for this DCB in case of close */ while (disposals) @@ -3087,7 +3087,7 @@ dcb_accept(DCB *listener, GWPROTOCOL *protocol_funcs) int sendbuf; struct sockaddr_storage client_conn; socklen_t optlen = sizeof(sendbuf); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; if ((c_sock = dcb_accept_one_connection(listener, (struct sockaddr *)&client_conn)) >= 0) { @@ -3256,7 +3256,7 @@ dcb_accept_one_connection(DCB *listener, struct sockaddr *client_conn) if (c_sock == -1) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; /* Did not get a file descriptor */ if (eno == EAGAIN || eno == EWOULDBLOCK) { @@ -3348,7 +3348,7 @@ dcb_listen(DCB *listener, const char *config, const char *protocol_name) if (listen(listener_socket, 10 * SOMAXCONN) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to start listening on '%s' with protocol '%s': %d, %s", config, protocol_name, @@ -3402,7 +3402,7 @@ dcb_listen_create_socket_inet(const char *config_bind) /** Create the TCP socket */ if ((listener_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Can't create socket: %i, %s", errno, strerror_r(errno, errbuf, sizeof(errbuf))); @@ -3426,7 +3426,7 @@ dcb_listen_create_socket_inet(const char *config_bind) if (bind(listener_socket, (struct sockaddr *) &server_address, sizeof(server_address)) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to bind on '%s': %i, %s", config_bind, errno, @@ -3469,7 +3469,7 @@ dcb_listen_create_socket_unix(const char *config_bind) // UNIX socket create if ((listener_socket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Can't create UNIX socket: %i, %s", errno, strerror_r(errno, errbuf, sizeof(errbuf))); @@ -3496,7 +3496,7 @@ dcb_listen_create_socket_unix(const char *config_bind) if ((-1 == unlink(config_bind)) && (errno != ENOENT)) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to unlink Unix Socket %s: %d %s", config_bind, errno, strerror_r(errno, errbuf, sizeof(errbuf))); } @@ -3504,7 +3504,7 @@ dcb_listen_create_socket_unix(const char *config_bind) /* Bind the socket to the Unix domain socket */ if (bind(listener_socket, (struct sockaddr *) &local_addr, sizeof(local_addr)) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to bind to UNIX Domain socket '%s': %i, %s", config_bind, errno, @@ -3516,7 +3516,7 @@ dcb_listen_create_socket_unix(const char *config_bind) /* set permission for all users */ if (chmod(config_bind, 0777) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to change permissions on UNIX Domain socket '%s': %i, %s", config_bind, errno, @@ -3543,7 +3543,7 @@ dcb_set_socket_option(int sockfd, int level, int optname, void *optval, socklen_ { if (setsockopt(sockfd, level, optname, optval, optlen) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to set socket options. Error %d: %s", errno, strerror_r(errno, errbuf, sizeof(errbuf))); diff --git a/server/core/externcmd.c b/server/core/externcmd.c index 9bcef24ae..37264e19d 100644 --- a/server/core/externcmd.c +++ b/server/core/externcmd.c @@ -12,6 +12,7 @@ */ #include +#include #include /** @@ -170,7 +171,7 @@ int externcmd_execute(EXTERNCMD* cmd) if (pid < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to execute command '%s', fork failed: [%d] %s", cmd->argv[0], errno, strerror_r(errno, errbuf, sizeof(errbuf))); rval = -1; diff --git a/server/core/gateway.c b/server/core/gateway.c index c2919e03e..0320ebf10 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -317,7 +317,7 @@ sigchld_handler (int i) if ((child = wait(&exit_status)) == -1) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to wait child process: %d %s", errno, strerror_r(errno, errbuf, sizeof(errbuf))); } @@ -428,7 +428,7 @@ static int signal_set(int sig, void (*handler)(int)) { int eno = errno; errno = 0; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed call sigaction() in %s due to %d, %s.", program_invocation_short_name, eno, @@ -463,7 +463,7 @@ static bool create_datadir(const char* base, char* datadir) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Cannot create data directory '%s': %d %s\n", datadir, errno, strerror_r(errno, errbuf, sizeof(errbuf))); } @@ -473,7 +473,7 @@ static bool create_datadir(const char* base, char* datadir) { if (len < PATH_MAX) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "Error: Cannot create data directory '%s': %d %s\n", datadir, errno, strerror_r(errno, errbuf, sizeof(errbuf))); } @@ -501,7 +501,7 @@ int ntfw_cb(const char* filename, { int eno = errno; errno = 0; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to remove the data directory %s of MaxScale due to %d, %s.", datadir, eno, strerror_r(eno, errbuf, sizeof(errbuf))); } @@ -702,7 +702,7 @@ static void print_log_n_stderr( { if (mxs_log_init(NULL, get_logdir(), MXS_LOG_TARGET_FS)) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("%s%s%s%s", logstr, eno == 0 ? "" : " (", @@ -712,7 +712,7 @@ static void print_log_n_stderr( } if (do_stderr) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Error: %s%s%s%s\n", fprstr, @@ -1798,7 +1798,7 @@ int main(int argc, char **argv) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Cannot create data directory '%s': %d %s\n", datadir, errno, strerror_r(errno, errbuf, sizeof(errbuf))); goto return_main; @@ -2121,7 +2121,7 @@ static void unlink_pidfile(void) { if (unlink(pidfile)) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "MaxScale failed to remove pidfile %s: error %d, %s\n", pidfile, @@ -2545,7 +2545,7 @@ static int set_user(const char* user) pwname = getpwnam(user); if (pwname == NULL) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; printf("Error: Failed to retrieve user information for '%s': %d %s\n", user, errno, errno == 0 ? "User not found" : strerror_r(errno, errbuf, sizeof(errbuf))); return -1; @@ -2554,7 +2554,7 @@ static int set_user(const char* user) rval = setgid(pwname->pw_gid); if (rval != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; printf("Error: Failed to change group to '%d': %d %s\n", pwname->pw_gid, errno, strerror_r(errno, errbuf, sizeof(errbuf))); return rval; @@ -2563,7 +2563,7 @@ static int set_user(const char* user) rval = setuid(pwname->pw_uid); if (rval != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; printf("Error: Failed to change user to '%s': %d %s\n", pwname->pw_name, errno, strerror_r(errno, errbuf, sizeof(errbuf))); return rval; @@ -2572,7 +2572,7 @@ static int set_user(const char* user) { if (prctl(PR_SET_DUMPABLE , 1) == -1) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; printf("Error: Failed to set dumpable flag on for the process '%s': %d %s\n", pwname->pw_name, errno, strerror_r(errno, errbuf, sizeof(errbuf))); return -1; @@ -2615,7 +2615,7 @@ static bool change_cwd() if (chdir(get_logdir()) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to change working directory to '%s': %d, %s. " "Trying to change working directory to '/'.", get_logdir(), errno, strerror_r(errno, errbuf, sizeof (errbuf))); diff --git a/server/core/gw_utils.c b/server/core/gw_utils.c index d7489d49a..78729e46a 100644 --- a/server/core/gw_utils.c +++ b/server/core/gw_utils.c @@ -143,7 +143,7 @@ bool gw_daemonize(void) if (pid < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "fork() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf))); exit(1); } @@ -156,7 +156,7 @@ bool gw_daemonize(void) if (setsid() < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "setsid() error %s\n", strerror_r(errno, errbuf, sizeof(errbuf))); exit(1); } diff --git a/server/core/log_manager.cc b/server/core/log_manager.cc index 75e855423..996e5e001 100644 --- a/server/core/log_manager.cc +++ b/server/core/log_manager.cc @@ -26,12 +26,12 @@ #include #include -#include #include -#include -#include +#include #include #include +#include +#include "maxscale/mlist.h" #define MAX_PREFIXLEN 250 #define MAX_SUFFIXLEN 250 @@ -1643,7 +1643,7 @@ static bool logfile_write_header(skygw_file_t* file) if ((header_items != 1) || (line_items != 1)) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; LOG_ERROR("MaxScale Log: Writing header failed due to %d, %s\n", errno, strerror_r(errno, errbuf, sizeof(errbuf))); written = false; @@ -1820,13 +1820,13 @@ static bool check_file_and_path(const char* filename, bool* writable) { if (file_is_symlink(filename)) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; LOG_ERROR("MaxScale Log: Error, Can't access file pointed to by %s due to %d, %s.\n", filename, errno, strerror_r(errno, errbuf, sizeof(errbuf))); } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; LOG_ERROR("MaxScale Log: Error, Can't access %s due to %d, %s.\n", filename, errno, strerror_r(errno, errbuf, sizeof(errbuf))); } @@ -1925,7 +1925,7 @@ static bool logfile_init(logfile_t* logfile, if (mkdir(dir, S_IRWXU | S_IRWXG) != 0 && (errno != EEXIST)) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; LOG_ERROR("MaxScale Log: Error, creating directory %s failed due to %d, %s.\n", dir, errno, strerror_r(errno, errbuf, sizeof(errbuf))); @@ -2110,7 +2110,7 @@ static bool logfile_write_footer(skygw_file_t* file, const char* suffix) if ((header_items != 1) || (line_items != 1)) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; LOG_ERROR("MaxScale Log: Writing footer failed due to %d, %s\n", errno, strerror_r(errno, errbuf, sizeof(errbuf))); written = false; @@ -2238,7 +2238,7 @@ static bool thr_flush_file(logmanager_t *lm, filewriter_t *fwr) if (err) { // TODO: Log this to syslog. - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; LOG_ERROR("MaxScale Log: Error, writing to the log-file %s failed due to %d, %s. " "Disabling writing to the log.\n", lf->lf_full_file_name, err, strerror_r(err, errbuf, sizeof(errbuf))); diff --git a/include/maxscale/mlist.h b/server/core/maxscale/mlist.h similarity index 95% rename from include/maxscale/mlist.h rename to server/core/maxscale/mlist.h index 36eec847e..c3ccc1695 100644 --- a/include/maxscale/mlist.h +++ b/server/core/maxscale/mlist.h @@ -1,5 +1,6 @@ -#ifndef _MLIST_H -#define _MLIST_H +#pragma once +#ifndef _MAXSCALE_MLIST_H +#define _MAXSCALE_MLIST_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,9 +14,10 @@ * Public License. */ +#include #include -EXTERN_C_BLOCK_BEGIN +MXS_BEGIN_DECLS typedef struct mlist_node_st mlist_node_t; @@ -74,6 +76,6 @@ mlist_cursor_t* mlist_cursor_init(mlist_t* ml); void* mlist_cursor_get_data_nomutex(mlist_cursor_t* c); bool mlist_cursor_move_to_first(mlist_cursor_t* c); -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/server/core/mlist.c b/server/core/mlist.c index c83df050b..a67822e2c 100644 --- a/server/core/mlist.c +++ b/server/core/mlist.c @@ -11,7 +11,7 @@ * Public License. */ -#include +#include "maxscale/mlist.h" #include static void mlist_free_memory(mlist_t* ml, char* name); diff --git a/server/core/modutil.c b/server/core/modutil.c index bb78c99e9..8f673d1a4 100644 --- a/server/core/modutil.c +++ b/server/core/modutil.c @@ -30,6 +30,7 @@ #include #include #include +#include #include /** These are used when converting MySQL wildcards to regular expressions */ @@ -1059,7 +1060,7 @@ void prepare_pcre2_patterns() { int err; size_t erroff; - PCRE2_UCHAR errbuf[STRERROR_BUFLEN]; + PCRE2_UCHAR errbuf[MXS_STRERROR_BUFLEN]; if ((re_percent = pcre2_compile(pattern_percent, PCRE2_ZERO_TERMINATED, 0, &err, &erroff, NULL)) && @@ -1137,7 +1138,7 @@ mxs_pcre2_result_t modutil_mysql_wildcard_match(const char* pattern, const char* { if (errcode != 0) { - PCRE2_UCHAR errbuf[STRERROR_BUFLEN]; + PCRE2_UCHAR errbuf[MXS_STRERROR_BUFLEN]; pcre2_get_error_message(errcode, errbuf, sizeof(errbuf)); MXS_ERROR("Failed to match pattern: %s", errbuf); } diff --git a/server/core/mysql_binlog.c b/server/core/mysql_binlog.c index 6e52cc47b..15e2a1f1c 100644 --- a/server/core/mysql_binlog.c +++ b/server/core/mysql_binlog.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/core/mysql_utils.c b/server/core/mysql_utils.c index 7ae98160f..1ba15bf67 100644 --- a/server/core/mysql_utils.c +++ b/server/core/mysql_utils.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include /** diff --git a/server/core/poll.c b/server/core/poll.c index e7a1fbb0f..683b8cbf3 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -215,7 +215,7 @@ poll_init() } if ((epoll_fd = epoll_create(MAX_EVENTS)) == -1) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("FATAL: Could not create epoll instance: %s", strerror_r(errno, errbuf, sizeof(errbuf))); exit(-1); } @@ -945,7 +945,7 @@ process_pollq(int thread_id) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_DEBUG("%lu [poll_waitevents] " "EPOLLOUT due %d, %s. " "dcb %p, fd %i", @@ -1012,7 +1012,7 @@ process_pollq(int thread_id) if (eno == 0) { eno = dcb_fake_write_errno[dcb->fd]; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_DEBUG("%lu [poll_waitevents] " "Added fake errno %d. " "%s", @@ -1024,7 +1024,7 @@ process_pollq(int thread_id) #endif /* FAKE_CODE */ if (eno != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_DEBUG("%lu [poll_waitevents] " "EPOLLERR due %d, %s.", pthread_self(), @@ -1047,7 +1047,7 @@ process_pollq(int thread_id) { int eno = 0; eno = gw_getsockerrno(dcb->fd); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_DEBUG("%lu [poll_waitevents] " "EPOLLHUP on dcb %p, fd %d. " "Errno %d, %s.", @@ -1083,7 +1083,7 @@ process_pollq(int thread_id) { int eno = 0; eno = gw_getsockerrno(dcb->fd); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_DEBUG("%lu [poll_waitevents] " "EPOLLRDHUP on dcb %p, fd %d. " "Errno %d, %s.", diff --git a/server/core/query_classifier.c b/server/core/query_classifier.c index 0c984df43..7a0ab82cb 100644 --- a/server/core/query_classifier.c +++ b/server/core/query_classifier.c @@ -16,6 +16,7 @@ #include #include #include +#include //#define QC_TRACE_ENABLED #undef QC_TRACE_ENABLED diff --git a/server/core/queuemanager.c b/server/core/queuemanager.c index 9ddafb487..75468563e 100644 --- a/server/core/queuemanager.c +++ b/server/core/queuemanager.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #if defined(SS_DEBUG) int debug_check_fail = 0; diff --git a/server/core/secrets.c b/server/core/secrets.c index 4ab38da52..21e7318d1 100644 --- a/server/core/secrets.c +++ b/server/core/secrets.c @@ -89,7 +89,7 @@ secrets_readKeys(const char* path) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("The provided path \"%s\" does not exist or cannot be accessed. " "Error: %d, %s.", path, errno, strerror_r(errno, errbuf, sizeof(errbuf))); return NULL; @@ -111,7 +111,7 @@ secrets_readKeys(const char* path) { if (!reported) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_NOTICE("Encrypted password file %s can't be accessed " "(%s). Password encryption is not used.", secret_file, @@ -121,7 +121,7 @@ secrets_readKeys(const char* path) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Access for secrets file " "[%s] failed. Error %d, %s.", secret_file, @@ -137,7 +137,7 @@ secrets_readKeys(const char* path) { int eno = errno; errno = 0; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed opening secret " "file [%s]. Error %d, %s.", secret_file, @@ -153,7 +153,7 @@ secrets_readKeys(const char* path) int eno = errno; errno = 0; close(fd); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("fstat for secret file %s " "failed. Error %d, %s.", secret_file, @@ -167,7 +167,7 @@ secrets_readKeys(const char* path) int eno = errno; errno = 0; close(fd); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Secrets file %s has " "incorrect size. Error %d, %s.", secret_file, @@ -202,7 +202,7 @@ secrets_readKeys(const char* path) errno = 0; close(fd); MXS_FREE(keys); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Read from secrets file " "%s failed. Read %ld, expected %d bytes. Error %d, %s.", secret_file, @@ -219,7 +219,7 @@ secrets_readKeys(const char* path) int eno = errno; errno = 0; MXS_FREE(keys); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed closing the " "secrets file %s. Error %d, %s.", secret_file, @@ -267,7 +267,7 @@ int secrets_writeKeys(const char *dir) /* Open for writing | Create | Truncate the file for writing */ if ((fd = open(secret_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR)) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("failed opening secret " "file [%s]. Error %d, %s.", secret_file, @@ -279,7 +279,7 @@ int secrets_writeKeys(const char *dir) /* Open for writing | Create | Truncate the file for writing */ if ((randfd = open("/dev/random", O_RDONLY)) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("failed opening /dev/random. Error %d, %s.", errno, strerror_r(errno, errbuf, sizeof(errbuf))); @@ -302,7 +302,7 @@ int secrets_writeKeys(const char *dir) /* Write data */ if (write(fd, &key, sizeof(key)) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("failed writing into " "secret file [%s]. Error %d, %s.", secret_file, @@ -315,7 +315,7 @@ int secrets_writeKeys(const char *dir) /* close file */ if (close(fd) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("failed closing the " "secret file [%s]. Error %d, %s.", secret_file, @@ -325,7 +325,7 @@ int secrets_writeKeys(const char *dir) if (chmod(secret_file, S_IRUSR) < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("failed to change the permissions of the" "secret file [%s]. Error %d, %s.", secret_file, diff --git a/server/core/service.c b/server/core/service.c index be80fc8c1..cc908b90f 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -67,6 +67,7 @@ #include #include #include +#include /** To be used with configuration type checks */ typedef struct typelib_st @@ -78,13 +79,13 @@ typedef struct typelib_st /** Set of subsequent false,true pairs */ static const char* bool_strings[11] = {"FALSE", "TRUE", "OFF", "ON", "N", "Y", "0", "1", "NO", "YES", 0}; -typelib_t bool_type = {array_nelems(bool_strings) - 1, "bool_type", bool_strings}; +typelib_t bool_type = {MXS_ARRAY_NELEMS(bool_strings) - 1, "bool_type", bool_strings}; /** List of valid values */ static const char* sqlvar_target_strings[4] = {"MASTER", "ALL", 0}; typelib_t sqlvar_target_type = { - array_nelems(sqlvar_target_strings) - 1, + MXS_ARRAY_NELEMS(sqlvar_target_strings) - 1, "sqlvar_target_type", sqlvar_target_strings }; @@ -382,7 +383,7 @@ int serviceStartAllPorts(SERVICE* service) service->stats.n_failed_starts++; char taskname[strlen(service->name) + strlen("_start_retry_") + (int) ceil(log10(INT_MAX)) + 1]; - int retry_after = MIN(service->stats.n_failed_starts * 10, SERVICE_MAX_RETRY_INTERVAL); + int retry_after = MXS_MIN(service->stats.n_failed_starts * 10, SERVICE_MAX_RETRY_INTERVAL); snprintf(taskname, sizeof(taskname), "%s_start_retry_%d", service->name, service->stats.n_failed_starts); hktask_oneshot(taskname, service_internal_restart, diff --git a/server/core/skygw_utils.cc b/server/core/skygw_utils.cc index c219d2521..8b1142edd 100644 --- a/server/core/skygw_utils.cc +++ b/server/core/skygw_utils.cc @@ -15,6 +15,8 @@ #define PCRE2_CODE_UNIT_WIDTH 8 #endif +#include +#include #include #include #include @@ -23,14 +25,23 @@ #include #include #include -#include -#include +#include #include #include #include #include #include +#if !defined(PATH_MAX) +# if defined(__USE_POSIX) +# define PATH_MAX _POSIX_PATH_MAX +# else +# define PATH_MAX 256 +# endif +#endif + +#define MAX_ERROR_MSG PATH_MAX + static void simple_mutex_free_memory(simple_mutex_t* sm); static void thread_free_memory(skygw_thread_t* th, char* name); /** End of static function declarations */ @@ -47,7 +58,7 @@ int skygw_rwlock_rdlock(skygw_rwlock_t* rwlock) else { rwlock->srw_rwlock_thr = 0; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; ss_dfprintf(stderr, "* pthread_rwlock_rdlock : %s\n", strerror_r(err, errbuf, sizeof (errbuf))); @@ -66,7 +77,7 @@ int skygw_rwlock_wrlock(skygw_rwlock_t* rwlock) else { rwlock->srw_rwlock_thr = 0; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; ss_dfprintf(stderr, "* pthread_rwlock_wrlock : %s\n", strerror_r(err, errbuf, sizeof (errbuf))); @@ -84,7 +95,7 @@ int skygw_rwlock_unlock(skygw_rwlock_t* rwlock) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; ss_dfprintf(stderr, "* pthread_rwlock_unlock : %s\n", strerror_r(err, errbuf, sizeof (errbuf))); } @@ -97,7 +108,7 @@ int skygw_rwlock_destroy(skygw_rwlock_t* rwlock) /** Lock */ if ((err = pthread_rwlock_wrlock(rwlock->srw_rwlock)) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Error : pthread_rwlock_wrlock failed due to %d, %s.\n", err, strerror_r(err, errbuf, sizeof (errbuf))); goto retblock; @@ -109,7 +120,7 @@ int skygw_rwlock_destroy(skygw_rwlock_t* rwlock) /** Destroy */ if ((err = pthread_rwlock_destroy(rwlock->srw_rwlock)) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Error : pthread_rwlock_destroy failed due to %d,%s\n", err, strerror_r(err, errbuf, sizeof (errbuf))); } @@ -141,7 +152,7 @@ int skygw_rwlock_init(skygw_rwlock_t** rwlock) if (err != 0) { free(rwl); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; ss_dfprintf(stderr, "* Creating pthread_rwlock failed : %s\n", strerror_r(err, errbuf, sizeof (errbuf))); goto return_err; @@ -193,7 +204,7 @@ size_t snprint_timestamp(char* p_ts, size_t tslen) t = time(NULL); localtime_r(&t, &tm); - snprintf(p_ts, MIN(tslen, timestamp_len), timestamp_formatstr, + snprintf(p_ts, MXS_MIN(tslen, timestamp_len), timestamp_formatstr, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); rval = strlen(p_ts) * sizeof (char); @@ -234,7 +245,7 @@ size_t snprint_timestamp_hp(char* p_ts, size_t tslen) gettimeofday(&tv, NULL); localtime_r(&tv.tv_sec, &tm); usec = tv.tv_usec / 1000; - snprintf(p_ts, MIN(tslen, timestamp_len_hp), timestamp_formatstr_hp, + snprintf(p_ts, MXS_MIN(tslen, timestamp_len_hp), timestamp_formatstr_hp, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, usec); rval = strlen(p_ts) * sizeof (char); @@ -339,7 +350,7 @@ int skygw_thread_start(skygw_thread_t* thr) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Starting file writer thread failed due error, %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); goto return_err; @@ -515,7 +526,7 @@ simple_mutex_t* simple_mutex_init(simple_mutex_t* mutexptr, const char* name) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Initializing simple mutex %s failed due error %d, %s\n", name, err, strerror_r(errno, errbuf, sizeof (errbuf))); perror("simple_mutex : "); @@ -555,7 +566,7 @@ int simple_mutex_done(simple_mutex_t* sm) if (err != 0) { perror("simple_mutex : "); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Destroying simple mutex %s failed due %d, %s\n", sm->sm_name, err, strerror_r(errno, errbuf, sizeof (errbuf))); goto return_err; @@ -602,7 +613,7 @@ int simple_mutex_lock(simple_mutex_t* sm, bool block) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Locking simple mutex %s failed due error, %d, %s\n", sm->sm_name, err, strerror_r(errno, errbuf, sizeof (errbuf))); perror("simple_mutex : "); @@ -631,7 +642,7 @@ int simple_mutex_unlock(simple_mutex_t* sm) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Unlocking simple mutex %s failed due error %d, %s\n", sm->sm_name, err, strerror_r(errno, errbuf, sizeof (errbuf))); perror("simple_mutex : "); @@ -665,7 +676,7 @@ skygw_message_t* skygw_message_init(void) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Initializing pthread mutex failed due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); free(mes); @@ -676,7 +687,7 @@ skygw_message_t* skygw_message_init(void) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Initializing pthread cond var failed, due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); pthread_mutex_destroy(&mes->mes_mutex); @@ -705,7 +716,7 @@ void skygw_message_done(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Destroying cond var failed due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); } @@ -714,7 +725,7 @@ void skygw_message_done(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Destroying pthread mutex failed, due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); } @@ -732,7 +743,7 @@ skygw_mes_rc_t skygw_message_send(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Locking pthread mutex failed, due to error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); goto return_mes_rc; @@ -746,7 +757,7 @@ skygw_mes_rc_t skygw_message_send(skygw_message_t* mes) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Signaling pthread cond var failed, due to error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); } @@ -754,7 +765,7 @@ skygw_mes_rc_t skygw_message_send(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Unlocking pthread mutex failed, due to error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); } @@ -772,7 +783,7 @@ void skygw_message_wait(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Locking pthread mutex failed, due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); } @@ -784,7 +795,7 @@ void skygw_message_wait(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Locking pthread cond wait failed, due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); } @@ -794,7 +805,7 @@ void skygw_message_wait(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Unlocking pthread mutex failed, due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); } @@ -810,7 +821,7 @@ void skygw_message_reset(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Locking pthread mutex failed, due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); goto return_mes_rc; @@ -821,7 +832,7 @@ void skygw_message_reset(skygw_message_t* mes) if (err != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Unlocking pthread mutex failed, due error %d, %s\n", err, strerror_r(errno, errbuf, sizeof (errbuf))); goto return_mes_rc; @@ -923,7 +934,7 @@ skygw_file_t* skygw_file_init(const char* fname, { int eno = errno; errno = 0; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Opening file %s failed due %d, %s.\n", file->sf_fname, eno, strerror_r(eno, errbuf, sizeof (errbuf))); free(file); @@ -947,7 +958,7 @@ skygw_file_t* skygw_file_init(const char* fname, { int eno = errno; errno = 0; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "failed to create symlink %s -> %s due %d, %s. Exiting.", fname, symlinkname, eno, strerror_r(eno, errbuf, sizeof (errbuf))); free(file); @@ -983,7 +994,7 @@ void skygw_file_close(skygw_file_t* file) if ((err = fclose(file->sf_file)) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "* Closing file %s failed due to %d, %s.\n", file->sf_fname, errno, strerror_r(errno, errbuf, sizeof (errbuf))); } @@ -1159,7 +1170,7 @@ char* replace_literal(char* haystack, const char* needle, const char* replacemen if (search_re == NULL) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "Regex memory allocation failed : %s\n", strerror_r(errno, errbuf, sizeof (errbuf))); newstr = haystack; @@ -1172,7 +1183,7 @@ char* replace_literal(char* haystack, const char* needle, const char* replacemen if (newstr == NULL) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; fprintf(stderr, "Regex memory allocation failed : %s\n", strerror_r(errno, errbuf, sizeof (errbuf))); free(search_re); diff --git a/server/core/slist.c b/server/core/slist.c deleted file mode 100644 index ab5cdd7ca..000000000 --- a/server/core/slist.c +++ /dev/null @@ -1,364 +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. - */ - -#include -#include -#include - -static slist_cursor_t* slist_cursor_init(slist_t* list); -static slist_t* slist_init_ex(bool create_cursors); -static slist_node_t* slist_node_init(void* data, slist_cursor_t* cursor); -static void slist_add_node(slist_t* list, slist_node_t* node); - -#if defined(NOT_USED) -static slist_node_t* slist_node_get_next(slist_node_t* curr_node); -static slist_node_t* slist_get_first(slist_t* list); -static slist_cursor_t* slist_get_cursor(slist_t* list); -#endif /*< NOT_USED */ - -/** End of static function declarations */ - -static slist_t* slist_init_ex(bool create_cursors) -{ - slist_t* list; - - list = (slist_t*) MXS_CALLOC(1, sizeof (slist_t)); - MXS_ABORT_IF_NULL(list); - list->slist_chk_top = CHK_NUM_SLIST; - list->slist_chk_tail = CHK_NUM_SLIST; - - if (create_cursors) - { - list->slist_cursors_list = slist_init_ex(false); - } - - return list; -} - -static slist_node_t* slist_node_init(void* data, slist_cursor_t* cursor) -{ - slist_node_t* node; - - node = (slist_node_t*) MXS_CALLOC(1, sizeof (slist_node_t)); - MXS_ABORT_IF_NULL(node); - node->slnode_chk_top = CHK_NUM_SLIST_NODE; - node->slnode_chk_tail = CHK_NUM_SLIST_NODE; - node->slnode_data = data; - CHK_SLIST_NODE(node); - - if (cursor != NULL) - { - node->slnode_cursor_refcount += 1; - cursor->slcursor_pos = node; - } - - return node; -} - -static void slist_add_node(slist_t* list, slist_node_t* node) -{ - CHK_SLIST(list); - CHK_SLIST_NODE(node); - - if (list->slist_tail != NULL) - { - CHK_SLIST_NODE(list->slist_tail); - CHK_SLIST_NODE(list->slist_head); - ss_dassert(list->slist_tail->slnode_next == NULL); - list->slist_tail->slnode_next = node; - } - else - { - list->slist_head = node; - } - list->slist_tail = node; - node->slnode_list = list; - list->slist_nelems += 1; - CHK_SLIST(list); -} - - -#if defined(NOT_USED) - -static slist_node_t* slist_node_get_next(slist_node_t* curr_node) -{ - CHK_SLIST_NODE(curr_node); - - if (curr_node->slnode_next != NULL) - { - CHK_SLIST_NODE(curr_node->slnode_next); - return (curr_node->slnode_next); - } - - return NULL; -} - -static slist_node_t* slist_get_first(slist_t* list) -{ - CHK_SLIST(list); - - if (list->slist_head != NULL) - { - CHK_SLIST_NODE(list->slist_head); - return list->slist_head; - } - return NULL; -} - -static slist_cursor_t* slist_get_cursor(slist_t* list) -{ - CHK_SLIST(list); - - slist_cursor_t* c; - - c = slist_cursor_init(list); - return c; -} -#endif /*< NOT_USED */ - -static slist_cursor_t* slist_cursor_init(slist_t* list) -{ - CHK_SLIST(list); - slist_cursor_t* c; - - c = (slist_cursor_t *) MXS_CALLOC(1, sizeof (slist_cursor_t)); - MXS_ABORT_IF_NULL(c); - c->slcursor_chk_top = CHK_NUM_SLIST_CURSOR; - c->slcursor_chk_tail = CHK_NUM_SLIST_CURSOR; - c->slcursor_list = list; - /** Set cursor position is list is not empty */ - if (list->slist_head != NULL) - { - list->slist_head->slnode_cursor_refcount += 1; - c->slcursor_pos = list->slist_head; - } - /** Add cursor to cursor list */ - slist_add_node(list->slist_cursors_list, slist_node_init(c, NULL)); - - CHK_SLIST_CURSOR(c); - return c; -} - -/** - * @node Create a cursor and a list with cursors supported. 19.6.2013 : - * supports only cursor per list. - * - * Parameters: - * @param void - - * - * - * @return returns a pointer to cursor, which is not positioned - * because the list is empty. - * - * - * @details (write detailed description here) - * - */ -slist_cursor_t* slist_init(void) -{ - slist_t* list; - slist_cursor_t* slc; - - list = slist_init_ex(true); - CHK_SLIST(list); - slc = slist_cursor_init(list); - CHK_SLIST_CURSOR(slc); - - return slc; -} - -/** - * @node moves cursor to the first node of list. - * - * Parameters: - * @param c - - * - * - * @return true if there is first node in the list - * false is the list is empty. - * - * - * @details (write detailed description here) - * - */ -bool slcursor_move_to_begin(slist_cursor_t* c) -{ - bool succp = true; - slist_t* list; - - CHK_SLIST_CURSOR(c); - list = c->slcursor_list; - CHK_SLIST(list); - c->slcursor_pos = list->slist_head; - if (c->slcursor_pos == NULL) - { - succp = false; - } - return succp; -} - -/** - * @node moves cursor to next node - * - * Parameters: - * @param c - - * - * - * @return true in success, false is there is no next node on the list. - * - * - * @details (write detailed description here) - * - */ -bool slcursor_step_ahead(slist_cursor_t* c) -{ - bool succp = false; - slist_node_t* node; - CHK_SLIST_CURSOR(c); - CHK_SLIST_NODE(c->slcursor_pos); - - node = c->slcursor_pos->slnode_next; - - if (node != NULL) - { - CHK_SLIST_NODE(node); - c->slcursor_pos = node; - succp = true; - } - return succp; -} - -void* slcursor_get_data(slist_cursor_t* c) -{ - slist_node_t* node; - void* data = NULL; - - CHK_SLIST_CURSOR(c); - node = c->slcursor_pos; - - if (node != NULL) - { - CHK_SLIST_NODE(node); - data = node->slnode_data; - } - return data; -} - -/** - * @node Add data to the list by using cursor. - * - * Parameters: - * @param c - - * - * - * @param data - - * - * - * @return void - * - * - * @details (write detailed description here) - * - */ -void slcursor_add_data(slist_cursor_t* c, void* data) -{ - slist_t* list; - slist_node_t* pos; - - CHK_SLIST_CURSOR(c); - list = c->slcursor_list; - CHK_SLIST(list); - if (c->slcursor_pos != NULL) - { - CHK_SLIST_NODE(c->slcursor_pos); - } - ss_dassert(list->slist_tail->slnode_next == NULL); - pos = slist_node_init(data, c); - slist_add_node(list, pos); - CHK_SLIST(list); - CHK_SLIST_CURSOR(c); -} - -/** - * Remove the node currently pointed by the cursor from the slist. This does not delete the data in the - * node but will delete the structure pointing to that data. This is useful when - * the user wants to free the allocated memory. After node removal, the cursor - * will point to the node before the removed node. - * @param c Cursor pointing to the data node to be removed - */ -void slcursor_remove_data(slist_cursor_t* c) -{ - slist_node_t* node = c->slcursor_pos; - int havemore = slist_size(c); - slcursor_move_to_begin(c); - - if (node == c->slcursor_pos) - { - c->slcursor_list->slist_head = c->slcursor_list->slist_head->slnode_next; - slcursor_move_to_begin(c); - atomic_add((int*) &node->slnode_list->slist_nelems, -1); - atomic_add((int*) &node->slnode_cursor_refcount, -1); - if (node->slnode_cursor_refcount == 0) - { - MXS_FREE(node); - } - return; - } - - while (havemore) - { - if (c->slcursor_pos->slnode_next == node) - { - c->slcursor_pos->slnode_next = node->slnode_next; - atomic_add((int*) &node->slnode_list->slist_nelems, -1); - atomic_add((int*) &node->slnode_cursor_refcount, -1); - if (node->slnode_cursor_refcount == 0) - { - MXS_FREE(node); - } - return; - } - havemore = slcursor_step_ahead(c); - } -} - -/** - * Return the size of the slist. - * @param c slist cursor which refers to a list - * @return nummber of elements in the list - */ -size_t slist_size(slist_cursor_t* c) -{ - return c->slcursor_list->slist_nelems; -} - -void slist_done(slist_cursor_t* c) -{ - bool succp; - void* data; - - succp = slcursor_move_to_begin(c); - - while (succp) - { - data = slcursor_get_data(c); - MXS_FREE(data); - succp = slcursor_step_ahead(c); - } - MXS_FREE(c->slcursor_list); - MXS_FREE(c); -} - - -/** End of list implementation */ - diff --git a/server/core/spinlock.c b/server/core/spinlock.c index 9772eb65f..532e8c71b 100644 --- a/server/core/spinlock.c +++ b/server/core/spinlock.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include /** * Initialise a spinlock. diff --git a/server/core/test/test_utils.h b/server/core/test/test_utils.h index d1ea666c8..150cc7ecd 100644 --- a/server/core/test/test_utils.h +++ b/server/core/test/test_utils.h @@ -1,6 +1,6 @@ +#pragma once #ifndef TEST_UTILS_H #define TEST_UTILS_H - /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -14,6 +14,7 @@ * Public License. */ +#include #include #include #include diff --git a/server/core/test/testadminusers.c b/server/core/test/testadminusers.c index 4ea8f5e88..1164f6f0c 100644 --- a/server/core/test/testadminusers.c +++ b/server/core/test/testadminusers.c @@ -37,7 +37,7 @@ #include #include #include - +#include /** * test1 default user diff --git a/server/core/test/testgwbitmask.c b/server/core/test/testgwbitmask.c index 751920624..78bc51cbf 100644 --- a/server/core/test/testgwbitmask.c +++ b/server/core/test/testgwbitmask.c @@ -35,7 +35,7 @@ #include -#include +#include /** * test1 Create a bitmap and mess around with it diff --git a/server/core/test/testmaxscalepcre2.c b/server/core/test/testmaxscalepcre2.c index b3c1b7395..a2b69fd3b 100644 --- a/server/core/test/testmaxscalepcre2.c +++ b/server/core/test/testmaxscalepcre2.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #define test_assert(a, b) if(!(a)){fprintf(stderr, b);return 1;} diff --git a/server/core/test/testpoll.c b/server/core/test/testpoll.c index aea0cd1a5..ecd5892a9 100644 --- a/server/core/test/testpoll.c +++ b/server/core/test/testpoll.c @@ -69,7 +69,7 @@ test1() if (dcb->fd < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; ss_dfprintf(stderr, "\nError on function call: socket() returned %d: %s\n", errno, strerror_r(errno, errbuf, sizeof(errbuf))); return 1; diff --git a/server/core/utils.c b/server/core/utils.c index b439f4fca..e829b871a 100644 --- a/server/core/utils.c +++ b/server/core/utils.c @@ -60,7 +60,7 @@ int setnonblocking(int fd) if ((fl = fcntl(fd, F_GETFL, 0)) == -1) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Can't GET fcntl for %i, errno = %d, %s.", fd, errno, @@ -70,7 +70,7 @@ int setnonblocking(int fd) if (fcntl(fd, F_SETFL, fl | O_NONBLOCK) == -1) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Can't SET fcntl for %i, errno = %d, %s", fd, errno, @@ -346,7 +346,7 @@ static bool mkdir_all_internal(char *path, mode_t mask) } else { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to create directory '%s': %d, %s", path, errno, strerror_r(errno, err, sizeof(err))); } @@ -355,7 +355,7 @@ static bool mkdir_all_internal(char *path, mode_t mask) } else { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to create directory '%s': %d, %s", path, errno, strerror_r(errno, err, sizeof(err))); } diff --git a/server/modules/authenticator/gssapi_auth.h b/server/modules/authenticator/gssapi_auth.h index 4f2935c2b..317db08b7 100644 --- a/server/modules/authenticator/gssapi_auth.h +++ b/server/modules/authenticator/gssapi_auth.h @@ -1,3 +1,6 @@ +#pragma once +#ifndef _GSSAPI_AUTH_H +#define _GSSAPI_AUTH_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -11,13 +14,13 @@ * Public License. */ -#ifndef _GSSAPI_AUTH_H -#define _GSSAPI_AUTH_H - +#include #include #include #include +MXS_BEGIN_DECLS + /** Client auth plugin name */ static const char auth_plugin_name[] = "auth_gssapi_client"; @@ -48,4 +51,6 @@ void gssapi_auth_free(void *data); /** Report GSSAPI errors */ void report_error(OM_uint32 major, OM_uint32 minor); +MXS_END_DECLS + #endif diff --git a/server/modules/filter/cache/cache.h b/server/modules/filter/cache/cache.h index c9deff52e..a0fc8bf2b 100644 --- a/server/modules/filter/cache/cache.h +++ b/server/modules/filter/cache/cache.h @@ -1,5 +1,6 @@ -#ifndef CACHE_H -#define CACHE_H +#pragma once +#ifndef _MAXSCALE_FILTER_CACHE_CACHE_H +#define _MAXSCALE_FILTER_CACHE_CACHE_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -15,6 +16,8 @@ #include +MXS_BEGIN_DECLS + #define CACHE_DEBUG_NONE 0 #define CACHE_DEBUG_MATCHING 1 #define CACHE_DEBUG_NON_MATCHING 2 @@ -35,4 +38,6 @@ // Integer value #define CACHE_DEFAULT_DEBUG 0 +MXS_END_DECLS + #endif diff --git a/server/modules/filter/cache/cache_storage_api.h b/server/modules/filter/cache/cache_storage_api.h index 3755d58ec..a413afe54 100644 --- a/server/modules/filter/cache/cache_storage_api.h +++ b/server/modules/filter/cache/cache_storage_api.h @@ -1,5 +1,6 @@ -#ifndef _MAXSCALE_FILTER_CACHE_CACHE_H -#define _MAXSCALE_FILTER_CACHE_CACHE_H +#pragma once +#ifndef _MAXSCALE_FILTER_CACHE_CACHE_STORAGE_API_H +#define _MAXSCALE_FILTER_CACHE_CACHE_STORAGE_API_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -17,9 +18,9 @@ #include #include #include -#include +#include -EXTERN_C_BLOCK_BEGIN +MXS_BEGIN_DECLS typedef enum cache_result { @@ -116,6 +117,6 @@ typedef struct cache_storage_api #define CACHE_STORAGE_ENTRY_POINT "CacheGetStorageAPI" typedef CACHE_STORAGE_API* (*CacheGetStorageAPIFN)(); -EXTERN_C_BLOCK_END +MXS_END_DECLS #endif diff --git a/server/modules/filter/cache/rules.c b/server/modules/filter/cache/rules.c index 8e5c0179a..cc2b3bdaa 100644 --- a/server/modules/filter/cache/rules.c +++ b/server/modules/filter/cache/rules.c @@ -246,7 +246,7 @@ CACHE_RULES *cache_rules_load(const char *path, uint32_t debug) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Could not open rules file %s for reading: %s", path, strerror_r(errno, errbuf, sizeof(errbuf))); diff --git a/server/modules/filter/cache/rules.h b/server/modules/filter/cache/rules.h index c5590094f..667ad344b 100644 --- a/server/modules/filter/cache/rules.h +++ b/server/modules/filter/cache/rules.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MAXSCALE_FILTER_CACHE_RULES_H #define _MAXSCALE_FILTER_CACHE_RULES_H /* @@ -13,12 +14,14 @@ * Public License. */ +#include #include #include #include #include #include +MXS_BEGIN_DECLS typedef enum cache_rule_attribute { @@ -71,4 +74,6 @@ CACHE_RULES *cache_rules_parse(const char *json, uint32_t debug); bool cache_rules_should_store(CACHE_RULES *rules, const char *default_db, const GWBUF* query); bool cache_rules_should_use(CACHE_RULES *rules, const SESSION *session); +MXS_END_DECLS + #endif diff --git a/server/modules/filter/cache/storage.h b/server/modules/filter/cache/storage.h index 3132938f3..f0d2f8bef 100644 --- a/server/modules/filter/cache/storage.h +++ b/server/modules/filter/cache/storage.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MAXSCALE_FILTER_CACHE_STORAGE_H #define _MAXSCALE_FILTER_CACHE_STORAGE_H /* @@ -13,8 +14,11 @@ * Public License. */ +#include #include "cache_storage_api.h" +MXS_BEGIN_DECLS + typedef struct cache_storage_module_t { void* handle; @@ -24,4 +28,6 @@ typedef struct cache_storage_module_t CACHE_STORAGE_MODULE* cache_storage_open(const char *name); void cache_storage_close(CACHE_STORAGE_MODULE *module); +MXS_END_DECLS + #endif diff --git a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbinternals.h b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbinternals.h index 9435f30d0..f82920732 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbinternals.h +++ b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbinternals.h @@ -14,6 +14,7 @@ * Public License. */ +#include #include "storage_rocksdb.h" #include #include diff --git a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc index 2fdbc5b1c..a57675594 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc +++ b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc @@ -118,7 +118,7 @@ bool RocksDBStorage::Initialize() else if (errno != EEXIST) { initialized = false; - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to create storage directory %s: %s", u_storageDirectory.c_str(), diff --git a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.h b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.h index 6c2eb1a72..0967fb86b 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.h +++ b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _ROCKSDBSTORAGE_H #define _ROCKSDBSTORAGE_H /* @@ -13,6 +14,7 @@ * Public License. */ +#include #include "storage_rocksdb.h" #include #include diff --git a/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.h b/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.h index 895421d4b..7ab92c51b 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.h +++ b/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _STORAGE_ROCKSDB_H #define _STORAGE_ROCKSDB_H /* @@ -14,6 +15,7 @@ */ #define MXS_MODULE_NAME "storage_rocksdb" +#include #include #endif diff --git a/server/modules/filter/cache/test/testrules.c b/server/modules/filter/cache/test/testrules.c index d717fd5a4..3039e6605 100644 --- a/server/modules/filter/cache/test/testrules.c +++ b/server/modules/filter/cache/test/testrules.c @@ -17,7 +17,7 @@ #if !defined(SS_DEBUG) #define SS_DEBUG #endif -#include +#include struct test_case { diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.c b/server/modules/filter/dbfwfilter/dbfwfilter.c index 33e684bd1..cebe94df1 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter/dbfwfilter.c @@ -70,7 +70,6 @@ #include #include #include -#include #include #include #include @@ -1174,7 +1173,7 @@ bool define_regex_rule(void* scanner, char* pattern) } else { - PCRE2_UCHAR errbuf[STRERROR_BUFLEN]; + PCRE2_UCHAR errbuf[MXS_STRERROR_BUFLEN]; pcre2_get_error_message(err, errbuf, sizeof(errbuf)); MXS_ERROR("dbfwfilter: Invalid regular expression '%s': %s", start, errbuf); @@ -1344,7 +1343,7 @@ static bool process_rule_file(const char* filename, FW_INSTANCE* instance) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to open rule file '%s': %d, %s", filename, errno, strerror_r(errno, errbuf, sizeof(errbuf))); @@ -2241,7 +2240,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue) int len; if (modutil_extract_SQL(queue, &sql, &len)) { - len = MIN(len, FW_MAX_SQL_LEN); + len = MXS_MIN(len, FW_MAX_SQL_LEN); if (match && my_instance->log_match & FW_LOG_MATCH) { ss_dassert(rname); diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.h b/server/modules/filter/dbfwfilter/dbfwfilter.h index 9e828e361..4171f2612 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.h +++ b/server/modules/filter/dbfwfilter/dbfwfilter.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _DBFWFILTER_H #define _DBFWFILTER_H /* @@ -20,8 +21,11 @@ * the generater parser which is created from the ruleparser.y and token.l files. */ +#include #include +MXS_BEGIN_DECLS + /** Matching type */ enum match_type { @@ -49,4 +53,6 @@ bool add_active_rule(void* scanner, const char* name); void set_matching_mode(void* scanner, enum match_type mode); bool create_user_templates(void* scanner); +MXS_END_DECLS + #endif diff --git a/server/modules/filter/gatekeeper/gatekeeper.c b/server/modules/filter/gatekeeper/gatekeeper.c index f51ffa0e6..e794c9a3b 100644 --- a/server/modules/filter/gatekeeper/gatekeeper.c +++ b/server/modules/filter/gatekeeper/gatekeeper.c @@ -183,7 +183,7 @@ static FILTER* createInstance(const char *name, char **options, FILTER_PARAMETER } else { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR(MODNAME"File is not accessible: %d, %s", errno, strerror_r(errno, err, sizeof(err))); ok = false; @@ -453,7 +453,7 @@ static bool write_stored_data(GK_INSTANCE *inst) if (write(fd, &len, sizeof(len)) != sizeof(len) || write(fd, key, len) != len) { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR(MODNAME"Failed to write key '%s' to disk (%d, %s). The datafile at '%s' was " "not updated but it will be updated when the next session closes. ", key, errno, strerror_r(errno, err, sizeof(err)), inst->datadir); @@ -471,7 +471,7 @@ static bool write_stored_data(GK_INSTANCE *inst) if (!rval) { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR(MODNAME"Failed to rename file '%s' to '%s' when writing data: %d, %s", filepath, newfilepath, errno, strerror_r(errno, err, sizeof(err))); } @@ -479,7 +479,7 @@ static bool write_stored_data(GK_INSTANCE *inst) } else if (fd == -1) { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR(MODNAME"Failed to open file '%s' when writing data: %d, %s", filepath, errno, strerror_r(errno, err, sizeof(err))); } @@ -497,7 +497,7 @@ static void report_failed_read(FILE *file, int nexpected, int nread) { if (ferror(file)) { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR(MODNAME"Failed to read %d bytes, only %d bytes read: %d, %s", nexpected, nread, errno, strerror_r(errno, err, sizeof(err))); } @@ -579,7 +579,7 @@ static bool read_stored_data(GK_INSTANCE *inst) } else { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR(MODNAME"Failed to open file '%s' when reading stored data: %d, %s", filepath, errno, strerror_r(errno, err, sizeof(err))); } diff --git a/server/modules/filter/hintfilter/mysqlhint.h b/server/modules/filter/hintfilter/mysqlhint.h index 85c9739fc..5766e1d38 100644 --- a/server/modules/filter/hintfilter/mysqlhint.h +++ b/server/modules/filter/hintfilter/mysqlhint.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MYSQLHINT_H #define _MYSQLHINT_H /* @@ -19,8 +20,12 @@ * Date Who Description * 17-07-2014 Mark Riddoch Initial implementation */ + +#include #include +MXS_BEGIN_DECLS + /* Parser tokens for the hint parser */ typedef enum { @@ -105,11 +110,10 @@ typedef struct #define HS_PVALUE 5 #define HS_PREPARE 6 - extern HINT *hint_parser(HINT_SESSION *session, GWBUF *request); NAMEDHINTS* free_named_hint(NAMEDHINTS* named_hint); HINTSTACK* free_hint_stack(HINTSTACK* hint_stack); - +MXS_END_DECLS #endif diff --git a/server/modules/filter/luafilter/luafilter.c b/server/modules/filter/luafilter/luafilter.c index 47f274326..5da797e47 100644 --- a/server/modules/filter/luafilter/luafilter.c +++ b/server/modules/filter/luafilter/luafilter.c @@ -36,9 +36,8 @@ * or diagnostic being made for the session script. */ -#include #include -#include +#include #include #include #include diff --git a/server/modules/filter/qlafilter/qlafilter.c b/server/modules/filter/qlafilter/qlafilter.c index eece0cb0f..f1d7a9fc0 100644 --- a/server/modules/filter/qlafilter/qlafilter.c +++ b/server/modules/filter/qlafilter/qlafilter.c @@ -350,7 +350,7 @@ newSession(FILTER *instance, SESSION *session) if (my_session->fp == NULL) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Opening output file for qla " "fileter failed due to %d, %s", errno, @@ -363,7 +363,7 @@ newSession(FILTER *instance, SESSION *session) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Memory allocation for qla filter failed due to " "%d, %s.", errno, diff --git a/server/modules/filter/tpmfilter/tpmfilter.c b/server/modules/filter/tpmfilter/tpmfilter.c index d803421a4..d082c89f6 100644 --- a/server/modules/filter/tpmfilter/tpmfilter.c +++ b/server/modules/filter/tpmfilter/tpmfilter.c @@ -39,6 +39,7 @@ * @endverbatim */ +#include #include #include #include diff --git a/server/modules/include/binlog_common.h b/server/modules/include/binlog_common.h index 7db1f79ae..0b7b301d6 100644 --- a/server/modules/include/binlog_common.h +++ b/server/modules/include/binlog_common.h @@ -1,5 +1,6 @@ -#ifndef BINLOG_COMMON_H -#define BINLOG_COMMON_H +#pragma once +#ifndef _BINLOG_COMMON_H +#define _BINLOG_COMMON_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -13,9 +14,13 @@ * Public License. */ +#include #include #include #include + +MXS_BEGIN_DECLS + /** * Packet header for replication messages */ @@ -45,4 +50,6 @@ bool binlog_next_file_exists(const char* binlogdir, const char* binlog); uint32_t extract_field(uint8_t *src, int bits); const char* binlog_event_name(int type); +MXS_END_DECLS + #endif /* BINLOG_COMMON_H */ diff --git a/server/modules/include/blr_constants.h b/server/modules/include/blr_constants.h index ae2dd7287..1a91e86ba 100644 --- a/server/modules/include/blr_constants.h +++ b/server/modules/include/blr_constants.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _BLR_DEFINES_H #define _BLR_DEFINES_H /* @@ -13,16 +14,19 @@ * Public License. */ -/* +/** + * @file blr_defines.h - Various definitions for binlogrouter + * @verbatim * Revision History * * 26/04/16 Massimiliano Pinto Added MariaDB 10.0 and 10.1 GTID event flags detection + * @endverbatim */ -/** - * @file blr_defines.h - Various definitions for binlogrouter - */ +#include + +MXS_BEGIN_DECLS #define BINLOG_FNAMELEN 255 #define BLR_PROTOCOL "MySQLBackend" @@ -201,4 +205,6 @@ #define EXTRACT32(x) extract_field((x), 32) #endif +MXS_END_DECLS + #endif diff --git a/server/modules/include/cdc.h b/server/modules/include/cdc.h index 80f0d0c81..0785ccbd0 100644 --- a/server/modules/include/cdc.h +++ b/server/modules/include/cdc.h @@ -1,3 +1,6 @@ +#pragma once +#ifndef _CDC_H +#define _CDC_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -18,6 +21,7 @@ * 11-01-2016 Massimiliano Pinto First Implementation */ +#include #include #include #include @@ -35,6 +39,8 @@ #include #include +MXS_BEGIN_DECLS + #define CDC_SMALL_BUFFER 1024 #define CDC_METHOD_MAXLEN 128 #define CDC_USER_MAXLEN 128 @@ -87,3 +93,7 @@ typedef struct cdc_protocol /* routines */ extern int gw_hex2bin(uint8_t *out, const char *in, unsigned int len); + +MXS_END_DECLS + +#endif diff --git a/server/modules/include/debugcli.h b/server/modules/include/debugcli.h index f736038b3..a32f47374 100644 --- a/server/modules/include/debugcli.h +++ b/server/modules/include/debugcli.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _DEBUGCLI_H #define _DEBUGCLI_H /* @@ -13,9 +14,6 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#include -#include -#include /** * @file debugcli.h The debug interface to the gateway @@ -28,6 +26,14 @@ * * @endverbatim */ + +#include +#include +#include +#include + +MXS_BEGIN_DECLS + struct cli_session; /** @@ -63,4 +69,7 @@ typedef struct cli_session /* Command line interface modes */ #define CLIM_USER 1 #define CLIM_DEVELOPER 2 + +MXS_END_DECLS + #endif diff --git a/server/modules/include/mysql_auth.h b/server/modules/include/mysql_auth.h index 761fe530c..a487d4aa7 100644 --- a/server/modules/include/mysql_auth.h +++ b/server/modules/include/mysql_auth.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MYSQL_AUTH_H #define _MYSQL_AUTH_H /* @@ -23,11 +24,14 @@ * @endverbatim */ +#include #include #include #include #include +MXS_BEGIN_DECLS + int gw_check_mysql_scramble_data(DCB *dcb, uint8_t *token, unsigned int token_len, @@ -41,4 +45,6 @@ int gw_find_mysql_user_password_sha1( uint8_t *gateway_password, DCB *dcb); +MXS_END_DECLS + #endif /** _MYSQL_AUTH_H */ diff --git a/server/modules/include/telnetd.h b/server/modules/include/telnetd.h index eef8fc4bb..a8689147c 100644 --- a/server/modules/include/telnetd.h +++ b/server/modules/include/telnetd.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _TELNETD_H #define _TELNETD_H /* @@ -24,8 +25,13 @@ * * @endverbatim */ + +#include #include #include + +MXS_BEGIN_DECLS + /** * The telnetd specific protocol structure to put in the DCB. */ @@ -57,4 +63,7 @@ typedef struct telnetd #define TELNET_IAC 255 #define TELNET_ECHO 1 #define TELNET_SUPPRESS_GO_AHEAD 3 + +MXS_END_DECLS + #endif diff --git a/server/modules/monitor/auroramon/auroramon.c b/server/modules/monitor/auroramon/auroramon.c index 784a7bd96..81196ff39 100644 --- a/server/modules/monitor/auroramon/auroramon.c +++ b/server/modules/monitor/auroramon/auroramon.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include static char *version_str = (char*)"V1.0.0"; diff --git a/server/modules/monitor/galeramon/galeramon.c b/server/modules/monitor/galeramon/galeramon.c index 781b7e891..c3b96a68e 100644 --- a/server/modules/monitor/galeramon/galeramon.c +++ b/server/modules/monitor/galeramon/galeramon.c @@ -559,12 +559,12 @@ monitorMain(void *arg) /* * Let's select a master server: - * it could be the candidate master following MIN(node_id) rule or + * it could be the candidate master following MXS_MIN(node_id) rule or * the server that was master in the previous monitor polling cycle * Decision depends on master_stickiness value set in configuration */ - /* get the candidate master, following MIN(node_id) rule */ + /* get the candidate master, following MXS_MIN(node_id) rule */ candidate_master = get_candidate_master(mon); /* Select the master, based on master_stickiness */ @@ -656,7 +656,7 @@ monitorMain(void *arg) /** * get candidate master from all nodes * - * The current available rule: get the server with MIN(node_id) + * The current available rule: get the server with MXS_MIN(node_id) * node_id comes from 'wsrep_local_index' variable * * @param servers The monitored servers list diff --git a/server/modules/monitor/galeramon/galeramon.h b/server/modules/monitor/galeramon/galeramon.h index a9563e025..42a1c5198 100644 --- a/server/modules/monitor/galeramon/galeramon.h +++ b/server/modules/monitor/galeramon/galeramon.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _GALERAMON_H #define _GALERAMON_H /* @@ -13,6 +14,18 @@ * Public License. */ +/** + * @file galeramon.h - The Galera cluster monitor + * + * @verbatim + * Revision History + * + * Date Who Description + * 07/05/15 Markus Makela Initial Implementation of galeramon.h + * @endverbatim + */ + +#include #include #include #include @@ -29,16 +42,7 @@ #include #include -/** - * @file galeramon.h - The Galera cluster monitor - * - * @verbatim - * Revision History - * - * Date Who Description - * 07/05/15 Markus Makela Initial Implementation of galeramon.h - * @endverbatim - */ +MXS_BEGIN_DECLS /** * The handle for an instance of a Galera Monitor module @@ -59,4 +63,6 @@ typedef struct bool events[MAX_MONITOR_EVENT]; /*< enabled events */ } GALERA_MONITOR; +MXS_END_DECLS + #endif diff --git a/server/modules/monitor/mmmon/mmmon.h b/server/modules/monitor/mmmon/mmmon.h index 674672d89..f63aa221a 100644 --- a/server/modules/monitor/mmmon/mmmon.h +++ b/server/modules/monitor/mmmon/mmmon.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MMMON_H #define _MMMON_H /* @@ -13,6 +14,7 @@ * Public License. */ +#include #include #include #include @@ -33,6 +35,8 @@ * @file mmmon.h - The Multi-Master monitor */ +MXS_BEGIN_DECLS + /** * The handle for an instance of a Multi-Master Monitor module */ @@ -49,4 +53,6 @@ typedef struct bool events[MAX_MONITOR_EVENT]; /*< enabled events */ } MM_MONITOR; +MXS_END_DECLS + #endif diff --git a/server/modules/monitor/mysqlmon.h b/server/modules/monitor/mysqlmon.h index 357d1b235..3d56ad4f6 100644 --- a/server/modules/monitor/mysqlmon.h +++ b/server/modules/monitor/mysqlmon.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MYSQLMON_H #define _MYSQLMON_H /* @@ -13,23 +14,6 @@ * Public License. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - /** * @file mysqlmon.h - The MySQL monitor * @@ -50,6 +34,26 @@ * @endverbatim */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MXS_BEGIN_DECLS + #define MYSQLMON_DEFAULT_FAILCOUNT 5 /** @@ -80,4 +84,6 @@ typedef struct bool warn_failover; /**< Log a warning when failover happens */ } MYSQL_MONITOR; +MXS_END_DECLS + #endif diff --git a/server/modules/protocol/HTTPD/httpd.h b/server/modules/protocol/HTTPD/httpd.h index 0bc8096af..4131f3ccf 100644 --- a/server/modules/protocol/HTTPD/httpd.h +++ b/server/modules/protocol/HTTPD/httpd.h @@ -1,3 +1,6 @@ +#pragma once +#ifndef _HTTPD_H +#define _HTTPD_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -18,6 +21,7 @@ * 08-07-2013 Massimiliano Pinto Added HTTPD protocol header file */ +#include #include #include #include @@ -35,6 +39,8 @@ #include #include +MXS_BEGIN_DECLS + #define HTTPD_SMALL_BUFFER 1024 #define HTTPD_METHOD_MAXLEN 128 #define HTTPD_USER_MAXLEN 128 @@ -59,3 +65,7 @@ typedef struct httpd_session char *query_string; /*< the Query string, starts with ?, after path_info and document name */ int headers_received; /*< All the headers has been received, if 1 */ } HTTPD_session; + +MXS_END_DECLS + +#endif diff --git a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c index 30d763a12..be8a20909 100644 --- a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c +++ b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c @@ -12,7 +12,6 @@ */ #include -#include #include #include #include @@ -311,7 +310,7 @@ gw_do_connect_to_backend(char *host, int port, int *fd) if (so < 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Establishing connection to backend server " "%s:%d failed.\n\t\t Socket creation failed " "due %d, %s.", @@ -329,7 +328,7 @@ gw_do_connect_to_backend(char *host, int port, int *fd) if (setsockopt(so, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(bufsize)) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to set socket options " "%s:%d failed.\n\t\t Socket configuration failed " "due %d, %s.", @@ -346,7 +345,7 @@ gw_do_connect_to_backend(char *host, int port, int *fd) if (setsockopt(so, SOL_SOCKET, SO_RCVBUF, &bufsize, sizeof(bufsize)) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to set socket options " "%s:%d failed.\n\t\t Socket configuration failed " "due %d, %s.", @@ -363,7 +362,7 @@ gw_do_connect_to_backend(char *host, int port, int *fd) int one = 1; if (setsockopt(so, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to set socket options " "%s:%d failed.\n\t\t Socket configuration failed " "due %d, %s.", @@ -389,7 +388,7 @@ gw_do_connect_to_backend(char *host, int port, int *fd) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to connect backend server %s:%d, " "due %d, %s.", host, @@ -1058,7 +1057,7 @@ static int gw_error_backend_event(DCB *dcb) { if (error != 0) { - char errstring[STRERROR_BUFLEN]; + char errstring[MXS_STRERROR_BUFLEN]; MXS_ERROR("DCB in state %s got error '%s'.", STRDCBSTATE(dcb->state), strerror_r(error, errstring, sizeof(errstring))); @@ -1096,7 +1095,7 @@ static int gw_error_backend_event(DCB *dcb) { if (error != 0) { - char errstring[STRERROR_BUFLEN]; + char errstring[MXS_STRERROR_BUFLEN]; MXS_ERROR("Error '%s' in session that is not ready for routing.", strerror_r(error, errstring, sizeof(errstring))); } @@ -1200,7 +1199,7 @@ static int gw_backend_hangup(DCB *dcb) { if (error != 0 && ses_state != SESSION_STATE_STOPPING) { - char errstring[STRERROR_BUFLEN]; + char errstring[MXS_STRERROR_BUFLEN]; MXS_ERROR("Hangup in session that is not ready for routing, " "Error reported is '%s'.", strerror_r(error, errstring, sizeof(errstring))); @@ -1767,7 +1766,7 @@ close_socket(int sock) /*< Close newly created socket. */ if (close(sock) != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to close socket %d due %d, %s.", sock, errno, diff --git a/server/modules/protocol/MySQL/mysql_common.c b/server/modules/protocol/MySQL/mysql_common.c index 08fb31b6e..16ea18d81 100644 --- a/server/modules/protocol/MySQL/mysql_common.c +++ b/server/modules/protocol/MySQL/mysql_common.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -845,7 +844,7 @@ void init_response_status(GWBUF* buf, nparam = gw_mysql_get_byte2(readbuf); gwbuf_copy_data(buf, 11, 2, readbuf); nattr = gw_mysql_get_byte2(readbuf); - *npackets = 1 + nparam + MIN(1, nparam) + nattr + MIN(nattr, 1); + *npackets = 1 + nparam + MXS_MIN(1, nparam) + nattr + MXS_MIN(nattr, 1); break; case MYSQL_COM_QUIT: diff --git a/server/modules/protocol/maxscaled/maxscaled.c b/server/modules/protocol/maxscaled/maxscaled.c index 9e8e6d4d2..df8ef451c 100644 --- a/server/modules/protocol/maxscaled/maxscaled.c +++ b/server/modules/protocol/maxscaled/maxscaled.c @@ -162,7 +162,7 @@ static bool authenticate_socket(MAXSCALED *protocol, DCB *dcb) } else { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; MXS_ERROR("Could not get socket family of client connection: %s", strerror_r(errno, errbuf, sizeof(errbuf))); diff --git a/server/modules/protocol/maxscaled/maxscaled.h b/server/modules/protocol/maxscaled/maxscaled.h index 8dff6aedb..44af2e2aa 100644 --- a/server/modules/protocol/maxscaled/maxscaled.h +++ b/server/modules/protocol/maxscaled/maxscaled.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MAXSCALED_H #define _MAXSCALED_H /* @@ -27,6 +28,9 @@ #include #include #include + +MXS_BEGIN_DECLS + /** * The maxscaled specific protocol structure to put in the DCB. */ @@ -41,4 +45,6 @@ typedef struct maxscaled #define MAXSCALED_STATE_PASSWD 2 /**< Waiting for password */ #define MAXSCALED_STATE_DATA 3 /**< User logged in */ +MXS_END_DECLS + #endif diff --git a/server/modules/routing/avro/avro.c b/server/modules/routing/avro/avro.c index 8c6cb1807..794cb3d26 100644 --- a/server/modules/routing/avro/avro.c +++ b/server/modules/routing/avro/avro.c @@ -39,7 +39,6 @@ #include #include -#include #include #include @@ -412,7 +411,7 @@ createInstance(SERVICE *service, char **options) } else if (strcmp(options[i], "start_index") == 0) { - first_file = MAX(1, atoi(value)); + first_file = MXS_MAX(1, atoi(value)); } else { @@ -1038,7 +1037,7 @@ void converter_func(void* data) if (binlog_end == AVRO_LAST_FILE) { - router->task_delay = MIN(router->task_delay + 1, AVRO_TASK_DELAY_MAX); + router->task_delay = MXS_MIN(router->task_delay + 1, AVRO_TASK_DELAY_MAX); add_conversion_task(router); MXS_INFO("Stopped processing file %s at position %lu. Waiting until" " more data is written before continuing. Next check in %d seconds.", @@ -1061,7 +1060,7 @@ static bool ensure_dir_ok(const char* path, int mode) if (path) { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; char resolved[PATH_MAX + 1]; const char *rp = realpath(path, resolved); diff --git a/server/modules/routing/avro/avro_client.c b/server/modules/routing/avro/avro_client.c index 9a051728c..c72c34bce 100644 --- a/server/modules/routing/avro/avro_client.c +++ b/server/modules/routing/avro/avro_client.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -858,7 +857,7 @@ GWBUF* read_avro_json_schema(const char *avrofile, const char* dir) } else { - char err[STRERROR_BUFLEN]; + char err[MXS_STRERROR_BUFLEN]; MXS_ERROR("Failed to open file '%s': %d, %s", buffer, errno, strerror_r(errno, err, sizeof(err))); } diff --git a/server/modules/routing/avro/avro_file.c b/server/modules/routing/avro/avro_file.c index bce83ffc8..fcaab652e 100644 --- a/server/modules/routing/avro/avro_file.c +++ b/server/modules/routing/avro/avro_file.c @@ -40,6 +40,7 @@ #include #include #include +#include static const char *statefile_section = "avro-conversion"; static const char *ddl_list_name = "table-ddl.list"; @@ -160,7 +161,7 @@ bool avro_save_conversion_state(AVRO_INSTANCE *router) { FILE *config_file; char filename[PATH_MAX + 1]; - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; snprintf(filename, sizeof(filename), "%s/"AVRO_PROGRESS_FILE".tmp", router->avrodir); @@ -419,7 +420,7 @@ static GWBUF* read_event_data(AVRO_INSTANCE *router, REP_HEADER* hdr, uint64_t p { if (n == -1) { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; MXS_ERROR("Error reading the event at %lu in %s. " "%s, expected %d bytes.", pos, router->binlog_name, diff --git a/server/modules/routing/avro/avro_index.c b/server/modules/routing/avro/avro_index.c index 70acf2353..d4510fb03 100644 --- a/server/modules/routing/avro/avro_index.c +++ b/server/modules/routing/avro/avro_index.c @@ -33,7 +33,7 @@ */ #include "avrorouter.h" -#include +#include #include void* safe_key_free(void *data); diff --git a/server/modules/routing/avro/avro_rbr.c b/server/modules/routing/avro/avro_rbr.c index a64927290..38dd47655 100644 --- a/server/modules/routing/avro/avro_rbr.c +++ b/server/modules/routing/avro/avro_rbr.c @@ -523,7 +523,7 @@ uint8_t* process_row_event_data(TABLE_MAP *map, TABLE_CREATE *create, avro_value { uint64_t value = 0; int width = metadata[metadata_offset] + metadata[metadata_offset + 1] * 8; - int bits_in_nullmap = MIN(width, extra_bits); + int bits_in_nullmap = MXS_MIN(width, extra_bits); extra_bits -= bits_in_nullmap; width -= bits_in_nullmap; size_t bytes = width / 8; diff --git a/server/modules/routing/avro/avro_schema.c b/server/modules/routing/avro/avro_schema.c index fdf48448a..f4172d689 100644 --- a/server/modules/routing/avro/avro_schema.c +++ b/server/modules/routing/avro/avro_schema.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/modules/routing/avro/avrorouter.h b/server/modules/routing/avro/avrorouter.h index 21812bf22..63147af7d 100644 --- a/server/modules/routing/avro/avrorouter.h +++ b/server/modules/routing/avro/avrorouter.h @@ -1,3 +1,6 @@ +#pragma once +#ifndef _MXS_AVRO_H +#define _MXS_AVRO_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -15,8 +18,7 @@ * MaxScale AVRO router * */ -#ifndef _MXS_AVRO_H -#define _MXS_AVRO_H +#include #include #include #include @@ -35,6 +37,8 @@ #include #include +MXS_BEGIN_DECLS + /** SQLite3 version 3.7.14 introduced the new v2 close interface */ #if SQLITE_VERSION_NUMBER < 3007014 #define sqlite3_close_v2 sqlite3_close @@ -312,4 +316,6 @@ extern void table_map_remap(uint8_t *ptr, uint8_t hdr_len, TABLE_MAP *map); #define AVRO_CS_BUSY 0x0001 #define AVRO_WAIT_DATA 0x0002 +MXS_END_DECLS + #endif diff --git a/server/modules/routing/binlog/blr.c b/server/modules/routing/binlog/blr.c index 7cf9d9448..914a4cc66 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -72,7 +72,6 @@ #include #include -#include #include #include @@ -570,7 +569,7 @@ createInstance(SERVICE *service, char **options) mkdir_rval = mkdir(inst->binlogdir, 0700); if (mkdir_rval == -1) { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; MXS_ERROR("Service %s, Failed to create binlog directory '%s': [%d] %s", service->name, inst->binlogdir, @@ -1631,7 +1630,7 @@ errorReply(ROUTER *instance, ROUTER_INSTANCE *router = (ROUTER_INSTANCE *)instance; int error; socklen_t len; - char msg[STRERROR_BUFLEN + 1 + 5] = ""; + char msg[MXS_STRERROR_BUFLEN + 1 + 5] = ""; char *errmsg; unsigned long mysql_errno; @@ -1691,7 +1690,7 @@ errorReply(ROUTER *instance, getsockopt(router->master->fd, SOL_SOCKET, SO_ERROR, &error, &len) == 0 && error != 0) { - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; sprintf(msg, "%s ", strerror_r(error, errbuf, sizeof(errbuf))); } else diff --git a/server/modules/routing/binlog/blr.h b/server/modules/routing/binlog/blr.h index cc85628e1..9b88a18c0 100644 --- a/server/modules/routing/binlog/blr.h +++ b/server/modules/routing/binlog/blr.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _BLR_H #define _BLR_H /* @@ -38,6 +39,8 @@ * * @endverbatim */ + +#include #include #include #include @@ -48,6 +51,8 @@ #include #include +MXS_BEGIN_DECLS + #define BINLOG_FNAMELEN 255 #define BLR_PROTOCOL "MySQLBackend" #define BINLOG_MAGIC { 0xfe, 0x62, 0x69, 0x6e } @@ -705,4 +710,6 @@ extern bool blr_send_event(blr_thread_role_t role, REP_HEADER *hdr, uint8_t *buf); +MXS_END_DECLS + #endif diff --git a/server/modules/routing/binlog/blr_cache.c b/server/modules/routing/binlog/blr_cache.c index 3e6e5768d..9501f0f92 100644 --- a/server/modules/routing/binlog/blr_cache.c +++ b/server/modules/routing/binlog/blr_cache.c @@ -43,7 +43,6 @@ #include #include -#include #include #include diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index f5d61ca75..063e97953 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -59,7 +59,6 @@ #include #include #include -#include #include #include #include @@ -288,7 +287,7 @@ blr_file_create(ROUTER_INSTANCE *router, char *file) } int created = 0; - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; char path[PATH_MAX + 1] = ""; @@ -428,7 +427,7 @@ blr_write_binlog_record(ROUTER_INSTANCE *router, REP_HEADER *hdr, uint32_t size, if ((n = pwrite(router->binlog_fd, buf, size, router->last_written)) != size) { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; MXS_ERROR("%s: Failed to write binlog record at %lu of %s, %s. " "Truncating to previous record.", router->service->name, router->last_written, @@ -658,7 +657,7 @@ blr_read_binlog(ROUTER_INSTANCE *router, BLFILE *file, unsigned long pos, REP_HE break; case -1: { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; snprintf(errmsg, BINLOG_ERROR_MSG_LEN, "Failed to read binlog file '%s'; (%s), event at %lu", file->binlogname, strerror_r(errno, err_msg, sizeof(err_msg)), pos); @@ -741,7 +740,7 @@ blr_read_binlog(ROUTER_INSTANCE *router, BLFILE *file, unsigned long pos, REP_HE break; case -1: { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; snprintf(errmsg, BINLOG_ERROR_MSG_LEN, "Failed to reread header in binlog file '%s'; (%s), event at %lu", file->binlogname, strerror_r(errno, err_msg, sizeof(err_msg)), pos); @@ -801,7 +800,7 @@ blr_read_binlog(ROUTER_INSTANCE *router, BLFILE *file, unsigned long pos, REP_HE { if (n == -1) { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; snprintf(errmsg, BINLOG_ERROR_MSG_LEN, "Error reading the binlog event at %lu in binlog file '%s';" "(%s), expected %d bytes.", @@ -2053,7 +2052,7 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error) char filename[len + sizeof('/') + sizeof(MASTER_INI)]; // sizeof includes NULL char tmp_file[len + sizeof('/') + sizeof(MASTER_INI) + sizeof('.') + sizeof(TMP)]; - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; char *ssl_ca; char *ssl_cert; char *ssl_key; diff --git a/server/modules/routing/binlog/blr_master.c b/server/modules/routing/binlog/blr_master.c index c96c30a70..7b02a66e3 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -69,7 +69,6 @@ #include #include -#include #include #include @@ -1292,7 +1291,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt) if (router->master_chksum) { - uint32_t size = MIN(len - extra_bytes - semisync_bytes, + uint32_t size = MXS_MIN(len - extra_bytes - semisync_bytes, router->checksum_size); router->stored_checksum = crc32(router->stored_checksum, @@ -1343,7 +1342,7 @@ blr_handle_binlog_record(ROUTER_INSTANCE *router, GWBUF *pkt) size = len - (check_packet_len + MYSQL_CHECKSUM_LEN); } - size = MIN(size, router->checksum_size); + size = MXS_MIN(size, router->checksum_size); if (router->checksum_size > 0) { @@ -2455,7 +2454,7 @@ GWBUF break; case -1: { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; MXS_ERROR("Reading saved events: failed to read binlog " "file %s at position %llu" " (%s).", router->binlog_name, @@ -2515,7 +2514,7 @@ GWBUF { if (n == -1) { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; MXS_ERROR("Reading saved events: the event at %llu in %s. " "%s, expected %d bytes.", pos, router->binlog_name, @@ -2807,7 +2806,7 @@ blr_write_data_into_binlog(ROUTER_INSTANCE *router, uint32_t data_len, uint8_t * if ((n = pwrite(router->binlog_fd, buf, data_len, router->last_written)) != data_len) { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; MXS_ERROR("%s: Failed to write binlog record at %lu of %s, %s. " "Truncating to previous record.", router->service->name, router->last_written, @@ -2935,7 +2934,7 @@ bool blr_send_event(blr_thread_role_t role, while (rval && len > 0) { uint64_t payload_len = first ? MYSQL_PACKET_LENGTH_MAX - 1 : - MIN(MYSQL_PACKET_LENGTH_MAX, len); + MXS_MIN(MYSQL_PACKET_LENGTH_MAX, len); if (blr_send_packet(slave, buf, payload_len, first)) { diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 84841c04e..5e2e89751 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -81,7 +81,6 @@ #include #include #include -#include #include #include #include @@ -877,7 +876,7 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue) if (removed_cfg == -1) { - char err_msg[STRERROR_BUFLEN]; + char err_msg[MXS_STRERROR_BUFLEN]; snprintf(error_string, BINLOG_ERROR_MSG_LEN, "Error removing %s, %s, errno %u", path, strerror_r(errno, err_msg, sizeof(err_msg)), errno); diff --git a/server/modules/routing/binlog/test/testbinlog.c b/server/modules/routing/binlog/test/testbinlog.c index a9e3e2373..f55d038c9 100644 --- a/server/modules/routing/binlog/test/testbinlog.c +++ b/server/modules/routing/binlog/test/testbinlog.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include diff --git a/server/modules/routing/cli/cli.c b/server/modules/routing/cli/cli.c index e5a88e759..948cebc6a 100644 --- a/server/modules/routing/cli/cli.c +++ b/server/modules/routing/cli/cli.c @@ -272,7 +272,7 @@ execute(ROUTER *instance, void *router_session, GWBUF *queue) { const char* data = GWBUF_DATA(queue); int len = GWBUF_LENGTH(queue); - int n = MIN(len, CMDBUFLEN - cmdlen - 1); + int n = MXS_MIN(len, CMDBUFLEN - cmdlen - 1); if (n != len) { diff --git a/server/modules/routing/debugcli/debugcli.c b/server/modules/routing/debugcli/debugcli.c index 26208b328..c360f2da4 100644 --- a/server/modules/routing/debugcli/debugcli.c +++ b/server/modules/routing/debugcli/debugcli.c @@ -293,7 +293,7 @@ execute(ROUTER *instance, void *router_session, GWBUF *queue) { const char* data = GWBUF_DATA(queue); int len = GWBUF_LENGTH(queue); - int n = MIN(len, CMDBUFLEN - cmdlen - 1); + int n = MXS_MIN(len, CMDBUFLEN - cmdlen - 1); if (n != len) { diff --git a/server/modules/routing/debugcli/debugcmd.c b/server/modules/routing/debugcli/debugcmd.c index 247f69f87..b5d3d1d4c 100644 --- a/server/modules/routing/debugcli/debugcmd.c +++ b/server/modules/routing/debugcli/debugcmd.c @@ -1051,7 +1051,7 @@ execute_cmd(CLI_SESSION *cli) } } *lptr = 0; - args[MIN(MAXARGS - 1, i + 1)] = NULL; + args[MXS_MIN(MAXARGS - 1, i + 1)] = NULL; if (args[0] == NULL || *args[0] == 0) { @@ -1964,9 +1964,9 @@ static void fail_accept( char* arg1, char* arg2) { - int failcount = MIN(atoi(arg2), 100); + int failcount = MXS_MIN(atoi(arg2), 100); fail_accept_errno = atoi(arg1); - char errbuf[STRERROR_BUFLEN]; + char errbuf[MXS_STRERROR_BUFLEN]; switch(fail_accept_errno) { case EAGAIN: diff --git a/server/modules/routing/maxinfo/maxinfo.h b/server/modules/routing/maxinfo/maxinfo.h index 08fa63f24..4e42292ae 100644 --- a/server/modules/routing/maxinfo/maxinfo.h +++ b/server/modules/routing/maxinfo/maxinfo.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _MAXINFO_H #define _MAXINFO_H /* @@ -12,9 +13,6 @@ * of this software will be governed by version 2 or later of the General * Public License. */ -#include -#include -#include /** * @file maxinfo.h The MaxScale information schema provider @@ -27,6 +25,14 @@ * * @endverbatim */ + +#include +#include +#include +#include + +MXS_BEGIN_DECLS + struct maxinfo_session; /** @@ -138,4 +144,7 @@ extern void maxinfo_send_parse_error(DCB *, char *, PARSE_ERROR); extern void maxinfo_send_error(DCB *, int, char *); extern RESULTSET *maxinfo_variables(); extern RESULTSET *maxinfo_status(); + +MXS_END_DECLS + #endif diff --git a/server/modules/routing/maxinfo/maxinfo_parse.c b/server/modules/routing/maxinfo/maxinfo_parse.c index 5fd8bfe05..ccf3aea7a 100644 --- a/server/modules/routing/maxinfo/maxinfo_parse.c +++ b/server/modules/routing/maxinfo/maxinfo_parse.c @@ -23,6 +23,8 @@ * * @endverbatim */ + +#include #include #include #include diff --git a/server/modules/routing/readconnroute/readconnection.h b/server/modules/routing/readconnroute/readconnection.h index 3fcbcb5d9..e832b9c2e 100644 --- a/server/modules/routing/readconnroute/readconnection.h +++ b/server/modules/routing/readconnroute/readconnection.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _READCONNECTION_H #define _READCONNECTION_H /* @@ -25,8 +26,12 @@ * * @endverbatim */ + +#include #include +MXS_BEGIN_DECLS + /** * Internal structure used to define the set of backend servers we are routing * connections to. This provides the storage for routing module specific data @@ -84,4 +89,7 @@ typedef struct router_instance struct router_instance *next; } ROUTER_INSTANCE; + +MXS_END_DECLS + #endif diff --git a/server/modules/routing/readconnroute/readconnroute.c b/server/modules/routing/readconnroute/readconnroute.c index c55a82fe8..bbb7d55b6 100644 --- a/server/modules/routing/readconnroute/readconnroute.c +++ b/server/modules/routing/readconnroute/readconnroute.c @@ -84,7 +84,6 @@ #include #include -#include #include #include diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 347ce8d15..7d9b8f3e4 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -559,7 +559,7 @@ static void *newSession(ROUTER *router_inst, SESSION *session) { int n_conn = 0; double pct = (double)client_rses->rses_config.rw_max_slave_conn_percent / 100.0; - n_conn = MAX(floor((double)client_rses->rses_nbackends * pct), 1); + n_conn = MXS_MAX(floor((double)client_rses->rses_nbackends * pct), 1); client_rses->rses_config.rw_max_slave_conn_count = n_conn; } @@ -1294,7 +1294,7 @@ int rses_get_max_slavecount(ROUTER_CLIENT_SES *rses, { conf_max_nslaves = (router_nservers * rses->rses_config.rw_max_slave_conn_percent) / 100; } - max_nslaves = MIN(router_nservers - 1, MAX(1, conf_max_nslaves)); + max_nslaves = MXS_MIN(router_nservers - 1, MXS_MAX(1, conf_max_nslaves)); return max_nslaves; } @@ -1897,7 +1897,7 @@ static bool have_enough_servers(ROUTER_CLIENT_SES **p_rses, const int min_nsrv, /** With too few servers session is not created */ if (router_nsrv < min_nsrv || - MAX((*p_rses)->rses_config.rw_max_slave_conn_count, + MXS_MAX((*p_rses)->rses_config.rw_max_slave_conn_count, (router_nsrv * (*p_rses)->rses_config.rw_max_slave_conn_percent) / 100) < min_nsrv) { diff --git a/server/modules/routing/readwritesplit/readwritesplit.h b/server/modules/routing/readwritesplit/readwritesplit.h index 3787155c0..98020b667 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.h +++ b/server/modules/routing/readwritesplit/readwritesplit.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _RWSPLITROUTER_H #define _RWSPLITROUTER_H /* @@ -24,10 +25,13 @@ * @endverbatim */ +#include #include #include #include +MXS_BEGIN_DECLS + #undef PREP_STMT_CACHING #if defined(PREP_STMT_CACHING) @@ -356,5 +360,6 @@ typedef struct router_instance #define BACKEND_TYPE(b) (SERVER_IS_MASTER((b)->backend_server) ? BE_MASTER : \ (SERVER_IS_SLAVE((b)->backend_server) ? BE_SLAVE : BE_UNDEFINED)); +MXS_END_DECLS #endif /*< _RWSPLITROUTER_H */ diff --git a/server/modules/routing/readwritesplit/rwsplit_internal.h b/server/modules/routing/readwritesplit/rwsplit_internal.h index b17048eae..cbaaa979b 100644 --- a/server/modules/routing/readwritesplit/rwsplit_internal.h +++ b/server/modules/routing/readwritesplit/rwsplit_internal.h @@ -1,3 +1,6 @@ +#pragma once +#ifndef _RWSPLIT_INTERNAL_H +#define _RWSPLIT_INTERNAL_H /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -18,15 +21,11 @@ * Created on 08 August 2016, 11:54 */ -#ifndef RWSPLIT_INTERNAL_H -#define RWSPLIT_INTERNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - +#include #include - + +MXS_BEGIN_DECLS + /* This needs to be removed along with dependency on it - see the * rwsplit_tmp_table_multi functions */ @@ -145,5 +144,7 @@ qc_query_type_t determine_query_type(GWBUF *querybuf, int packet_type, bool non_ } #endif +MXS_END_DECLS + #endif /* RWSPLIT_INTERNAL_H */ diff --git a/server/modules/routing/readwritesplit/rwsplit_mysql.c b/server/modules/routing/readwritesplit/rwsplit_mysql.c index 4397f9a11..aa7050dcd 100644 --- a/server/modules/routing/readwritesplit/rwsplit_mysql.c +++ b/server/modules/routing/readwritesplit/rwsplit_mysql.c @@ -163,10 +163,10 @@ log_transaction_status(ROUTER_CLIENT_SES *rses, GWBUF *querybuf, qc_query_type_t { uint8_t *packet = GWBUF_DATA(querybuf); unsigned char ptype = packet[4]; - size_t len = MIN(GWBUF_LENGTH(querybuf), + size_t len = MXS_MIN(GWBUF_LENGTH(querybuf), MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start) - 1); char *data = (char *)&packet[5]; - char *contentstr = strndup(data, MIN(len, RWSPLIT_TRACE_MSG_LEN)); + char *contentstr = strndup(data, MXS_MIN(len, RWSPLIT_TRACE_MSG_LEN)); char *qtypestr = qc_get_qtype_str(qtype); MXS_INFO("> Autocommit: %s, trx is %s, cmd: %s, type: %s, stmt: %s%s %s", (rses->rses_autocommit_enabled ? "[enabled]" : "[disabled]"), diff --git a/server/modules/routing/schemarouter/schemarouter.c b/server/modules/routing/schemarouter/schemarouter.c index 3ed3ba191..551841b5a 100644 --- a/server/modules/routing/schemarouter/schemarouter.c +++ b/server/modules/routing/schemarouter/schemarouter.c @@ -2004,7 +2004,7 @@ static int routeQuery(ROUTER* instance, { uint8_t* packet = GWBUF_DATA(querybuf); unsigned char ptype = packet[4]; - size_t len = MIN(GWBUF_LENGTH(querybuf), + size_t len = MXS_MIN(GWBUF_LENGTH(querybuf), MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start) - 1); char* data = (char*)&packet[5]; char* contentstr = strndup(data, len); diff --git a/server/modules/routing/schemarouter/schemarouter.h b/server/modules/routing/schemarouter/schemarouter.h index 17a30729d..88dd01eda 100644 --- a/server/modules/routing/schemarouter/schemarouter.h +++ b/server/modules/routing/schemarouter/schemarouter.h @@ -1,3 +1,4 @@ +#pragma once #ifndef _SCHEMAROUTER_H #define _SCHEMAROUTER_H /* @@ -23,14 +24,15 @@ * * @endverbatim */ -#ifndef PCRE2_CODE_UNIT_WIDTH -#define PCRE2_CODE_UNIT_WIDTH 8 -#endif +#include #include #include #include -#include +#include + +MXS_BEGIN_DECLS + /** * Bitmask values for the router session's initialization. These values are used * to prevent responses from internal commands being forwarded to the client. @@ -377,4 +379,6 @@ typedef struct router_instance #define BACKEND_TYPE(b) (SERVER_IS_MASTER((b)->backend_server) ? BE_MASTER : \ (SERVER_IS_SLAVE((b)->backend_server) ? BE_SLAVE : BE_UNDEFINED)); +MXS_END_DECLS + #endif /*< _SCHEMAROUTER_H */ diff --git a/server/modules/routing/schemarouter/sharding_common.h b/server/modules/routing/schemarouter/sharding_common.h index f4fb06307..de215b7a5 100644 --- a/server/modules/routing/schemarouter/sharding_common.h +++ b/server/modules/routing/schemarouter/sharding_common.h @@ -1,3 +1,6 @@ +#pragma once +#ifndef _SHARDING_COMMON_HG +#define _SHARDING_COMMON_HG /* * Copyright (c) 2016 MariaDB Corporation Ab * @@ -11,9 +14,7 @@ * Public License. */ -#ifndef _SHARDING_COMMON_HG -#define _SHARDING_COMMON_HG - +#include #include #include #include @@ -23,8 +24,12 @@ #include #include +MXS_BEGIN_DECLS + bool extract_database(GWBUF* buf, char* str); void create_error_reply(char* fail_str, DCB* dcb); bool change_current_db(char* dest, HASHTABLE* dbhash, GWBUF* buf); +MXS_END_DECLS + #endif