From 03dbc6df807197356abe4c5ad25627b5ff0cbfee Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 14 Oct 2016 15:38:16 +0300 Subject: [PATCH] Remove dependency on skygw_utils.h - STRERROR_BUFLEN moved to cdefs.h and renamed to MXS_STRERROR_BUFLEN. Better would be to provide a 'const char* mxs_strerror(int errno)' that would have a thread specific buffer for the error message. - MIN and MAX also moved to defs.h as MXS_MIN and MXS_MAX. - Now only mlist.h of the headers depend upon skygw_utils.h. --- avro/maxavro_record.c | 4 +- include/maxscale/cdefs.h | 38 ++++++++++++ include/maxscale/config.h | 1 - include/maxscale/dcb.h | 1 - include/maxscale/externcmd.h | 1 - include/maxscale/gwdirs.h.in | 1 - include/maxscale/log_manager.h | 7 --- include/maxscale/query_classifier.h | 1 - include/maxscale/session.h | 1 - include/maxscale/skygw_utils.h | 13 ---- include/maxscale/slist.h | 2 +- .../test/canonical_tests/canonizer.c | 1 + server/core/buffer.c | 4 +- server/core/config.c | 4 +- server/core/dcb.c | 48 +++++++-------- server/core/externcmd.c | 2 +- server/core/gateway.c | 28 ++++----- server/core/gw_utils.c | 4 +- server/core/log_manager.cc | 12 ++-- server/core/modutil.c | 5 +- server/core/poll.c | 12 ++-- server/core/query_classifier.c | 1 + server/core/secrets.c | 26 ++++---- server/core/service.c | 2 +- server/core/skygw_utils.cc | 60 +++++++++---------- server/core/test/testadminusers.c | 2 +- server/core/test/testpoll.c | 2 +- server/core/utils.c | 8 +-- server/modules/filter/cache/rules.c | 2 +- .../storage/storage_rocksdb/rocksdbstorage.cc | 2 +- server/modules/filter/dbfwfilter/dbfwfilter.c | 6 +- server/modules/filter/gatekeeper/gatekeeper.c | 12 ++-- server/modules/filter/qlafilter/qlafilter.c | 4 +- server/modules/monitor/galeramon/galeramon.c | 6 +- .../MySQL/MySQLBackend/mysql_backend.c | 18 +++--- server/modules/protocol/MySQL/mysql_common.c | 2 +- server/modules/protocol/maxscaled/maxscaled.c | 2 +- server/modules/routing/avro/avro.c | 6 +- server/modules/routing/avro/avro_client.c | 2 +- server/modules/routing/avro/avro_file.c | 5 +- server/modules/routing/avro/avro_rbr.c | 2 +- server/modules/routing/binlog/blr.c | 6 +- server/modules/routing/binlog/blr_file.c | 12 ++-- server/modules/routing/binlog/blr_master.c | 12 ++-- server/modules/routing/binlog/blr_slave.c | 2 +- server/modules/routing/cli/cli.c | 2 +- server/modules/routing/debugcli/debugcli.c | 2 +- server/modules/routing/debugcli/debugcmd.c | 6 +- .../routing/readwritesplit/readwritesplit.c | 6 +- .../routing/readwritesplit/rwsplit_mysql.c | 4 +- .../routing/schemarouter/schemarouter.c | 2 +- 51 files changed, 215 insertions(+), 199 deletions(-) diff --git a/avro/maxavro_record.c b/avro/maxavro_record.c index 1d0e70479..07a6de119 100644 --- a/avro/maxavro_record.c +++ b/avro/maxavro_record.c @@ -11,8 +11,8 @@ * Public License. */ +#include #include "maxavro.h" -#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/include/maxscale/cdefs.h b/include/maxscale/cdefs.h index ed7de8ba7..62c28b328 100644 --- a/include/maxscale/cdefs.h +++ b/include/maxscale/cdefs.h @@ -35,4 +35,42 @@ # 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 ba4c374a4..128a906eb 100644 --- a/include/maxscale/config.h +++ b/include/maxscale/config.h @@ -31,7 +31,6 @@ */ #include -#include #include #include #include diff --git a/include/maxscale/dcb.h b/include/maxscale/dcb.h index 8ef080523..5b08e377c 100644 --- a/include/maxscale/dcb.h +++ b/include/maxscale/dcb.h @@ -56,7 +56,6 @@ #include #include #include -#include #include MXS_BEGIN_DECLS diff --git a/include/maxscale/externcmd.h b/include/maxscale/externcmd.h index ed0a90f48..36efeb544 100644 --- a/include/maxscale/externcmd.h +++ b/include/maxscale/externcmd.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/include/maxscale/gwdirs.h.in b/include/maxscale/gwdirs.h.in index 39e55b0b2..a782c30d2 100644 --- a/include/maxscale/gwdirs.h.in +++ b/include/maxscale/gwdirs.h.in @@ -20,7 +20,6 @@ #include #include #include -#include MXS_BEGIN_DECLS diff --git a/include/maxscale/log_manager.h b/include/maxscale/log_manager.h index 357706c8f..e47d37509 100644 --- a/include/maxscale/log_manager.h +++ b/include/maxscale/log_manager.h @@ -21,13 +21,6 @@ MXS_BEGIN_DECLS -/* - * We need a common.h file that is included by every component. - */ -#if !defined(STRERROR_BUFLEN) -#define STRERROR_BUFLEN 512 -#endif - /** * If MXS_MODULE_NAME is defined before log_manager.h is included, then all * logged messages will be prefixed with that string enclosed in square brackets. diff --git a/include/maxscale/query_classifier.h b/include/maxscale/query_classifier.h index 4ea60e365..f53b6a1ca 100644 --- a/include/maxscale/query_classifier.h +++ b/include/maxscale/query_classifier.h @@ -15,7 +15,6 @@ */ #include -#include #include MXS_BEGIN_DECLS diff --git a/include/maxscale/session.h b/include/maxscale/session.h index 988fb9efd..c688e6149 100644 --- a/include/maxscale/session.h +++ b/include/maxscale/session.h @@ -42,7 +42,6 @@ #include #include #include -#include #include MXS_BEGIN_DECLS diff --git a/include/maxscale/skygw_utils.h b/include/maxscale/skygw_utils.h index 50c238546..e21a41afa 100644 --- a/include/maxscale/skygw_utils.h +++ b/include/maxscale/skygw_utils.h @@ -18,19 +18,6 @@ MXS_BEGIN_DECLS -/* - * We need a common.h file that is included by every component. - */ -#if !defined(STRERROR_BUFLEN) -#define STRERROR_BUFLEN 512 -#endif - -#ifndef MIN -#define MIN(a,b) (ab ? a : b) -#endif #define FSYNCLIMIT 10 #include diff --git a/include/maxscale/slist.h b/include/maxscale/slist.h index 93e43afd7..995e32cee 100644 --- a/include/maxscale/slist.h +++ b/include/maxscale/slist.h @@ -15,7 +15,7 @@ */ #include -#include +#include MXS_BEGIN_DECLS 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/buffer.c b/server/core/buffer.c index a8cd8a377..cf25bdb08 100644 --- a/server/core/buffer.c +++ b/server/core/buffer.c @@ -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 d4fa6bcbb..37264e19d 100644 --- a/server/core/externcmd.c +++ b/server/core/externcmd.c @@ -171,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 ebf893bc8..2a19fbf50 100644 --- a/server/core/log_manager.cc +++ b/server/core/log_manager.cc @@ -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/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/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/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 137324ea8..cc908b90f 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -383,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 6c6566c47..8b1142edd 100644 --- a/server/core/skygw_utils.cc +++ b/server/core/skygw_utils.cc @@ -58,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))); @@ -77,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))); @@ -95,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))); } @@ -108,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; @@ -120,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))); } @@ -152,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; @@ -204,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); @@ -245,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); @@ -350,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; @@ -526,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 : "); @@ -566,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; @@ -613,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 : "); @@ -642,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 : "); @@ -676,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); @@ -687,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); @@ -716,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))); } @@ -725,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))); } @@ -743,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; @@ -757,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))); } @@ -765,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))); } @@ -783,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))); } @@ -795,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))); } @@ -805,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))); } @@ -821,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; @@ -832,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; @@ -934,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); @@ -958,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); @@ -994,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))); } @@ -1170,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; @@ -1183,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/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/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/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/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/dbfwfilter/dbfwfilter.c b/server/modules/filter/dbfwfilter/dbfwfilter.c index 8ba47775c..cebe94df1 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter/dbfwfilter.c @@ -1173,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); @@ -1343,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))); @@ -2240,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/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/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/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/protocol/MySQL/MySQLBackend/mysql_backend.c b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c index fa1b05141..be8a20909 100644 --- a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c +++ b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c @@ -310,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.", @@ -328,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.", @@ -345,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.", @@ -362,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.", @@ -388,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, @@ -1057,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))); @@ -1095,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))); } @@ -1199,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))); @@ -1766,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 77a827967..16ea18d81 100644 --- a/server/modules/protocol/MySQL/mysql_common.c +++ b/server/modules/protocol/MySQL/mysql_common.c @@ -844,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/routing/avro/avro.c b/server/modules/routing/avro/avro.c index 5e5da7926..794cb3d26 100644 --- a/server/modules/routing/avro/avro.c +++ b/server/modules/routing/avro/avro.c @@ -411,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 { @@ -1037,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.", @@ -1060,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 2c2936f20..c72c34bce 100644 --- a/server/modules/routing/avro/avro_client.c +++ b/server/modules/routing/avro/avro_client.c @@ -857,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_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/binlog/blr.c b/server/modules/routing/binlog/blr.c index 30b17dfb3..a781cb9bb 100644 --- a/server/modules/routing/binlog/blr.c +++ b/server/modules/routing/binlog/blr.c @@ -568,7 +568,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, @@ -1628,7 +1628,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; @@ -1688,7 +1688,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_file.c b/server/modules/routing/binlog/blr_file.c index 342f64990..0db05df59 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -244,7 +244,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] = ""; @@ -366,7 +366,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, @@ -594,7 +594,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); @@ -677,7 +677,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); @@ -737,7 +737,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.", @@ -1906,7 +1906,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 e3de00ebb..7b02a66e3 100644 --- a/server/modules/routing/binlog/blr_master.c +++ b/server/modules/routing/binlog/blr_master.c @@ -1291,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, @@ -1342,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) { @@ -2454,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, @@ -2514,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, @@ -2806,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, @@ -2934,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 4650053d7..6d4904b18 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -874,7 +874,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/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/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/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);