def_prog_mode();
- result = pb_run_cmd(cmd_argv);
+ result = pb_run_cmd(cmd_argv, 1, 0);
reset_prog_mode();
redrawwin(cui->current->main_ncw);
clear();
mvaddstr(1, 0, "system is going down now...");
refresh();
- sleep(60);
+ sleep(cui->dry_run ? 1 : 60);
}
pb_log("%s: failed: %s\n", __func__, cod->kd->image);
return old;
}
+/**
+ * cui_process_key - Process input on stdin.
+ */
+
static int cui_process_key(void *arg)
{
struct cui *cui = cui_from_arg(arg);
return 0;
}
+/**
+ * cui_process_js - Process joystick events.
+ */
+
+static int cui_process_js(void *arg)
+{
+ struct cui *cui = cui_from_arg(arg);
+ int c;
+
+ c = pjs_process_event(cui->pjs);
+
+ if (c) {
+ ungetch(c);
+ cui_process_key(arg);
+ }
+
+ return 0;
+}
/**
* cui_client_process_socket - Process a socket event from the discover server.
*/
*/
struct cui *cui_init(void* platform_info,
- int (*on_kexec)(struct cui *, struct cui_opt_data *))
+ int (*on_kexec)(struct cui *, struct cui_opt_data *),
+ int (*js_map)(const struct js_event *e), int start_deamon, int dry_run)
{
struct cui *cui;
struct discover_client *client;
cui->platform_info = platform_info;
cui->on_kexec = on_kexec;
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. */
- for (i = 10; i; i--) {
+retry_start:
+ for (i = start_deamon ? 2 : 10; i; i--) {
client = discover_client_init(&cui_client_ops, cui);
- if (client)
+ if (client || !i)
break;
pb_log("%s: waiting for server %d\n", __func__, i);
sleep(1);
}
+ if (!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 (!client) {
pb_log("%s: discover_client_init failed.\n", __func__);
fprintf(stderr, "%s: error: discover_client_init failed.\n",
atexit(nc_atexit);
nc_start();
- waiter_register(discover_client_get_fd(client), WAIT_IN,
- cui_client_process_socket, client);
+ 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);
- waiter_register(STDIN_FILENO, WAIT_IN, cui_process_key, cui);
+ if (js_map) {
+
+ cui->pjs = pjs_init(cui, js_map);
+
+ if (cui->pjs)
+ waiter_register(cui->waitset, pjs_get_fd(cui->pjs),
+ WAIT_IN, cui_process_js, cui);
+ }
return cui;
cui->current->post(cui->current);
while (1) {
- int result = waiter_poll();
+ int result = waiter_poll(cui->waitset);
if (result < 0 && errno != EINTR) {
pb_log("%s: poll: %s\n", __func__, strerror(errno));