diff mbox series

ui/ncurses: Spawn shell in exit handler

Message ID 20170915054232.31136-1-sam@mendozajonas.com
State Accepted
Headers show
Series ui/ncurses: Spawn shell in exit handler | expand

Commit Message

Sam Mendoza-Jonas Sept. 15, 2017, 5:42 a.m. UTC
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 <sam@mendozajonas.com>
---
 ui/ncurses/nc-cui.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
index 8fba7d5..60bd4e2 100644
--- a/ui/ncurses/nc-cui.c
+++ b/ui/ncurses/nc-cui.c
@@ -151,7 +151,20 @@  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);
+
+	const char *argv[] = {
+		"/bin/sh",
+		"-c",
+		"echo \"Exiting petitboot. Type 'exit' to return.\";\
+		 echo \"You may run 'pb-sos' to gather diagnostic data\";\
+		 /bin/sh",
+		NULL
+	};
+
+	cui_run_cmd(cui, argv);
+
+	nc_scr_status_printf(cui->current, _("Returned from shell"));
 }
 
 /**
@@ -173,6 +186,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 +199,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]);