]> git.ozlabs.org Git - petitboot/blobdiff - ui/twin/pbt-client.c
ui: pb_kexec_data -> pb_boot_data
[petitboot] / ui / twin / pbt-client.c
index 1170b34555664c449fdbb12f0c3cdaf19541cc9b..39facf5fe73094b16dc8759086c43708daa2b6f3 100644 (file)
@@ -23,6 +23,8 @@
 #include <assert.h>
 #include <string.h>
 
+#include <pb-protocol/pb-protocol.h>
+
 #include "pbt-client.h"
 
 #include "log/log.h"
@@ -46,6 +48,7 @@ void pbt_frame_status_printf(struct pbt_frame *frame, const char *format, ...)
 
        va_start(ap, format);
        // TODO
+       (void)frame;
        va_end(ap);
 }
 
@@ -63,14 +66,13 @@ static int pbt_client_run_kexec(struct pbt_item *item)
        result = item->pbt_client->kexec_cb(item->pbt_client, opt_data);
 
        if (!result) {
-               //mvaddstr(1, 0, "system is going down now...");
-               sleep(60);
+               sleep(item->pbt_client->dry_run ? 1 : 60);
        }
 
-       pb_log("%s: failed: %s\n", __func__, opt_data->kd->image);
+       pb_log("%s: failed: %s\n", __func__, opt_data->bd->image);
 
        pbt_frame_status_printf(&item->pbt_client->frame, "Failed: kexec %s",
-               opt_data->kd->image);
+               opt_data->bd->image);
 
        return 0;
 }
@@ -143,12 +145,12 @@ static int pbt_device_add(struct device *dev, struct pbt_client *client)
 
                i->data = opt_data = talloc(i, struct pb_opt_data);
                opt_data->name = opt->name;
-               opt_data->kd = talloc(i, struct pb_kexec_data);
-               opt_data->kd->image = talloc_strdup(opt_data->kd,
+               opt_data->bd = talloc(i, struct pb_boot_data);
+               opt_data->bd->image = talloc_strdup(opt_data->bd,
                        opt->boot_image_file);
-               opt_data->kd->initrd = talloc_strdup(opt_data->kd,
+               opt_data->bd->initrd = talloc_strdup(opt_data->bd,
                        opt->initrd_file);
-               opt_data->kd->args = talloc_strdup(opt_data->kd,
+               opt_data->bd->args = talloc_strdup(opt_data->bd,
                        opt->boot_args);
                opt_data->dev = dev;
                opt_data->opt = opt;
@@ -185,12 +187,11 @@ static void pbt_device_remove(struct device *dev, struct pbt_client *client)
 {
        struct pbt_frame *const frame = &client->frame;
        struct list *i_list = frame->top_menu->item_list;
+       twin_window_t *last_window = NULL;
        struct pbt_item *removed_item;
        struct pbt_item *prev_item;
        struct pbt_item *next_item;
        struct pbt_item *i;
-       twin_window_t *last_window;
-       struct boot_option *opt;
 
        pb_log("%s: %p %s: n_options %d\n", __func__, dev, dev->id,
                dev->n_options);
@@ -280,22 +281,25 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend,
 
        talloc_set_destructor(pbt_client, (void *)pbt_client_destructor);
 
+       pbt_client->waitset = waitset_create(pbt_client);
+
        pbt_client->sig = "pbt_client";
        pbt_client->kexec_cb = kexec_cb;
        pbt_client->dry_run = dry_run;
-       pbt_client->frame.scr = pbt_scr_init(pbt_client, backend, width, height,
-               NULL, NULL);
+       pbt_client->frame.scr = pbt_scr_init(pbt_client, pbt_client->waitset,
+                       backend, width, height, NULL, NULL);
+
 
        if (!pbt_client->frame.scr)
                goto fail_scr_init;
 
        /* Loop here for scripts that just started the server. */
-if (1) {
-start_deamon:
-       for (i = 10; i; i--) {
+
+retry_start:
+       for (i = start_deamon ? 2 : 10; i; i--) {
                pbt_client->discover_client
                        = discover_client_init(&pbt_client_ops, pbt_client);
-               if (pbt_client->discover_client)
+               if (pbt_client->discover_client || !i)
                        break;
                pb_log("%s: waiting for server %d\n", __func__, i);
                sleep(1);
@@ -309,7 +313,7 @@ start_deamon:
                result = pb_start_daemon();
 
                if (!result)
-                       goto start_deamon;
+                       goto retry_start;
 
                pb_log("%s: discover_client_init failed.\n", __func__);
                fprintf(stderr, "%s: error: discover_client_init failed.\n",
@@ -328,10 +332,11 @@ start_deamon:
                goto fail_client_init;
        }
 
-       waiter_register(discover_client_get_fd(pbt_client->discover_client),
-               WAIT_IN, (waiter_cb)discover_client_process,
-               pbt_client->discover_client);
-}
+       waiter_register(pbt_client->waitset,
+                       discover_client_get_fd(pbt_client->discover_client),
+                       WAIT_IN, (waiter_cb)discover_client_process,
+                       pbt_client->discover_client);
+
        return pbt_client;
 
 fail_client_init: