Replace strerror_r with mxs_strerror

The mxs_strerror function requires no local buffer, thus making it simpler
and cleaner to use.
This commit is contained in:
Markus Mäkelä
2017-03-07 12:18:53 +02:00
parent d7e48f93bb
commit e1a1959bc2
33 changed files with 174 additions and 337 deletions

View File

@ -653,12 +653,11 @@ createInstance(SERVICE *service, char **options)
mkdir_rval = mkdir(inst->binlogdir, 0700);
if (mkdir_rval == -1)
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("Service %s, Failed to create binlog directory '%s': [%d] %s",
service->name,
inst->binlogdir,
errno,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
free_instance(inst);
return NULL;
@ -1788,8 +1787,7 @@ errorReply(MXS_ROUTER *instance,
getsockopt(router->master->fd, SOL_SOCKET, SO_ERROR, &error, &len) == 0 &&
error != 0)
{
char errbuf[MXS_STRERROR_BUFLEN];
sprintf(msg, "%s ", strerror_r(error, errbuf, sizeof(errbuf)));
sprintf(msg, "%s ", mxs_strerror(error));
}
else
{
@ -2622,10 +2620,9 @@ int blr_parse_key_file(ROUTER_INSTANCE *router)
if (!file)
{
char errbuf[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to open KEY file '%s': %s",
router->encryption.key_management_filename,
strerror_r(errno, errbuf, sizeof(errbuf)));
mxs_strerror(errno));
return -1;
}

View File

@ -307,10 +307,9 @@ blr_file_init(ROUTER_INSTANCE *router)
root_len = strlen(router->fileroot);
if ((dirp = opendir(path)) == NULL)
{
char err_msg[BLRM_STRERROR_R_MSG_SIZE];
MXS_ERROR("%s: Unable to read the binlog directory %s, %s.",
router->service->name, router->binlogdir,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
return 0;
}
while ((dp = readdir(dirp)) != NULL)
@ -433,20 +432,20 @@ blr_file_create(ROUTER_INSTANCE *router, char *file)
else
{
MXS_ERROR("%s: Failed to write magic string to created binlog file %s, %s.",
router->service->name, path, strerror_r(errno, err_msg, sizeof(err_msg)));
router->service->name, path, mxs_strerror(errno));
close(fd);
if (!unlink(path))
{
MXS_ERROR("%s: Failed to delete file %s, %s.",
router->service->name, path, strerror_r(errno, err_msg, sizeof(err_msg)));
router->service->name, path, mxs_strerror(errno));
}
}
}
else
{
MXS_ERROR("%s: Failed to create binlog file %s, %s.",
router->service->name, path, strerror_r(errno, err_msg, sizeof(err_msg)));
router->service->name, path, mxs_strerror(errno));
}
return created;
@ -577,19 +576,18 @@ blr_write_binlog_record(ROUTER_INSTANCE *router, REP_HEADER *hdr, uint32_t size,
/* Check write operation result*/
if (n != size)
{
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->binlog_position,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
/* Remove any partial event that was written */
if (ftruncate(router->binlog_fd, router->binlog_position))
{
MXS_ERROR("%s: Failed to truncate binlog record at %lu of %s, %s. ",
router->service->name, router->binlog_position,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
}
return 0;
}
@ -836,9 +834,8 @@ blr_read_binlog(ROUTER_INSTANCE *router,
break;
case -1:
{
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);
file->binlogname, mxs_strerror(errno), pos);
if (errno == EBADF)
{
@ -899,10 +896,9 @@ blr_read_binlog(ROUTER_INSTANCE *router,
break;
case -1:
{
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);
file->binlogname, mxs_strerror(errno), pos);
if (errno == EBADF)
{
@ -983,13 +979,12 @@ blr_read_binlog(ROUTER_INSTANCE *router,
if (n == -1)
{
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.",
pos,
file->binlogname,
strerror_r(errno, err_msg, sizeof(err_msg)),
mxs_strerror(errno),
hdr->event_size - BINLOG_EVENT_HDR_LEN);
}
else
@ -1199,9 +1194,8 @@ blr_cache_response(ROUTER_INSTANCE *router, char *response, GWBUF *buf)
}
if (write(fd, GWBUF_DATA(buf), GWBUF_LENGTH(buf)) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to write cached response: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
close(fd);
@ -1257,9 +1251,8 @@ blr_cache_read_response(ROUTER_INSTANCE *router, char *response)
}
if (read(fd, GWBUF_DATA(buf), statb.st_size) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to read cached response: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
close(fd);
return buf;
@ -1438,10 +1431,9 @@ blr_read_events_all_events(ROUTER_INSTANCE *router,
break;
case -1:
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to read binlog file %s at position %llu"
" (%s).", router->binlog_name, pos,
strerror_r(errno, err, sizeof(err)));
mxs_strerror(errno));
if (errno == EBADF)
{
@ -1657,11 +1649,10 @@ blr_read_events_all_events(ROUTER_INSTANCE *router,
{
if (n == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Error reading the event at %llu in %s. "
"%s, expected %d bytes.",
pos, router->binlog_name,
strerror_r(errno, err, sizeof(err)),
mxs_strerror(errno),
hdr.event_size - BINLOG_EVENT_HDR_LEN);
}
else
@ -2443,7 +2434,6 @@ 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[MXS_STRERROR_BUFLEN];
char *ssl_ca;
char *ssl_cert;
char *ssl_key;
@ -2457,7 +2447,7 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error)
if (config_file == NULL)
{
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u",
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
return 2;
}
@ -2465,7 +2455,7 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error)
{
fclose(config_file);
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u",
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
return 2;
}
@ -2517,14 +2507,14 @@ blr_file_write_master_config(ROUTER_INSTANCE *router, char *error)
if (rc == -1)
{
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u",
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
return 3;
}
if (chmod(filename, S_IRUSR | S_IWUSR) < 0)
{
snprintf(error, BINLOG_ERROR_MSG_LEN, "%s, errno %u",
strerror_r(errno, err_msg, sizeof(err_msg)), errno);
mxs_strerror(errno), errno);
return 3;
}
@ -2724,12 +2714,11 @@ blr_write_special_event(ROUTER_INSTANCE *router, uint32_t file_offset, uint32_t
/* Write the event */
if ((n = pwrite(router->binlog_fd, new_event, event_size, router->last_written)) != event_size)
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("%s: Failed to write %s special binlog record at %lu of %s, %s. "
"Truncating to previous record.",
router->service->name, new_event_desc, (unsigned long)file_offset,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
/* Remove any partial event that was written */
if (ftruncate(router->binlog_fd, router->binlog_position))
@ -2737,7 +2726,7 @@ blr_write_special_event(ROUTER_INSTANCE *router, uint32_t file_offset, uint32_t
MXS_ERROR("%s: Failed to truncate %s special binlog record at %lu of %s, %s. ",
router->service->name, new_event_desc, (unsigned long)file_offset,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
}
MXS_FREE(new_event);
return 0;

View File

@ -2015,11 +2015,10 @@ GWBUF
break;
case -1:
{
char err_msg[MXS_STRERROR_BUFLEN];
MXS_ERROR("Reading saved events: failed to read binlog "
"file %s at position %llu"
" (%s).", router->binlog_name,
pos, strerror_r(errno, err_msg, sizeof(err_msg)));
pos, mxs_strerror(errno));
if (errno == EBADF)
{
@ -2075,11 +2074,10 @@ GWBUF
{
if (n == -1)
{
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,
strerror_r(errno, err_msg, sizeof(err_msg)), hdr->event_size - 19);
mxs_strerror(errno), hdr->event_size - 19);
}
else
{
@ -2327,12 +2325,11 @@ 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[MXS_STRERROR_BUFLEN];
MXS_ERROR("%s: Failed to write binlog record at %lu of %s, %s. "
"Truncating to previous record.",
router->service->name, router->binlog_position,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
/* Remove any partial event that was written */
if (ftruncate(router->binlog_fd, router->binlog_position))
@ -2340,7 +2337,7 @@ blr_write_data_into_binlog(ROUTER_INSTANCE *router, uint32_t data_len, uint8_t *
MXS_ERROR("%s: Failed to truncate binlog record at %lu of %s, %s. ",
router->service->name, router->last_written,
router->binlog_name,
strerror_r(errno, err_msg, sizeof(err_msg)));
mxs_strerror(errno));
}
return 0;
}

View File

@ -1008,10 +1008,9 @@ blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
if (removed_cfg == -1)
{
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);
mxs_strerror(errno), errno);
MXS_ERROR("%s: %s", router->service->name, error_string);
}
@ -3677,9 +3676,8 @@ blr_start_slave(ROUTER_INSTANCE* router, ROUTER_SLAVE* slave)
/* Truncate previous binlog file to last_safe pos */
if (truncate(file, router->last_safe_pos) == -1)
{
char err[MXS_STRERROR_BUFLEN];
MXS_ERROR("Failed to truncate file: %d, %s",
errno, strerror_r(errno, err, sizeof(err)));
errno, mxs_strerror(errno));
}
/* Log it */