Skip to content

Commit 63fdeb2

Browse files
committed
fix default handler for tunable update
Signed-off-by: Emelia Lei <wlei29@bloomberg.net>
1 parent 0cad820 commit 63fdeb2

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

db/db_tunables.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,13 +1261,6 @@ static int file_copier_update(void *context, void *value)
12611261
return 0;
12621262
}
12631263

1264-
static int iam_metrics_namespace_update(void *context, void *value)
1265-
{
1266-
comdb2_tunable *tunable = (comdb2_tunable *)context;
1267-
*(char **)tunable->var = intern((char *)value);
1268-
return 0;
1269-
}
1270-
12711264
static void *file_permissions_value(void *context)
12721265
{
12731266
static char val[15];
@@ -1407,6 +1400,15 @@ int register_tunable(comdb2_tunable *tunable)
14071400
/* Keep tunable names in lower case (to be consistent). */
14081401
tunable_tolower(t->name);
14091402

1403+
// Ensure the initial value for tunables without an update function
1404+
// is heap-allocated so the default update handler can safely free() it.
1405+
if ((tunable->type == TUNABLE_STRING || tunable->type == TUNABLE_RAW) &&
1406+
!tunable->update) {
1407+
if (tunable->var && *(char **)tunable->var) {
1408+
*((char **)tunable->var) = strdup(*(char **)tunable->var);
1409+
}
1410+
}
1411+
14101412
t->descr = tunable->descr;
14111413

14121414
if (tunable->type >= TUNABLE_INVALID) {

db/db_tunables.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,8 +2583,7 @@ REGISTER_TUNABLE("iam_base_bri",
25832583
TUNABLE_STRING, &gbl_iam_base_bri, READEARLY | READONLY, NULL,
25842584
NULL, NULL, NULL);
25852585
REGISTER_TUNABLE("iam_metrics_namespace", "metrics namespace for IAM user metrics (default: comdb2-iam)",
2586-
TUNABLE_STRING, &gbl_iam_metrics_namespace, READEARLY | READONLY, NULL, NULL,
2587-
iam_metrics_namespace_update, NULL);
2586+
TUNABLE_STRING, &gbl_iam_metrics_namespace, READEARLY | READONLY, NULL, NULL, NULL, NULL);
25882587
REGISTER_TUNABLE("queue_nonodh_scan_limit", "For comdb2_queues, stop queue scan at this depth (Default: 10000)", TUNABLE_INTEGER, &gbl_nonodh_queue_scan_limit, 0, NULL, NULL, NULL, NULL);
25892588
REGISTER_TUNABLE("always_request_log_req", "Always request the next log record on replicant if there is a gap (default: off)", TUNABLE_BOOLEAN, &gbl_always_request_log_req, 0, NULL, NULL, NULL, NULL);
25902589
REGISTER_TUNABLE("nudge_replication_when_idle",

0 commit comments

Comments
 (0)