Added strerror_r and new constants
Added strerror_r and new constants
This commit is contained in:
@ -164,6 +164,18 @@
|
||||
/* string len for COM_STATISTICS output */
|
||||
#define BLRM_COM_STATISTICS_SIZE 1000
|
||||
|
||||
/* string len for strerror_r message */
|
||||
#define BLRM_STRERROR_R_MSG_SIZE 128
|
||||
|
||||
/* string len for task message name */
|
||||
#define BLRM_TASK_NAME_LEN 80
|
||||
|
||||
/* string len for temp binlog filename */
|
||||
#define BLRM_BINLOG_NAME_STR_LEN 80
|
||||
|
||||
/* string len for temp binlog filename */
|
||||
#define BLRM_SET_HEARTBEAT_QUERY_LEN 80
|
||||
|
||||
/**
|
||||
* Some useful macros for examining the MySQL Response packets
|
||||
*/
|
||||
|
@ -45,6 +45,7 @@
|
||||
* master_uuid, master_hostname, master_version
|
||||
* If set those values are sent to slaves instead of
|
||||
* saved master responses
|
||||
* 23/08/2015 Massimiliano Pinto Added strerror_r
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -192,13 +193,14 @@ static ROUTER *
|
||||
createInstance(SERVICE *service, char **options)
|
||||
{
|
||||
ROUTER_INSTANCE *inst;
|
||||
char *value, *name;
|
||||
char *value;
|
||||
int i;
|
||||
unsigned char *defuuid;
|
||||
char path[PATH_MAX+1] = "";
|
||||
char filename[PATH_MAX+1] = "";
|
||||
int master_info = 0;
|
||||
int rc = 0;
|
||||
char task_name[BLRM_TASK_NAME_LEN+1] = "";
|
||||
|
||||
if(service->credentials.name == NULL ||
|
||||
service->credentials.authdata == NULL)
|
||||
@ -491,12 +493,14 @@ int rc = 0;
|
||||
int mkdir_rval;
|
||||
mkdir_rval = mkdir(inst->binlogdir, 0700);
|
||||
if (mkdir_rval == -1) {
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"Error : Service %s, Failed to create binlog directory '%s': [%d] %s",
|
||||
service->name,
|
||||
inst->binlogdir,
|
||||
errno,
|
||||
strerror(errno));
|
||||
err_msg);
|
||||
|
||||
free(inst);
|
||||
return NULL;
|
||||
@ -634,12 +638,11 @@ int rc = 0;
|
||||
*/
|
||||
blr_init_cache(inst);
|
||||
|
||||
if ((name = (char *)malloc(80)) != NULL)
|
||||
{
|
||||
sprintf(name, "%s stats", service->name);
|
||||
hktask_add(name, stats_func, inst, BLR_STATS_FREQ);
|
||||
free(name);
|
||||
}
|
||||
/*
|
||||
* Add tasks for statistic computation
|
||||
*/
|
||||
snprintf(task_name, BLRM_TASK_NAME_LEN, "%s stats", service->name);
|
||||
hktask_add(task_name, stats_func, inst, BLR_STATS_FREQ);
|
||||
|
||||
/* Log whether the transaction safety option value is on*/
|
||||
if (inst->trx_safe) {
|
||||
@ -1312,7 +1315,8 @@ errorReply(ROUTER *instance, void *router_session, GWBUF *message, DCB *backend_
|
||||
ROUTER_INSTANCE *router = (ROUTER_INSTANCE *)instance;
|
||||
int error;
|
||||
socklen_t len;
|
||||
char msg[85], *errmsg;
|
||||
char msg[BLRM_STRERROR_R_MSG_SIZE + 1 + 5] = "";
|
||||
char *errmsg;
|
||||
unsigned long mysql_errno;
|
||||
|
||||
if (action == ERRACT_RESET)
|
||||
@ -1336,7 +1340,7 @@ unsigned long mysql_errno;
|
||||
len = sizeof(error);
|
||||
if (router->master && getsockopt(router->master->fd, SOL_SOCKET, SO_ERROR, &error, &len) == 0 && error != 0)
|
||||
{
|
||||
strerror_r(error, msg, 80);
|
||||
strerror_r(error, msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
strcat(msg, " ");
|
||||
}
|
||||
else
|
||||
@ -1840,12 +1844,14 @@ int mkdir_rval;
|
||||
|
||||
if (mkdir_rval == -1)
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
skygw_log_write(LOGFILE_ERROR,
|
||||
"Error : Service %s, Failed to create directory '%s': [%d] %s",
|
||||
service->name,
|
||||
path,
|
||||
errno,
|
||||
strerror(errno));
|
||||
err_msg);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
* 29/06/2015 Massimiliano Pinto Addition of blr_file_write_master_config()
|
||||
* Cache directory is now 'cache' under router->binlogdir
|
||||
* 05/08/2015 Massimiliano Pinto Initial implementation of transaction safety
|
||||
* 24/08/2015 Massimiliano Pinto Added strerror_r
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -117,10 +118,13 @@ struct dirent *dp;
|
||||
root_len = strlen(router->fileroot);
|
||||
if ((dirp = opendir(path)) == NULL)
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1]="";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"%s: Unable to read the binlog directory %s, %s.",
|
||||
router->service->name, router->binlogdir,
|
||||
strerror(errno))));
|
||||
err_msg)));
|
||||
return 0;
|
||||
}
|
||||
while ((dp = readdir(dirp)) != NULL)
|
||||
@ -202,7 +206,7 @@ unsigned char magic[] = BINLOG_MAGIC;
|
||||
static int
|
||||
blr_file_create(ROUTER_INSTANCE *router, char *file)
|
||||
{
|
||||
char path[PATH_MAX + 1];
|
||||
char path[PATH_MAX + 1] = "";
|
||||
int fd;
|
||||
|
||||
strcpy(path, router->binlogdir);
|
||||
@ -215,9 +219,12 @@ int fd;
|
||||
}
|
||||
else
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"%s: Failed to create binlog file %s, %s.",
|
||||
router->service->name, path, strerror(errno))));
|
||||
router->service->name, path, err_msg)));
|
||||
return 0;
|
||||
}
|
||||
fsync(fd);
|
||||
@ -291,12 +298,14 @@ int n;
|
||||
if ((n = pwrite(router->binlog_fd, buf, hdr->event_size,
|
||||
hdr->next_pos - hdr->event_size)) != hdr->event_size)
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"%s: Failed to write binlog record at %d of %s, %s. "
|
||||
"Truncating to previous record.",
|
||||
router->service->name, hdr->next_pos - hdr->event_size,
|
||||
router->binlog_name,
|
||||
strerror(errno))));
|
||||
err_msg)));
|
||||
/* Remove any partual event that was written */
|
||||
ftruncate(router->binlog_fd, hdr->next_pos - hdr->event_size);
|
||||
return 0;
|
||||
@ -432,16 +441,20 @@ struct stat statb;
|
||||
pos)));
|
||||
break;
|
||||
case -1:
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Failed to read binlog file %s at position %d"
|
||||
" (%s).", file->binlogname,
|
||||
pos, strerror(errno))));
|
||||
pos, err_msg)));
|
||||
if (errno == EBADF)
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Bad file descriptor in read binlog for file %s"
|
||||
", reference count is %d, descriptor %d.",
|
||||
file->binlogname, file->refcnt, file->fd)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Short read when reading the header. "
|
||||
@ -498,16 +511,21 @@ struct stat statb;
|
||||
pos)));
|
||||
break;
|
||||
case -1:
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Failed to read binlog file %s at position %d"
|
||||
" (%s).", file->binlogname,
|
||||
pos, strerror(errno))));
|
||||
pos, err_msg)));
|
||||
|
||||
if (errno == EBADF)
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Bad file descriptor in read binlog for file %s"
|
||||
", reference count is %d, descriptor %d.",
|
||||
file->binlogname, file->refcnt, file->fd)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Short read when reading the header. "
|
||||
@ -554,11 +572,13 @@ struct stat statb;
|
||||
{
|
||||
if (n == -1)
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Error reading the event at %ld in %s. "
|
||||
"%s, expected %d bytes.",
|
||||
pos, file->binlogname,
|
||||
strerror(errno), hdr->event_size - 19)));
|
||||
err_msg, hdr->event_size - 19)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -747,7 +767,7 @@ GWBUF *buf;
|
||||
int
|
||||
blr_file_next_exists(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave)
|
||||
{
|
||||
char *sptr, buf[80], bigbuf[PATH_MAX + 1];
|
||||
char *sptr, buf[BLRM_BINLOG_NAME_STR_LEN], bigbuf[PATH_MAX + 1];
|
||||
int filenum;
|
||||
|
||||
if ((sptr = strrchr(slave->binlogfile, '.')) == NULL)
|
||||
@ -795,7 +815,7 @@ blr_cache_read_master_data(ROUTER_INSTANCE *router)
|
||||
int
|
||||
blr_file_get_next_binlogname(ROUTER_INSTANCE *router)
|
||||
{
|
||||
char *sptr, buf[80], bigbuf[4096];
|
||||
char *sptr;
|
||||
int filenum;
|
||||
|
||||
if ((sptr = strrchr(router->binlog_name, '.')) == NULL)
|
||||
@ -850,6 +870,7 @@ int rc;
|
||||
char path[(PATH_MAX - 15) + 1] = "";
|
||||
char filename[(PATH_MAX - 4) + 1] = "";
|
||||
char tmp_file[PATH_MAX + 1] = "";
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
|
||||
strncpy(path, router->binlogdir, (PATH_MAX - 15));
|
||||
|
||||
@ -862,12 +883,14 @@ char tmp_file[PATH_MAX + 1] = "";
|
||||
/* open file for writing */
|
||||
config_file = fopen(tmp_file,"wb");
|
||||
if (config_file == NULL) {
|
||||
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u", strerror(errno), errno);
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u", err_msg, errno);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if(chmod(tmp_file, S_IRUSR | S_IWUSR) < 0) {
|
||||
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u", strerror(errno), errno);
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u", err_msg, errno);
|
||||
return 2;
|
||||
}
|
||||
|
||||
@ -887,12 +910,14 @@ char tmp_file[PATH_MAX + 1] = "";
|
||||
rc = rename(tmp_file, filename);
|
||||
|
||||
if (rc == -1) {
|
||||
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u", strerror(errno), errno);
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u", err_msg, errno);
|
||||
return 3;
|
||||
}
|
||||
|
||||
if(chmod(filename, S_IRUSR | S_IWUSR) < 0) {
|
||||
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u", strerror(errno), errno);
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u", err_msg, errno);
|
||||
return 3;
|
||||
}
|
||||
|
||||
@ -966,16 +991,21 @@ int event_error = 0;
|
||||
|
||||
break;
|
||||
case -1:
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"*** ERROR: Failed to read binlog file %s at position %llu"
|
||||
" (%s).", router->binlog_name,
|
||||
pos, strerror(errno))));
|
||||
pos, err_msg)));
|
||||
|
||||
if (errno == EBADF)
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"*** ERROR: Bad file descriptor in read binlog for file %s"
|
||||
", descriptor %d.",
|
||||
router->binlog_name, router->binlog_fd)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"*** ERROR: Short read when reading the header. "
|
||||
@ -1134,11 +1164,13 @@ int event_error = 0;
|
||||
{
|
||||
if (n == -1)
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
|
||||
"Error reading the event at %llu in %s. "
|
||||
"%s, expected %d bytes.",
|
||||
pos, router->binlog_name,
|
||||
strerror(errno), hdr.event_size - 19)));
|
||||
err_msg, hdr.event_size - 19)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -41,6 +41,7 @@
|
||||
* Server error code and msg are reported via SHOW SLAVE STATUS
|
||||
* 03/08/2015 Massimiliano Pinto Initial implementation of transaction safety
|
||||
* 13/08/2015 Massimiliano Pinto Addition of heartbeat check
|
||||
* 23/08/2015 Massimiliano Pinto Added strerror_r
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -325,6 +326,7 @@ void
|
||||
blr_master_response(ROUTER_INSTANCE *router, GWBUF *buf)
|
||||
{
|
||||
char query[128];
|
||||
char task_name[BLRM_TASK_NAME_LEN + 1] = "";
|
||||
|
||||
atomic_add(&router->handling_threads, 1);
|
||||
ss_dassert(router->handling_threads == 1);
|
||||
@ -447,7 +449,7 @@ char query[128];
|
||||
}
|
||||
|
||||
{
|
||||
char str[80];
|
||||
char str[BLRM_SET_HEARTBEAT_QUERY_LEN];
|
||||
sprintf(str, "SET @master_heartbeat_period = %lu000000000", router->heartbeat);
|
||||
buf = blr_make_query(str);
|
||||
}
|
||||
@ -645,23 +647,19 @@ char query[128];
|
||||
router->service->dbref->server->port)));
|
||||
break;
|
||||
case BLRM_BINLOGDUMP:
|
||||
{
|
||||
char *name;
|
||||
|
||||
// Main body, we have received a binlog record from the master
|
||||
/**
|
||||
* Main body, we have received a binlog record from the master
|
||||
*/
|
||||
blr_handle_binlog_record(router, buf);
|
||||
|
||||
// set heartbeat check task
|
||||
if ((name = (char *)malloc(80)) != NULL)
|
||||
{
|
||||
sprintf(name, "%s heartbeat", router->service->name);
|
||||
hktask_add(name, blr_check_last_master_event, router, router->heartbeat);
|
||||
free(name);
|
||||
}
|
||||
/**
|
||||
* Set heartbeat check task
|
||||
*/
|
||||
snprintf(task_name, BLRM_TASK_NAME_LEN, "%s heartbeat", router->service->name);
|
||||
hktask_add(task_name, blr_check_last_master_event, router, router->heartbeat);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (router->reconnect_pending)
|
||||
blr_restart_master(router);
|
||||
@ -1801,11 +1799,14 @@ int n;
|
||||
"Reading saved events: reached end of binlog file at %d.", pos)));
|
||||
break;
|
||||
case -1:
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Error: Reading saved events: failed to read binlog "
|
||||
"file %s at position %d"
|
||||
" (%s).", router->binlog_name,
|
||||
pos, strerror(errno))));
|
||||
pos, err_msg)));
|
||||
|
||||
if (errno == EBADF)
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
@ -1813,6 +1814,7 @@ int n;
|
||||
", descriptor %d.",
|
||||
router->binlog_name, router->binlog_fd)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Error: Reading saved events: short read when reading the header. "
|
||||
@ -1861,11 +1863,13 @@ int n;
|
||||
{
|
||||
if (n == -1)
|
||||
{
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1] = "";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Error: Reading saved events: the event at %ld in %s. "
|
||||
"%s, expected %d bytes.",
|
||||
pos, router->binlog_name,
|
||||
strerror(errno), hdr->event_size - 19)));
|
||||
err_msg, hdr->event_size - 19)));
|
||||
} else {
|
||||
LOGIF(LE, (skygw_log_write(LOGFILE_ERROR,
|
||||
"Error: Reading saved events: short read when reading "
|
||||
@ -1956,7 +1960,7 @@ blr_check_last_master_event(void *inst) {
|
||||
ROUTER_INSTANCE *router = (ROUTER_INSTANCE *)inst;
|
||||
int master_check = 1;
|
||||
int master_state = BLRM_UNCONNECTED;
|
||||
char *name = NULL;
|
||||
char task_name[BLRM_TASK_NAME_LEN + 1] = "";
|
||||
|
||||
spinlock_acquire(&router->lock);
|
||||
|
||||
@ -1980,13 +1984,9 @@ char *name = NULL;
|
||||
* when master state is back to BLRM_BINLOGDUMP
|
||||
* by blr_master_response()
|
||||
*/
|
||||
if ((name = (char *)malloc(80)) != NULL) {
|
||||
sprintf(name, "%s heartbeat", router->service->name);
|
||||
snprintf(task_name, BLRM_TASK_NAME_LEN, "%s heartbeat", router->service->name);
|
||||
|
||||
hktask_remove(name);
|
||||
|
||||
free(name);
|
||||
}
|
||||
hktask_remove(task_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -636,7 +636,9 @@ extern char *strcasestr();
|
||||
removed_cfg = unlink(path);
|
||||
|
||||
if (removed_cfg == -1) {
|
||||
snprintf(error_string, BINLOG_ERROR_MSG_LEN, "Error removing %s, %s, errno %u", path, strerror(errno), errno);
|
||||
char err_msg[BLRM_STRERROR_R_MSG_SIZE+1]="";
|
||||
strerror_r(errno, err_msg, BLRM_STRERROR_R_MSG_SIZE);
|
||||
snprintf(error_string, BINLOG_ERROR_MSG_LEN, "Error removing %s, %s, errno %u", path, err_msg, errno);
|
||||
LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR, "%s: %s", router->service->name, error_string)));
|
||||
}
|
||||
|
||||
@ -1026,8 +1028,8 @@ static int
|
||||
blr_slave_send_maxscale_variables(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave)
|
||||
{
|
||||
GWBUF *pkt;
|
||||
char name[80];
|
||||
char version[40];
|
||||
char name[40];
|
||||
char version[80];
|
||||
uint8_t *ptr;
|
||||
int len, vers_len, seqno = 2;
|
||||
|
||||
|
Reference in New Issue
Block a user