mirror of https://gerrit.osmocom.org/osmo-sysmon
Add oneshot mode that exits after one iteration
Change-Id: Id920c4afee633b8da6919b7b318f9c868890a176
This commit is contained in:
parent
85d0fb2b38
commit
ebbfbbdbc7
|
@ -118,6 +118,7 @@ static void print_usage()
|
||||||
static void print_help()
|
static void print_help()
|
||||||
{
|
{
|
||||||
printf(" -h --help This text.\n");
|
printf(" -h --help This text.\n");
|
||||||
|
printf(" -o --oneshot Oneshot mode. Execute queries once, then exit.\n");
|
||||||
printf(" -c --config-file filename The config file to use.\n");
|
printf(" -c --config-file filename The config file to use.\n");
|
||||||
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM Enable debugging.\n");
|
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM Enable debugging.\n");
|
||||||
printf(" -D --daemonize Fork the process into a background daemon.\n");
|
printf(" -D --daemonize Fork the process into a background daemon.\n");
|
||||||
|
@ -130,9 +131,11 @@ static void print_help()
|
||||||
static struct {
|
static struct {
|
||||||
const char *config_file;
|
const char *config_file;
|
||||||
bool daemonize;
|
bool daemonize;
|
||||||
|
bool oneshot;
|
||||||
} cmdline_opts = {
|
} cmdline_opts = {
|
||||||
.config_file = "osmo-sysmon.cfg",
|
.config_file = "osmo-sysmon.cfg",
|
||||||
.daemonize = false,
|
.daemonize = false,
|
||||||
|
.oneshot = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void handle_options(int argc, char **argv)
|
static void handle_options(int argc, char **argv)
|
||||||
|
@ -141,6 +144,7 @@ static void handle_options(int argc, char **argv)
|
||||||
int option_index = 0, c;
|
int option_index = 0, c;
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"help", 0, 0, 'h'},
|
{"help", 0, 0, 'h'},
|
||||||
|
{"oneshot", 0, 0, 'o'},
|
||||||
{"config-file", 1, 0, 'c'},
|
{"config-file", 1, 0, 'c'},
|
||||||
{"debug", 1, 0, 'd'},
|
{"debug", 1, 0, 'd'},
|
||||||
{"daemonize", 0, 0, 'D'},
|
{"daemonize", 0, 0, 'D'},
|
||||||
|
@ -151,7 +155,7 @@ static void handle_options(int argc, char **argv)
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "hc:d:Dse:TV",
|
c = getopt_long(argc, argv, "hoc:d:Dse:TV",
|
||||||
long_options, &option_index);
|
long_options, &option_index);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
@ -161,6 +165,9 @@ static void handle_options(int argc, char **argv)
|
||||||
print_usage();
|
print_usage();
|
||||||
print_help();
|
print_help();
|
||||||
exit(0);
|
exit(0);
|
||||||
|
case 'o':
|
||||||
|
cmdline_opts.oneshot = true;
|
||||||
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
cmdline_opts.config_file = optarg;
|
cmdline_opts.config_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -212,6 +219,9 @@ static void print_nodes(__attribute__((unused)) void *data)
|
||||||
display_update(root);
|
display_update(root);
|
||||||
value_node_del(root);
|
value_node_del(root);
|
||||||
|
|
||||||
|
if (cmdline_opts.oneshot)
|
||||||
|
exit(0);
|
||||||
|
|
||||||
osmo_timer_schedule(&print_timer, 1, 0);
|
osmo_timer_schedule(&print_timer, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue