X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fpb-discover.c;h=70f0365af65fa76281311a52eb603adcb4555801;hp=536f6e65a7b34a88a916417f553eb7414a5773f3;hb=c24015f626b8249ba300ea311892856dc0134c2b;hpb=37428306a270088bfcb1f94362a0fe5b7a5a888e diff --git a/discover/pb-discover.c b/discover/pb-discover.c index 536f6e6..70f0365 100644 --- a/discover/pb-discover.c +++ b/discover/pb-discover.c @@ -11,11 +11,13 @@ #include #include +#include #include "udev.h" #include "user-event.h" #include "discover-server.h" #include "device-handler.h" +#include "network.h" static void print_version(void) { @@ -26,7 +28,8 @@ static void print_usage(void) { print_version(); printf( -"Usage: pb-discover [-h, --help] [-l, --log log-file] [-V, --version]\n"); +"Usage: pb-discover [-a, --no-autoboot] [-h, --help] [-l, --log log-file]\n" +" [-n, --dry-run] [-V, --version]\n"); } /** @@ -40,8 +43,10 @@ enum opt_value {opt_undef = 0, opt_yes, opt_no}; */ struct opts { + enum opt_value no_autoboot; enum opt_value show_help; const char *log_file; + enum opt_value dry_run; enum opt_value show_version; }; @@ -52,14 +57,18 @@ struct opts { 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'}, {"version", no_argument, NULL, 'V'}, { NULL, 0, NULL, 0}, }; - static const char short_options[] = "hl:V"; + static const char short_options[] = "ahl:nV"; static const struct opts default_values = { + .no_autoboot = opt_no, .log_file = "/var/log/petitboot/pb-discover.log", + .dry_run = opt_no, }; *opts = default_values; @@ -72,12 +81,18 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) 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->show_version = opt_yes; break; @@ -101,9 +116,10 @@ int main(int argc, char *argv[]) { struct device_handler *handler; struct discover_server *server; + struct network *network; struct waitset *waitset; struct opts opts; - struct udev *udev; + struct pb_udev *udev; struct user_event *uev; if (opts_parse(&opts, argc, argv)) { @@ -139,13 +155,22 @@ int main(int argc, char *argv[]) signal(SIGINT, sigint_handler); + config_init(NULL); + + if (opts.no_autoboot == opt_yes) + config_set_autoboot(false); + waitset = waitset_create(NULL); server = discover_server_init(waitset); if (!server) return EXIT_FAILURE; - handler = device_handler_init(server); + network = network_init(server, waitset, opts.dry_run == opt_yes); + if (!network) + return EXIT_FAILURE; + + handler = device_handler_init(server, waitset, opts.dry_run == opt_yes); if (!handler) return EXIT_FAILURE; @@ -159,7 +184,6 @@ int main(int argc, char *argv[]) if (!uev) return EXIT_FAILURE; - udev_trigger(udev); user_event_trigger(uev); for (running = 1; running;) { @@ -168,7 +192,8 @@ int main(int argc, char *argv[]) } device_handler_destroy(handler); - waitset_destroy(waitset); + udev_destroy(udev); + config_fini(); pb_log("--- end ---\n");