+static int opts_parse(struct opts *opts, int argc, char *argv[])
+{
+ static const struct option long_options[] = {
+ {"no-autoboot", no_argument, NULL, 'a'},
+ {"help", no_argument, NULL, 'h'},
+ {"log", required_argument, NULL, 'l'},
+ {"dry-run", no_argument, NULL, 'n'},
+ {"verbose", no_argument, NULL, 'v'},
+ {"version", no_argument, NULL, 'V'},
+ { NULL, 0, NULL, 0},
+ };
+ static const char short_options[] = "ahl:nvV";
+ static const struct opts default_values = {
+ .no_autoboot = opt_no,
+ .log_file = "/var/log/petitboot/pb-discover.log",
+ .dry_run = opt_no,
+ .verbose = opt_no,
+ };
+
+ *opts = default_values;
+
+ while (1) {
+ int c = getopt_long(argc, argv, short_options, long_options,
+ NULL);
+
+ if (c == EOF)
+ break;
+
+ switch (c) {
+ case 'a':
+ opts->no_autoboot = opt_yes;
+ break;
+ case 'h':
+ opts->show_help = opt_yes;
+ break;
+ case 'l':
+ opts->log_file = optarg;
+ break;
+ case 'n':
+ opts->dry_run = opt_yes;
+ break;
+ case 'v':
+ opts->verbose = opt_yes;
+ break;
+ case 'V':
+ opts->show_version = opt_yes;
+ break;
+ default:
+ opts->show_help = opt_yes;
+ return -1;
+ }
+ }
+
+ return optind != argc;
+}
+
+static int running;
+
+static void sigint_handler(int __attribute__((unused)) signum)
+{
+ running = 0;
+}