From 85e198b178813e658c21787f53f37ef679c8467a Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Tue, 13 Aug 2024 07:02:15 +0200 Subject: [PATCH] Config module: use printf_params() to print log messages --- common/config/config_load_configmodule.c | 12 +++++------- common/config/libconfig/config_libconfig.c | 16 +++++++--------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/common/config/config_load_configmodule.c b/common/config/config_load_configmodule.c index 71cab2a33a..9bb1b85f7d 100644 --- a/common/config/config_load_configmodule.c +++ b/common/config/config_load_configmodule.c @@ -302,7 +302,7 @@ configmodule_interface_t *load_configmodule(int argc, } static configmodule_interface_t *cfgptr; if (cfgptr) - printf("ERROR: Call load_configmodule more than one time\n"); + fprintf(stderr, "ERROR: Call load_configmodule more than one time\n"); // The macros are not thread safe print_params and similar cfgptr = calloc(sizeof(configmodule_interface_t), 1); @@ -369,8 +369,7 @@ configmodule_interface_t *load_configmodule(int argc, if (strstr(cfgparam,CONFIG_CMDLINEONLY) == NULL) { i=load_config_sharedlib(cfgptr); - if (i == 0) { - printf("[CONFIG] config module %s loaded\n",cfgmode); + if (i == 0) { int idx = config_paramidx_fromname(Config_Params, sizeofArray(Config_Params), CONFIGP_DEBUGFLAGS); Config_Params[idx].uptr = &(cfgptr->rtflags); idx = config_paramidx_fromname(Config_Params, sizeofArray(Config_Params), CONFIGP_TMPDIR); @@ -387,7 +386,7 @@ configmodule_interface_t *load_configmodule(int argc, cfgptr->end = (configmodule_endfunc_t)nooptfunc; } - printf("[CONFIG] debug flags: 0x%08x\n", cfgptr->rtflags); + printf_params(cfgptr, "[CONFIG] debug flags: 0x%08x\n", cfgptr->rtflags); if (modeparams != NULL) free(modeparams); @@ -413,7 +412,7 @@ void write_parsedcfg(configmodule_interface_t *cfgptr) cfgptr->status->num_write); } if (cfgptr->write_parsedcfg != NULL) { - printf("[CONFIG] calling config module write_parsedcfg function...\n"); + printf_params(cfgptr, "[CONFIG] calling config module write_parsedcfg function...\n"); cfgptr->write_parsedcfg(cfgptr); } } @@ -425,12 +424,11 @@ void end_configmodule(configmodule_interface_t *cfgptr) if (cfgptr != NULL) { write_parsedcfg(cfgptr); if (cfgptr->end != NULL) { - printf ("[CONFIG] calling config module end function...\n"); + printf_params(cfgptr, "[CONFIG] calling config module end function...\n"); cfgptr->end(cfgptr); } pthread_mutex_lock(&cfgptr->memBlocks_mutex); - printf ("[CONFIG] free %u config value pointers\n",cfgptr->numptrs); for(int i=0; inumptrs ; i++) { if (cfgptr->oneBlock[i].ptrs != NULL && cfgptr->oneBlock[i].ptrsAllocated== true && cfgptr->oneBlock[i].toFree) { diff --git a/common/config/libconfig/config_libconfig.c b/common/config/libconfig/config_libconfig.c index a41a4dab33..0934024391 100644 --- a/common/config/libconfig/config_libconfig.c +++ b/common/config/libconfig/config_libconfig.c @@ -461,13 +461,11 @@ int config_libconfig_get(configmodule_interface_t *cfg, paramdef_t *cfgoptions, } /* switch on param type */ if( notfound == 1) { - printf("[LIBCONFIG] %s not found in %s ", cfgpath,libconfig_privdata.configfile ); + fprintf(stderr, "[LIBCONFIG] %s not found in %s ", cfgpath, libconfig_privdata.configfile); if ( (cfgoptions[i].paramflags & PARAMFLAG_MANDATORY) != 0) { fatalerror=1; - printf(" mandatory parameter missing\n"); - } else { - printf("\n"); + fprintf(stderr, " mandatory parameter missing\n"); } } else { if (defval == 1) { @@ -570,8 +568,8 @@ int config_libconfig_init(configmodule_interface_t *cfg) } const char *incp = config_get_include_dir (&(libconfig_privdata.cfg)) ; - - printf("[LIBCONFIG] Path for include directive set to: %s\n", (incp!=NULL)?incp:"libconfig defaults"); + + printf_params(cfg, "[LIBCONFIG] Path for include directive set to: %s\n", (incp != NULL) ? incp : "libconfig defaults"); /* set convertion option to allow integer to float conversion*/ config_set_auto_convert (&(libconfig_privdata.cfg), CONFIG_TRUE); /* Read the file. If there is an error, report it and exit. */ @@ -582,7 +580,7 @@ int config_libconfig_init(configmodule_interface_t *cfg) config_error_line(&(libconfig_privdata.cfg)), config_error_text(&(libconfig_privdata.cfg))); config_destroy(&(libconfig_privdata.cfg)); - printf( "\n"); + fprintf(stderr, "\n"); free(tmppath); return -1; } @@ -623,11 +621,11 @@ void config_libconfig_write_parsedcfg(configmodule_interface_t *cfg) config_error_line(&(libconfig_privdata.runtcfg)), config_error_text(&(libconfig_privdata.runtcfg))); } else { - printf("[LIBCONFIG] file %s created successfully\n", cfg->status->debug_cfgname); + printf_params(cfg, "[LIBCONFIG] file %s created successfully\n", cfg->status->debug_cfgname); } free(fname); } else { - printf("[LIBCONFIG] Cannot create config file after parsing: CONFIG_SAVERUNCFG flag not specified\n"); + printf_params(cfg, "[LIBCONFIG] Cannot create config file after parsing: CONFIG_SAVERUNCFG flag not specified\n"); } }