ui/ncurses: Spawn shell in exit handler
[petitboot] / ui / ncurses / nc-cui.c
index 8fba7d5119e50c4a2f8308eed1169db5ecf6903a..6ced24c3857aec9302ef6f75a712e966e2e543f0 100644 (file)
@@ -151,7 +151,30 @@ void cui_resize(struct cui *cui)
 
 void cui_on_exit(struct pmenu *menu)
 {
 
 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_status_printf(cui->current, _("Running %s..."), cmd_argv[0]);
 
+       nc_scr_unpost(cui->current);
+       clear();
+       refresh();
+
        def_prog_mode();
        endwin();
 
        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);
        refresh();
 
        redrawwin(cui->current->main_ncw);
+       nc_scr_post(cui->current);
 
        if (result) {
                pb_log("%s: failed: '%s'\n", __func__, cmd_argv[0]);
 
        if (result) {
                pb_log("%s: failed: '%s'\n", __func__, cmd_argv[0]);