X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fpb-discover.c;h=fd370685653f979419943ee03db5c3b64f311f5f;hp=d8708a3d40194d9d2017d41058a4ed57f8971b6e;hb=03fe06fa71f065e918c46a65e6a45e76063a07eb;hpb=729bcafedd3b117c031c413fac2e2d2096d62510 diff --git a/discover/pb-discover.c b/discover/pb-discover.c index d8708a3..fd37068 100644 --- a/discover/pb-discover.c +++ b/discover/pb-discover.c @@ -11,16 +11,14 @@ #include #include -#include #include #include +#include -#include "udev.h" -#include "user-event.h" #include "discover-server.h" #include "device-handler.h" -#include "network.h" #include "sysinfo.h" +#include "platform.h" static void print_version(void) { @@ -32,7 +30,7 @@ static void print_usage(void) print_version(); printf( "Usage: pb-discover [-a, --no-autoboot] [-h, --help] [-l, --log log-file]\n" -" [-n, --dry-run] [-V, --version]\n"); +" [-n, --dry-run] [-v, --verbose] [-V, --version]\n"); } /** @@ -51,6 +49,7 @@ struct opts { const char *log_file; enum opt_value dry_run; enum opt_value show_version; + enum opt_value verbose; }; /** @@ -64,14 +63,16 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) {"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:nV"; + 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; @@ -96,6 +97,9 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) case 'n': opts->dry_run = opt_yes; break; + case 'v': + opts->verbose = opt_yes; + break; case 'V': opts->show_version = opt_yes; break; @@ -119,14 +123,15 @@ int main(int argc, char *argv[]) { struct device_handler *handler; struct discover_server *server; - struct network *network; struct waitset *waitset; struct procset *procset; struct opts opts; - struct pb_udev *udev; - struct user_event *uev; FILE *log; + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + if (opts_parse(&opts, argc, argv)) { print_usage(); return EXIT_FAILURE; @@ -153,6 +158,9 @@ int main(int argc, char *argv[]) } pb_log_init(log); + if (opts.verbose == opt_yes) + pb_log_set_debug(true); + pb_log("--- pb-discover ---\n"); /* we look for closed sockets when we write, so ignore SIGPIPE */ @@ -170,10 +178,16 @@ int main(int argc, char *argv[]) if (!procset) return EXIT_FAILURE; - config_init(NULL); + platform_init(NULL); if (opts.no_autoboot == opt_yes) config_set_autoboot(false); + if (config_get()->lang) + setlocale(LC_ALL, config_get()->lang); + + if (config_get()->debug) + pb_log_set_debug(true); + system_info_init(server); handler = device_handler_init(server, waitset, opts.dry_run == opt_yes); @@ -182,30 +196,14 @@ int main(int argc, char *argv[]) discover_server_set_device_source(server, handler); - /* init our device sources: udev, network and user events */ - udev = udev_init(waitset, handler); - if (!udev) - return EXIT_FAILURE; - - network = network_init(handler, waitset, opts.dry_run == opt_yes); - if (!network) - return EXIT_FAILURE; - - uev = user_event_init(waitset, handler); - if (!uev) - return EXIT_FAILURE; - for (running = 1; running;) { if (waiter_poll(waitset)) break; } - network_shutdown(network); device_handler_destroy(handler); - user_event_destroy(uev); - udev_destroy(udev); discover_server_destroy(server); - config_fini(); + platform_fini(); talloc_free(waitset); pb_log("--- end ---\n");