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.
This commit is contained in:
Johan Wikman
2016-10-14 15:38:16 +03:00
parent bff2cfb7e5
commit 03dbc6df80
51 changed files with 215 additions and 199 deletions

View File

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

View File

@ -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)));
}

View File

@ -40,6 +40,7 @@
#include <stdlib.h>
#include <glob.h>
#include <maxscale/alloc.h>
#include <maxscale/skygw_utils.h>
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,

View File

@ -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;

View File

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

View File

@ -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;

View File

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

View File

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

View File

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

View File

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

View File

@ -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:

View File

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

View File

@ -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]"),

View File

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