From: Samuel Mendoza-Jonas Date: Tue, 29 Aug 2017 03:52:31 +0000 (+1000) Subject: ui/ncurses: Spawn shell in exit handler X-Git-Tag: v1.6.1~2 X-Git-Url: https://git.ozlabs.org/?p=petitboot;a=commitdiff_plain;h=e1e2ca68;ds=sidebyside ui/ncurses: Spawn shell in exit handler In cui_on_exit()_ instead of exiting the program spawn a sh instance. This allows the user to drop to the shell and return without losing any custom boot options, for example. SIGINT still calls cui_abort() to properly exit Petitboot. Signed-off-by: Samuel Mendoza-Jonas --- diff --git a/configure.ac b/configure.ac index 2c2f23b..a4b5fc7 100644 --- a/configure.ac +++ b/configure.ac @@ -336,6 +336,7 @@ DEFINE_HOST_PROG(VGSCAN, vgscan, [/usr/sbin/vgscan]) DEFINE_HOST_PROG(VGCHANGE, vgchange, [/usr/sbin/vgchange]) DEFINE_HOST_PROG(PB_PLUGIN, pb-plugin, [/usr/sbin/pb-plugin]) DEFINE_HOST_PROG(PB_EXEC, pb-exec, [/usr/sbin/pb-exec]) +DEFINE_HOST_PROG(SH, sh, [/bin/sh]) AC_ARG_WITH( [tftp], diff --git a/lib/system/system.c b/lib/system/system.c index 33f79ed..b1121a1 100644 --- a/lib/system/system.c +++ b/lib/system/system.c @@ -32,6 +32,7 @@ const struct pb_system_apps pb_system_apps = { .vgchange = HOST_PROG_VGCHANGE, .pb_plugin = HOST_PROG_PB_PLUGIN, .pb_exec = HOST_PROG_PB_EXEC, + .sh = HOST_PROG_SH, }; #ifndef TFTP_TYPE diff --git a/lib/system/system.h b/lib/system/system.h index e803391..d27c2cd 100644 --- a/lib/system/system.h +++ b/lib/system/system.h @@ -17,6 +17,7 @@ struct pb_system_apps { const char *vgchange; const char *pb_plugin; const char *pb_exec; + const char *sh; }; extern const struct pb_system_apps pb_system_apps; diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 8fba7d5..6ced24c 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -151,7 +151,30 @@ void cui_resize(struct cui *cui) void cui_on_exit(struct pmenu *menu) { - cui_abort(cui_from_pmenu(menu)); + struct cui *cui = cui_from_pmenu(menu); + char *sh_cmd; + + sh_cmd = talloc_asprintf(cui, + "echo \"Exiting petitboot. Type 'exit' to return.\";\ + echo \"You may run 'pb-sos' to gather diagnostic data\";\ + %s", pb_system_apps.sh); + + if (!sh_cmd) { + pb_log("Failed to allocate shell arguments\n"); + return; + } + + const char *argv[] = { + pb_system_apps.sh, + "-c", + sh_cmd, + NULL + }; + + cui_run_cmd(cui, argv); + + nc_scr_status_printf(cui->current, _("Returned from shell")); + talloc_free(sh_cmd); } /** @@ -173,6 +196,10 @@ int cui_run_cmd(struct cui *cui, const char **cmd_argv) nc_scr_status_printf(cui->current, _("Running %s..."), cmd_argv[0]); + nc_scr_unpost(cui->current); + clear(); + refresh(); + def_prog_mode(); endwin(); @@ -182,6 +209,7 @@ int cui_run_cmd(struct cui *cui, const char **cmd_argv) refresh(); redrawwin(cui->current->main_ncw); + nc_scr_post(cui->current); if (result) { pb_log("%s: failed: '%s'\n", __func__, cmd_argv[0]);