Skip to contentSkip to conversation

emu: fix unusable terminal after exit

PATCH In review Michael Chang 2 participants 3 messages Dec 23, 2015 – Dec 28, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 emu: fix unusable terminal after exit

The grub-emu's grub_exit function will exit immediately without any housekeeping work for restoring terminal settings and leaves unusable terminal in the end. Fix the problem by calling grub_reboot to allow doing the housekeeping work and restoring the terminal settings.

---
 grub-core/commands/minicmd.c | 4 ++++
 1 file changed, 4 insertions(+)
grub-core/commands/minicmd.c +4 -0
index a3a1182..63ffeb5 100644
@@ -181,7 +181,11 @@ grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
 		    int argc __attribute__ ((unused)),
 		    char *argv[] __attribute__ ((unused)))
 {
+#if defined (GRUB_MACHINE_EMU)
+  grub_reboot ();
+#else
   grub_exit ();
+#endif
   /* Not reached.  */
 }
 
Signature · 1 line
2.6.3
#1 lore raw
Quoted 15 lines · Michael Chang

The grub-emu's grub_exit function will exit immediately without any housekeeping work for restoring terminal settings and leaves unusable terminal in the end. Fix the problem by calling grub_reboot to allow doing the housekeeping work and restoring the terminal settings.

---
 grub-core/commands/minicmd.c | 4 ++++
 1 file changed, 4 insertions(+)
grub-core/commands/minicmd.c +0 -0
index a3a1182..63ffeb5 100644
@@ -181,7 +181,11 @@ grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
                    int argc __attribute__ ((unused)),

grub-core/commands/minicmd.c grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)), · line 191

Quoted 10 lines
grub-core/commands/minicmd.c +4 -0
                    char *argv[] __attribute__ ((unused)))
 {
+#if defined (GRUB_MACHINE_EMU)
+  grub_reboot ();
+#else
   grub_exit ();
+#endif
   /* Not reached.  */
 }
 

No, please. Just make EMU grub_exit do the right thing (assuming it is the right thing :)

#2 lore raw
Quoted 21 lines · Andrei Borzenkov
Quoted 20 lines · Michael Chang

The grub-emu's grub_exit function will exit immediately without any housekeeping work for restoring terminal settings and leaves unusable terminal in the end. Fix the problem by calling grub_reboot to allow doing the housekeeping work and restoring the terminal settings.

---
 grub-core/commands/minicmd.c | 4 ++++
 1 file changed, 4 insertions(+)
grub-core/commands/minicmd.c +3 -0
index a3a1182..63ffeb5 100644
@@ -181,7 +181,11 @@ grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
                    int argc __attribute__ ((unused)),
                    char *argv[] __attribute__ ((unused)))
 {
+#if defined (GRUB_MACHINE_EMU)
+  grub_reboot ();
+#else
Quoted 8 lines

grub-core/commands/minicmd.c grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)), · line 191

Quoted 5 lines
grub-core/commands/minicmd.c +1 -0
   grub_exit ();
+#endif
   /* Not reached.  */
 }
 

No, please. Just make EMU grub_exit do the right thing (assuming it is the right thing :)

I'm not sure it's right thing either, that's why I was not trying to modify grub_exit because EMU shares it with utils, as souce file grub-core/kern/emu/misc.c is also part of libgrubkern.a used also in other platforms.

But anyway, please check attached patch again, which tries to separate the EMU's grub_exit with the one in libgrubkern.a.

Thanks.

grub-core/kern/emu/main.c +6 -0
index 4b50913..221aa12 100644
@@ -66,6 +66,12 @@ grub_reboot (void)
 }
 
 void
+grub_exit (void)
+{
+  grub_reboot ();
+}
+
+void
 grub_machine_init (void)
 {
 }
grub-core/kern/emu/misc.c +2 -0
index bb606da..9353fa7 100644
@@ -134,11 +134,13 @@ xasprintf (const char *fmt, ...)
 }
 #endif
 
+#if !defined (GRUB_MACHINE_EMU) || defined (GRUB_UTIL)
 void
 grub_exit (void)
 {
   exit (1);
 }
+#endif
 
 grub_uint64_t
 grub_get_time_ms (void)