[PATCH] ui/ncurses: Spawn shell in exit handler

Samuel Mendoza-Jonas sam at mendozajonas.com
Fri Sep 15 15:42:32 AEST 2017


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 at mendozajonas.com>
---
 ui/ncurses/nc-cui.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

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]);
-- 
2.14.1



More information about the Petitboot mailing list