101 lines
2.1 KiB
C
101 lines
2.1 KiB
C
#include "master.h"
|
|
#include "config.h"
|
|
#include "version.h"
|
|
|
|
#include "utils/logger.h"
|
|
|
|
#include <getopt.h>
|
|
|
|
static int get_app_options(int argc, char* argv[]);
|
|
static void show_usage();
|
|
static void show_version();
|
|
|
|
static int
|
|
get_app_options(int argc, char* argv[])
|
|
{
|
|
int option_idx = 0;
|
|
|
|
static char short_opts[] = "hv";
|
|
static struct option long_options[] = {
|
|
{"help", no_argument, NULL, 'h'},
|
|
{"version", no_argument, NULL, 'v'},
|
|
{NULL, 0, NULL, 0 }
|
|
};
|
|
|
|
while (1) {
|
|
int c = getopt_long(argc, argv, short_opts, long_options, &option_idx);
|
|
if (c == -1)
|
|
break;
|
|
|
|
switch (c) {
|
|
case 'h':
|
|
show_usage();
|
|
exit(EXIT_SUCCESS);
|
|
break;
|
|
case 'v':
|
|
show_version();
|
|
exit(EXIT_SUCCESS);
|
|
break;
|
|
|
|
default:
|
|
fprintf(stderr, "get_app_options. unknown option: %s\n", optarg);
|
|
goto print_and_exit_with_error;
|
|
} /* switch (c) */
|
|
} /* while (true) */
|
|
|
|
if (optind < argc) {
|
|
fprintf(stderr, "non-option arguments: ");
|
|
while (optind < argc) {
|
|
fprintf(stderr, "%s ", argv[optind++]);
|
|
}
|
|
fprintf(stderr, "\n");
|
|
goto print_and_exit_with_error;
|
|
}
|
|
|
|
/* options successfully parsed */
|
|
return 0;
|
|
|
|
print_and_exit_with_error:
|
|
show_usage();
|
|
exit(EXIT_FAILURE);
|
|
return -1;
|
|
}
|
|
|
|
|
|
static void
|
|
show_usage()
|
|
{
|
|
printf("Usage: " APP_NAME " [-hv]\n"
|
|
"\n"
|
|
"Options:\n"
|
|
" -h, --help : Show this help, then exit\n"
|
|
" -v, --version : Show version, then exit\n");
|
|
}
|
|
|
|
|
|
static void
|
|
show_version()
|
|
{
|
|
printf("Version: " APP_VERSION "\n");
|
|
}
|
|
|
|
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
int rc = -1;
|
|
service_manager_conf_t conf;
|
|
|
|
get_app_options(argc, argv);
|
|
|
|
if (service_manager_load_conf(CONF_NAME, &conf)) {
|
|
LOG_ERROR("service_manager_load_conf failed");
|
|
goto end;
|
|
}
|
|
|
|
rc = master_main(&conf);
|
|
|
|
end:
|
|
service_manager_clear_conf(&conf);
|
|
return rc;
|
|
}
|