Commit e1109e62 authored by frtabu's avatar frtabu

remove getopt call in configuration module, it changes the argv order. Fix...

remove getopt call in configuration module, it changes the argv order. Fix configuration module bugs (command line arguments sometimes not properly processed
parent 3197c314
......@@ -41,11 +41,13 @@ char *tmpval = value;
int optisset=0;
char defbool[2]="1";
if ( ((cfgoptions->paramflags &PARAMFLAG_BOOL) == 0) && value == NULL ) { /* not a boolean, argument required */
if ( value == NULL) {
if( (cfgoptions->paramflags &PARAMFLAG_BOOL) == 0 ) { /* not a boolean, argument required */
fprintf(stderr,"[CONFIG] command line, option %s requires an argument\n",cfgoptions->optname);
return 0;
} else { /* boolean value option without argument, set value to true*/
} else { /* boolean value option without argument, set value to true*/
tmpval = defbool;
}
}
switch(cfgoptions->type)
{
......@@ -124,8 +126,8 @@ char *cfgpath;
if (strcmp(*p, "-h") == 0 || strcmp(*p, "--help") == 0 ) {
config_printhelp(cfgoptions,numoptions);
}
if (*p[0] == '-') {
if (*p[0] == '-') {
for(int i=0;i<numoptions;i++) {
if ( ( cfgoptions[i].paramflags & PARAMFLAG_DISABLECMDLINE) != 0) {
continue;
......@@ -135,17 +137,17 @@ char *cfgpath;
} else {
sprintf(cfgpath,"%s",cfgoptions[i].optname);
}
if ( ((strlen(*p) == 2) && (strcmp(*p + 1,cfgpath) == 0)) ||
((strlen(*p) > 2) && (strcmp(*p + 2,cfgpath ) == 0 )) ) {
pp = *(p+1);
if ( ( pp != NULL ) && (pp[0]!= '-') ) {
p++;
c--;
if ( ( pp != NULL ) && (c>1) && (pp[0]!= '-') ) {
j += processoption(&(cfgoptions[i]), pp);
} else {
j += processoption(&(cfgoptions[i]), NULL);
}
break;
}
} /* for */
} /* if (*p[0] == '-') */
......
......@@ -109,14 +109,14 @@ char *atoken;
uint32_t tmpflags=0;
int i;
/* first parse the command line to look for the -O option */
opterr=0;
while ((i = getopt(argc, argv, "O:h")) != -1) {
if ( i == 'O' ) {
cfgparam = optarg;
for (i = 0;i<argc;i++) {
if (strlen(argv[i]) < 2) continue;
if ( argv[i][1] == 'O' && i < (argc -1)) {
cfgparam = argv[i+1];
}
if ( i == 'h' ) {
if ( argv[i][1] == 'h' ) {
tmpflags = CONFIG_HELP;
}
}
......
......@@ -123,6 +123,11 @@ void config_printhelp(paramdef_t *params,int numparams)
int config_get(paramdef_t *params,int numparams, char *prefix)
{
int ret= -1;
if (CONFIG_ISFLAGSET(CONFIG_ABORT)) {
fprintf(stderr,"[CONFIG] config_get skipped, config module not properly initialized\n");
return ret;
}
configmodule_interface_t *cfgif = config_get_if();
if (cfgif != NULL) {
ret = config_get_if()->get(params, numparams,prefix);
......
......@@ -113,7 +113,11 @@ void log_getconfig(log_t *g_log) {
paramdef_t logparams_verbosity[MAX_LOG_COMPONENTS];
paramdef_t logparams_logfile[MAX_LOG_COMPONENTS];
config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX);
int ret = config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX);
if (ret <0) {
fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed");
return;
}
memset(logparams_level, 0, sizeof(paramdef_t)*MAX_LOG_COMPONENTS);
memset(logparams_verbosity,0, sizeof(paramdef_t)*MAX_LOG_COMPONENTS);
memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_COMPONENTS);
......
......@@ -584,7 +584,7 @@ static void get_options(void) {
if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) {
set_glog(glog_level, -1);
}
if(config_isparamset(cmdline_logparams,CMDLINE_GLOGLEVEL_IDX)) {
if(config_isparamset(cmdline_logparams,CMDLINE_GLOGVERBO_IDX)) {
set_glog(-1, glog_verbosity);
}
if (start_telnetsrv) {
......@@ -889,7 +889,6 @@ int main( int argc, char **argv )
if ( load_configmodule(argc,argv) == NULL) {
exit_fun("[SOFTMODEM] Error, configuration module init failed\n");
}
#ifdef DEBUG_CONSOLE
setvbuf(stdout, NULL, _IONBF, 0);
......@@ -920,7 +919,6 @@ int main( int argc, char **argv )
}
#if T_TRACER
T_init(T_port, T_wait, T_dont_fork);
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment