Fix cli utility

This commit is contained in:
vdutta 2022-09-14 18:23:53 +05:30
parent 94cc2f8c98
commit a62a6efceb
2 changed files with 11 additions and 7 deletions

View file

@ -16,6 +16,7 @@
#include <getopt.h>
#include <stdarg.h>
#include <regex.h>
#include <mxml.h>
#include "common.h"
#include "cwmp_cli.h"
@ -96,6 +97,11 @@ int global_env_init(int argc, char **argv, struct env *env)
{
int c, option_index = 0;
/* This is to initialize the global context in mxml,
* with out init mxml sometimes segfaults, when calling the destructor.
*/
mxml_error(NULL);
while ((c = getopt_long(argc, argv, "bgchv", cwmp_long_options, &option_index)) != -1) {
switch (c) {
case 'b':
@ -105,7 +111,9 @@ int global_env_init(int argc, char **argv, struct env *env)
env->periodic = CWMP_START_PERIODIC;
break;
case 'c':
cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp));
execute_cwmp_cli_command(argv[2], argv + 3);
FREE(cwmp_main);
exit(0);
case 'h':
show_help();

View file

@ -201,10 +201,6 @@ static int cwmp_init()
openlog("cwmp", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
CWMP_LOG(INFO, "STARTING ICWMP with PID :%d", getpid());
/* This is to initialize the global context in mxml,
* with out init mxml sometimes segfaults, when calling the destructor.
*/
mxml_error(NULL);
cwmp_main = (struct cwmp*)calloc(1, sizeof(struct cwmp));
cwmp_main->init_complete = false;
@ -343,13 +339,13 @@ int main(int argc, char **argv)
if (error)
return error;
if ((error = cwmp_init()))
return error;
memset(&env, 0, sizeof(struct env));
if ((error = global_env_init(argc, argv, &env)))
return error;
if ((error = cwmp_init()))
return error;
memcpy(&(cwmp_main->env), &env, sizeof(struct env));
if ((error = cwmp_init_backup_session(NULL, ALL)))