]> git.ozlabs.org Git - petitboot/commitdiff
ui/ncurses: Spawn shell in exit handler
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 29 Aug 2017 03:52:31 +0000 (13:52 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Wed, 4 Oct 2017 05:41:17 +0000 (16:41 +1100)
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>
configure.ac
lib/system/system.c
lib/system/system.h
ui/ncurses/nc-cui.c

index 2c2f23b92662c92ad75f92d5d86f8040c110d468..a4b5fc78693fc3046cce5b3c00e1bfa56274e6f8 100644 (file)
@@ -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],
index 33f79eddad5f8d25e321b13a79d72072a9921d40..b1121a17a4df6e59ccc9f66541845ed14c49ecb0 100644 (file)
@@ -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
index e803391601d14f7e2c94991e5f92ab00c4137cd0..d27c2cd4d79d89b342587831e3b3dde6f74b6fa8 100644 (file)
@@ -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;
index 8fba7d5119e50c4a2f8308eed1169db5ecf6903a..6ced24c3857aec9302ef6f75a712e966e2e543f0 100644 (file)
@@ -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]);