Use constant sized arrays for some service strings

The `user`, `password`, `version_string` and `weightby` values should be
allocated as a part of the service structure. This allows them to be
modified at runtime without having to worry about memory allocation
problems.

Although this removes the problem of reallocation, it still does not make
the updating of the strings thread-safe. This can cause invalid values to
be read from the service strings.
This commit is contained in:
Markus Mäkelä
2017-04-24 11:31:25 +03:00
parent b434c94563
commit e62be5034a
10 changed files with 67 additions and 85 deletions

View File

@ -651,7 +651,7 @@ static int routeQuery(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session,
static void diagnostics(MXS_ROUTER *instance, DCB *dcb)
{
ROUTER_INSTANCE *router = (ROUTER_INSTANCE *)instance;
char *weightby;
const char *weightby = serviceGetWeightingParameter(router->service);
double master_pct = 0.0, slave_pct = 0.0, all_pct = 0.0;
dcb_printf(dcb, "\n");
@ -695,7 +695,7 @@ static void diagnostics(MXS_ROUTER *instance, DCB *dcb)
dcb_printf(dcb, "\tNumber of queries forwarded to all: %" PRIu64 " (%.2f%%)\n",
router->stats.n_all, all_pct);
if ((weightby = serviceGetWeightingParameter(router->service)) != NULL)
if (*weightby)
{
dcb_printf(dcb, "\tConnection distribution based on %s "
"server parameter.\n",
@ -754,9 +754,9 @@ static json_t* diagnostics_json(const MXS_ROUTER *instance)
json_object_set_new(rval, "route_slave", json_integer(router->stats.n_slave));
json_object_set_new(rval, "route_all", json_integer(router->stats.n_all));
char *weightby = serviceGetWeightingParameter(router->service);
const char *weightby = serviceGetWeightingParameter(router->service);
if (weightby)
if (*weightby)
{
json_object_set_new(rval, "weightby", json_string(weightby));
}