X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Ftwin%2Fpbt-client.c;h=ed12e5a993a7d381550d4eac54e70f13d3f8263b;hp=a2c3e931204bc639af070ea2d26b618b547bbd48;hb=e01ca9726e5ce96605cb57595999885fde18884b;hpb=bd0c684c9941c24ee4191f4550ec966d5b1fa8ab;ds=sidebyside diff --git a/ui/twin/pbt-client.c b/ui/twin/pbt-client.c index a2c3e93..ed12e5a 100644 --- a/ui/twin/pbt-client.c +++ b/ui/twin/pbt-client.c @@ -46,6 +46,7 @@ void pbt_frame_status_printf(struct pbt_frame *frame, const char *format, ...) va_start(ap, format); // TODO + (void)frame; va_end(ap); } @@ -63,8 +64,7 @@ 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); @@ -185,12 +185,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); @@ -262,9 +261,10 @@ static void pbt_client_destructor(struct pbt_client *client) memset(client, 0, sizeof(*client)); } -struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int width, - unsigned int height, - int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *)) +struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, + unsigned int width, unsigned int height, + int (*kexec_cb)(struct pbt_client *, struct pb_opt_data *), + int start_deamon, int dry_run) { struct pbt_client *pbt_client; unsigned int i; @@ -281,6 +281,7 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int w 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); @@ -288,18 +289,35 @@ struct pbt_client *pbt_client_init(enum pbt_twin_backend backend, unsigned int w goto fail_scr_init; /* Loop here for scripts that just started the server. */ -if (1) { - 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); } + if (!pbt_client->discover_client && start_deamon) { + int result; + + start_deamon = 0; + + result = pb_start_daemon(); + + if (!result) + goto retry_start; + + pb_log("%s: discover_client_init failed.\n", __func__); + fprintf(stderr, "%s: error: discover_client_init failed.\n", + __func__); + fprintf(stderr, "could not start pb-discover, the petitboot " + "daemon.\n"); + goto fail_client_init; + } + if (!pbt_client->discover_client) { pb_log("%s: discover_client_init failed.\n", __func__); fprintf(stderr, "%s: error: discover_client_init failed.\n", @@ -312,7 +330,7 @@ if (1) { waiter_register(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: