]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-cui.c
Move --dry-run option to discover server
[petitboot] / ui / ncurses / nc-cui.c
index ae3d7c6d9741da102655850700b7b534b894fd94..37ba1c4477558b76479f0debe693a5a78de69855 100644 (file)
@@ -135,14 +135,13 @@ static int cui_boot(struct pmenu_item *item)
        struct cui_opt_data *cod = cod_from_item(item);
 
        assert(cui->current == &cui->main->scr);
-       assert(cui->on_boot);
 
        pb_log("%s: %s\n", __func__, cod->name);
        nc_scr_status_printf(cui->current, "Booting %s...", cod->name);
 
        def_prog_mode();
 
-       result = cui->on_boot(cui, cod);
+       result = discover_client_boot(cui->client, cod->dev, cod->opt, cod->bd);
 
        reset_prog_mode();
        redrawwin(cui->current->main_ncw);
@@ -151,12 +150,11 @@ static int cui_boot(struct pmenu_item *item)
                clear();
                mvaddstr(1, 0, "system is going down now...");
                refresh();
-               sleep(cui->dry_run ? 1 : 60);
+       } else {
+               nc_scr_status_printf(cui->current,
+                               "Failed: boot %s", cod->bd->image);
        }
 
-       pb_log("%s: failed: %s\n", __func__, cod->bd->image);
-       nc_scr_status_printf(cui->current, "Failed: kexec %s", cod->bd->image);
-
        return 0;
 }
 
@@ -264,17 +262,6 @@ static int cui_process_js(void *arg)
 
        return 0;
 }
-/**
- * cui_client_process_socket - Process a socket event from the discover server.
- */
-
-static int cui_client_process_socket(void *arg)
-{
-       struct discover_client *client = arg;
-
-       discover_client_process(client);
-       return 0;
-}
 
 /**
  * cui_handle_timeout - Handle the timeout.
@@ -533,11 +520,9 @@ static struct discover_client_ops cui_client_ops = {
  */
 
 struct cui *cui_init(void* platform_info,
-       int (*on_boot)(struct cui *, struct cui_opt_data *),
-       int (*js_map)(const struct js_event *e), int start_deamon, int dry_run)
+       int (*js_map)(const struct js_event *e), int start_deamon)
 {
        struct cui *cui;
-       struct discover_client *client;
        unsigned int i;
 
        cui = talloc_zero(NULL, struct cui);
@@ -550,23 +535,22 @@ struct cui *cui_init(void* platform_info,
 
        cui->c_sig = pb_cui_sig;
        cui->platform_info = platform_info;
-       cui->on_boot = on_boot;
        cui->timer.handle_timeout = cui_handle_timeout;
-       cui->dry_run = dry_run;
        cui->waitset = waitset_create(cui);
 
        /* Loop here for scripts that just started the server. */
 
 retry_start:
        for (i = start_deamon ? 2 : 10; i; i--) {
-               client = discover_client_init(&cui_client_ops, cui);
-               if (client || !i)
+               cui->client = discover_client_init(cui->waitset,
+                               &cui_client_ops, cui);
+               if (cui->client || !i)
                        break;
                pb_log("%s: waiting for server %d\n", __func__, i);
                sleep(1);
        }
 
-       if (!client && start_deamon) {
+       if (!cui->client && start_deamon) {
                int result;
 
                start_deamon = 0;
@@ -584,7 +568,7 @@ retry_start:
                goto fail_client_init;
        }
 
-       if (!client) {
+       if (!cui->client) {
                pb_log("%s: discover_client_init failed.\n", __func__);
                fprintf(stderr, "%s: error: discover_client_init failed.\n",
                        __func__);
@@ -596,9 +580,6 @@ retry_start:
        atexit(nc_atexit);
        nc_start();
 
-       waiter_register(cui->waitset, discover_client_get_fd(client), WAIT_IN,
-                       cui_client_process_socket, client);
-
        waiter_register(cui->waitset, STDIN_FILENO, WAIT_IN,
                        cui_process_key, cui);