Merge remote-tracking branch 'origin/issue-1054-fix' into integration_2026_w19 (!3960)

fix: issue 1054 - Config: Creating New Array members via command line arguments

Before this change, if you wanted to use --rfsimulator.[0].serveraddr
server on the command line but if you had no rfsimulator block in your
config file, it would just ignore it and print:

[CONFIG] unknown option: --rfsimulator.[0].serveraddr
[CONFIG] unknown option: server

This is because the config module only processes array members that
already exist in the config file. If the array is empty, the command
args are never checked.

What I changed is, in config_getlist() in config_userapi.c, after it
finishes processing existing array parameters, it checks whether a new
parameter is needed. If so, it matches with the list of parameters
first, then the highest index is found for that parameter using the
strtol,

"--rfsimulator.[0].serveraddr",
"--rfsimulator.[2].serveraddr",

What I changed is, in config_getlist() in config_userapi.c, after it
finishes processing existing array parameters, it checks whether a new
parameter is needed. If so, it matches with the list of parameters
first, then the highest index is found for that parameter using the
strtol,

"--rfsimulator.[0].serveraddr",
"--rfsimulator.[2].serveraddr",
"--rfsimulator.[4].serverport",
"--rfsimulator.[1].serveraddr",

It sets the index as 4, allocates 4 slots, memory is managed via
standard functions then it fills the gap of all the indices.

this closes #1054

Signed-off-by: Jaroslava Fiedlerova <jaroslava.fiedlerova@openairinterface.org>
Reviewed-by: Bartosz Podrygajlo <bartosz.podrygajlo@openairinterface.org>
This commit is contained in:
Jaroslava Fiedlerova
2026-05-07 09:36:58 +02:00
2 changed files with 90 additions and 29 deletions

View File

@@ -126,37 +126,97 @@ int config_getlist(configmodule_interface_t *cfg, paramlist_def_t *ParamList, pa
}
const int ret = cfg->getlist(cfg, ParamList, params, numparams, prefix);
if (ret >= 0 && params) {
char *newprefix;
if (prefix) {
int rc = asprintf(&newprefix, "%s.%s", prefix, ParamList->listname);
if (rc < 0) newprefix = NULL;
} else {
newprefix = ParamList->listname;
}
char cfgpath[MAX_OPTNAME_SIZE*2 + 6]; /* prefix.listname.[listindex] */
for (int i = 0; i < ParamList->numelt; ++i) {
// TODO config_process_cmdline?
sprintf(cfgpath, "%s.[%i]", newprefix, i);
config_process_cmdline(cfg, ParamList->paramarray[i], numparams, cfgpath);
if (cfg->rtflags & CONFIG_SAVERUNCFG) {
cfg->set(ParamList->paramarray[i], numparams, cfgpath);
}
config_execcheck(cfg, ParamList->paramarray[i], numparams, cfgpath);
}
if (prefix)
free(newprefix);
/* build newprefix OUTSIDE the params check so we can use it below too */
char *newprefix = NULL;
if (prefix) {
int rc = asprintf(&newprefix, "%s.%s", prefix, ParamList->listname);
if (rc < 0)
newprefix = NULL;
} else {
newprefix = ParamList->listname;
}
return ret;
char cfgpath[MAX_OPTNAME_SIZE * 2 + 6]; /* prefix.listname.[listindex] */
if (ret >= 0 && params) {
for (int i = 0; i < ParamList->numelt; ++i) {
sprintf(cfgpath, "%s.[%i]", newprefix, i);
config_process_cmdline(cfg, ParamList->paramarray[i], numparams, cfgpath);
if (cfg->rtflags & CONFIG_SAVERUNCFG)
cfg->set(ParamList->paramarray[i], numparams, cfgpath);
config_execcheck(cfg, ParamList->paramarray[i], numparams, cfgpath);
}
}
if (params && newprefix && (ret >= 0 || ParamList->numelt == 0)) {
sprintf(cfgpath, "%s", newprefix);
char searchstr[MAX_OPTNAME_SIZE * 2 + 10];
snprintf(searchstr, sizeof(searchstr), "--%s.", cfgpath);
char *endptr;
int valid_idx = ParamList->numelt;
for (int i = 1; i < cfg->argc; i++) {
char *res = strstr(cfg->argv[i], searchstr);
if (res != NULL) {
char *bracket = strchr(res + strlen(searchstr), '[');
bracket++;
long num = strtol(bracket, &endptr, 10);
if (num < valid_idx)
continue;
if (valid_idx == num) {
valid_idx++;
} else if (num > valid_idx) {
LOG_E(HW, "Out of Order Element Creation\n index: %s, valid_idx: %d, num: %ld\n", cfg->argv[i], valid_idx, num);
return -1;
} else {
LOG_E(HW, "[CONFIG] Invalid Configuration\n index: %s, valid_idx: %d, num: %ld\n", cfg->argv[i], valid_idx, num);
return -1;
}
}
}
while (ParamList->numelt < valid_idx) {
int new_idx = ParamList->numelt;
sprintf(cfgpath, "%s.[%i]", newprefix, new_idx);
paramdef_t **old = ParamList->paramarray;
ParamList->paramarray = config_allocate_new(cfg, (new_idx + 1) * sizeof(paramdef_t *), true);
memcpy(ParamList->paramarray, old, new_idx * sizeof(paramdef_t *));
ParamList->paramarray[new_idx] = config_allocate_new(cfg, numparams * sizeof(paramdef_t), true);
memcpy(ParamList->paramarray[new_idx], params, sizeof(paramdef_t) * numparams);
for (int p = 0; p < numparams; p++) {
ParamList->paramarray[new_idx][p].voidptr = NULL;
}
ParamList->numelt++;
fprintf(stderr, "[CONFIG] Created new array parameter %s.[%d]\n", newprefix, new_idx);
config_process_cmdline(cfg, ParamList->paramarray[new_idx], numparams, cfgpath);
for (int p = 0; p < numparams; p++) {
paramdef_t *pd = &ParamList->paramarray[new_idx][p];
if (pd->paramflags & PARAMFLAG_PARAMSET)
continue;
config_common_getdefault(cfg, pd, cfgpath);
}
config_execcheck(cfg, ParamList->paramarray[new_idx], numparams, cfgpath);
for (int p = 0; p < numparams; p++) {
if (ParamList->paramarray[new_idx][p].paramflags & PARAMFLAG_PARAMSET)
fprintf(stderr, "[CONFIG] New parameter set: %s\n", ParamList->paramarray[new_idx][p].optname);
}
}
}
if (prefix)
free(newprefix);
/* when added parameters via CLI, return numelt instead of original ret */
return (ParamList->numelt > 0) ? (int)ParamList->numelt : ret;
}
int config_isparamset(paramdef_t *params,int paramidx) {
int config_isparamset(paramdef_t *params, int paramidx)
{
if ((params[paramidx].paramflags & PARAMFLAG_PARAMSET) != 0) {
return 1;
} else {