Modified -C command-line handling and added to SNMP

This commit is contained in:
Olof hagsand 2023-08-23 10:52:47 +02:00
parent c101799e74
commit 124afb8788
6 changed files with 20 additions and 16 deletions

View file

@ -614,9 +614,7 @@ main(int argc,
case 'l' : case 'l' :
break; /* see above */ break; /* see above */
case 'C': /* Explicitly dump configuration */ case 'C': /* Explicitly dump configuration */
if (!strlen(optarg)) if ((config_dump_format = format_str2int(optarg)) == (enum format_enum)-1){
usage(h, argv[0]);
if ((config_dump_format = format_str2int(optarg)) < 0){
fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]); fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]);
usage(h, argv[0]); usage(h, argv[0]);
} }

View file

@ -613,9 +613,7 @@ main(int argc,
case 'l': /* Log destination */ case 'l': /* Log destination */
break; /* see above */ break; /* see above */
case 'C': /* Explicitly dump configuration */ case 'C': /* Explicitly dump configuration */
if (!strlen(optarg)) if ((config_dump_format = format_str2int(optarg)) == (enum format_enum)-1){
usage(h, argv[0]);
if ((config_dump_format = format_str2int(optarg)) < 0){
fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]); fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]);
usage(h, argv[0]); usage(h, argv[0]);
} }

View file

@ -732,9 +732,7 @@ main(int argc,
case 'l': /* log */ case 'l': /* log */
break; /* see above */ break; /* see above */
case 'C': /* Explicitly dump configuration */ case 'C': /* Explicitly dump configuration */
if (!strlen(optarg)) if ((config_dump_format = format_str2int(optarg)) == (enum format_enum)-1){
usage(h, argv[0]);
if ((config_dump_format = format_str2int(optarg)) < 0){
fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]); fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]);
usage(h, argv[0]); usage(h, argv[0]);
} }

View file

@ -392,9 +392,7 @@ main(int argc,
case 'l': /* log */ case 'l': /* log */
break; /* taken care of in earlier getopt above */ break; /* taken care of in earlier getopt above */
case 'C': /* Explicitly dump configuration */ case 'C': /* Explicitly dump configuration */
if (!strlen(optarg)) if ((config_dump_format = format_str2int(optarg)) == (enum format_enum)-1){
usage(h, argv[0]);
if ((config_dump_format = format_str2int(optarg)) < 0){
fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]); fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]);
usage(h, argv[0]); usage(h, argv[0]);
} }

View file

@ -1241,9 +1241,7 @@ main(int argc,
case 'l': /* log */ case 'l': /* log */
break; /* see above */ break; /* see above */
case 'C': /* Explicitly dump configuration */ case 'C': /* Explicitly dump configuration */
if (!strlen(optarg)) if ((config_dump_format = format_str2int(optarg)) == (enum format_enum)-1){
usage(h, argv[0]);
if ((config_dump_format = format_str2int(optarg)) < 0){
fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]); fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]);
usage(h, argv[0]); usage(h, argv[0]);
} }

View file

@ -70,7 +70,7 @@
#include "snmp_register.h" #include "snmp_register.h"
/* Command line options to be passed to getopt(3) */ /* Command line options to be passed to getopt(3) */
#define SNMP_OPTS "hD:f:l:o:z" #define SNMP_OPTS "hD:f:l:C:o:z"
/* Forward */ /* Forward */
static int clixon_snmp_input_cb(int s, void *arg); static int clixon_snmp_input_cb(int s, void *arg);
@ -312,6 +312,7 @@ usage(clicon_handle h,
"\t-D <level>\tDebug level (>1 for extensive libnetsnmp debug)\n" "\t-D <level>\tDebug level (>1 for extensive libnetsnmp debug)\n"
"\t-f <file>\tConfiguration file (mandatory)\n" "\t-f <file>\tConfiguration file (mandatory)\n"
"\t-l (e|o|s|f<file>) Log on std(e)rr, std(o)ut, (s)yslog(default), (f)ile\n" "\t-l (e|o|s|f<file>) Log on std(e)rr, std(o)ut, (s)yslog(default), (f)ile\n"
"\t-C <format>\tDump configuration options on stdout after loading. Format is xml|json|text\n"
"\t-z\t\tKill other %s daemon and exit\n" "\t-z\t\tKill other %s daemon and exit\n"
"\t-o \"<option>=<value>\"\tGive configuration option overriding config file (see clixon-config.yang)\n", "\t-o \"<option>=<value>\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
argv0, argv0 argv0, argv0
@ -412,6 +413,13 @@ main(int argc,
case 'f': /* config file */ case 'f': /* config file */
case 'l': /* log */ case 'l': /* log */
break; /* see above */ break; /* see above */
case 'C': /* Explicitly dump configuration */
if ((config_dump_format = format_str2int(optarg)) == (enum format_enum)-1){
fprintf(stderr, "Unrecognized dump format: %s(expected: xml|json|text)\n", argv[0]);
usage(h, argv[0]);
}
config_dump++;
break;
case 'o':{ /* Configuration option */ case 'o':{ /* Configuration option */
char *val; char *val;
if ((val = index(optarg, '=')) == NULL) if ((val = index(optarg, '=')) == NULL)
@ -514,6 +522,11 @@ main(int argc,
if (clicon_nsctx_global_set(h, nsctx_global) < 0) if (clicon_nsctx_global_set(h, nsctx_global) < 0)
goto done; goto done;
if (config_dump){
if (clicon_option_dump1(h, stdout, config_dump_format) < 0)
goto done;
goto ok;
}
clicon_option_dump(h, 1); clicon_option_dump(h, 1);
/* Send hello request to backend to get session-id back /* Send hello request to backend to get session-id back
@ -540,6 +553,7 @@ main(int argc,
/* main event loop */ /* main event loop */
if (clixon_event_loop(h) < 0) if (clixon_event_loop(h) < 0)
goto done; goto done;
ok:
retval = 0; retval = 0;
done: done:
snmp_terminate(h); snmp_terminate(h);