Skip to contentSkip to conversation

tell the user why they are in rescue mode

PATCH In review Sam Morris 2 participants 6 messages Feb 8, 2008 – Feb 10, 2008

lore
Share & tools
lore

Sam Morris

author
#0 lore raw

PATCH 1/1 tell the user why they are in rescue mode

Here's a patch that explains to the user why they are being sent to rescue mode in cast normal mode fails.

I've also corrected a grammatical error in the 'entering rescue mode' message.

Signature · 5 lines
Sam Morris
http://robots.org.uk/

PGP key id 1024D/5EA01078
3412 EA18 1277 354B 991B  C869 B219 7FDB 5EA0 1078
kern/main.c +7 -2
diff -ru grub2-1.96+20080203+orig/kern/main.c grub2-1.96+20080203+sam/kern/main.c
@@ -102,8 +102,13 @@
   /* Load the module.  */
   grub_dl_load ("normal");
   
-  /* Ignore any error, because we have the rescue mode anyway.  */
-  grub_errno = GRUB_ERR_NONE;
+  if (grub_errno != GRUB_ERR_NONE)
+    {
+      grub_printf ("Unable to enter 'normal' mode (error %d: %s)\n", grub_errno, grub_errmsg);
+
+      /* We're about to continue into rescue mode, so clear the error. */
+      grub_errno = GRUB_ERR_NONE;
+    }
 }
 
 /* The main routine.  */
kern/rescue.c +1 -1
diff -ru grub2-1.96+20080203+orig/kern/rescue.c grub2-1.96+20080203+sam/kern/rescue.c
@@ -618,7 +618,7 @@
   /* First of all, attempt to execute the normal mode.  */
   attempt_normal_mode ();
 
-  grub_printf ("Entering into rescue mode...\n");
+  grub_printf ("Entering rescue mode...\n");
   
   grub_rescue_register_command ("boot", grub_rescue_cmd_boot,
 				"boot an operating system");
#1 lore raw

Hi Sam,

Quoted 6 lines · Sam Morris

diff -ru grub2-1.96+20080203+orig/kern/main.c grub2-1.96+20080203+sam/kern/main.c

kern/main.c +0 -0
@@ -102,8 +102,13 @@
   /* Load the module.  */
   grub_dl_load ("normal");

kern/main.c line 111

Quoted 10 lines
kern/main.c +7 -2
 
-  /* Ignore any error, because we have the rescue mode anyway.  */
-  grub_errno = GRUB_ERR_NONE;
+  if (grub_errno != GRUB_ERR_NONE)
+    {
+      grub_printf ("Unable to enter 'normal' mode (error %d: %s)\n", grub_errno, grub_errmsg);
+
+      /* We're about to continue into rescue mode, so clear the error. */
+      grub_errno = GRUB_ERR_NONE;
+    }

I just checked, and it seems we already have a function for this:
grub_print_error(). If you just invoke this function, do you get the desired result?

Also, I wonder why the existing grub_print_error() call in the rescue loop doesn't handle this already (in kern/rescue.c).

Perhaps all you need to do is remove these two lines?

kern/main.c 2008-02-08 02:09:03.000000000 +0100 renamed from kern/main.c 2008-01-05 13:04:35.000000000 +0100 +0 -3
diff -ur grub2/kern/main.c tmp/kern/main.c
@@ -101,9 +101,6 @@
 {
   /* Load the module.  */
   grub_dl_load ("normal");
-
-  /* Ignore any error, because we have the rescue mode anyway.  */
-  grub_errno = GRUB_ERR_NONE;
 }
 
 /* The main routine.  */
Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
author
#2 lore raw
Quoted 21 lines · Robert Millan

Hi Sam,

Quoted 13 lines · Sam Morris

diff -ru grub2-1.96+20080203+orig/kern/main.c
grub2-1.96+20080203+sam/kern/main.c ---
grub2-1.96+20080203+orig/kern/main.c 2008-01-05 12:04:35.000000000
+0000 +++ grub2-1.96+20080203+sam/kern/main.c 2008-02-07
08:41:01.000000000 +0000 @@ -102,8 +102,13 @@
/* Load the module. */
grub_dl_load ("normal");

- /* Ignore any error, because we have the rescue mode anyway. */ - grub_errno = GRUB_ERR_NONE;

(quoted diff) +3 -0
+  if (grub_errno != GRUB_ERR_NONE)
+    {
+      grub_printf ("Unable to enter 'normal' mode (error %d: %s)\n",
Quoted 4 lines

grub_errno, grub_errmsg); +
+ /* We're about to continue into rescue mode, so clear the error.
*/ + grub_errno = GRUB_ERR_NONE;
+ }

Quoted 3 lines

I just checked, and it seems we already have a function for this:
grub_print_error(). If you just invoke this function, do you get the desired result?

Yes, it works fine.

Quoted 16 lines

Also, I wonder why the existing grub_print_error() call in the rescue loop doesn't handle this already (in kern/rescue.c).

Perhaps all you need to do is remove these two lines?

diff -ur grub2/kern/main.c tmp/kern/main.c --- grub2/kern/main.c

2008-01-05 13:04:35.000000000 +0100 +++ tmp/kern/main.c     2008-02-08
02:09:03.000000000 +0100 @@ -101,9 +101,6 @@
 {
   /* Load the module.  */
   grub_dl_load ("normal");
(quoted diff) +0 -2
-
-  /* Ignore any error, because we have the rescue mode anyway.  */ - 

grub_errno = GRUB_ERR_NONE;
}

Quoted 1 line

/* The main routine. */

While that works, the output looks like this:

Entering rescue mode...
error: out of disk

Quoted 1 line

_

Which does not present the information in the clearest possible way: it looks like the error happened in the rescue mode code, instead of the normal mode code.

Also, the error message could be lost if any of the code between the start of grub_enter_rescue_mode and its call to grub_print_error itself triggers an error.

For these reasons I think it's better to call grub_print_error from within grub_load_normal.

BTW, does anyone know the first thing grub_enter_rescue_mode does is call attempt_normal_mode?

Signature · 5 lines
Sam Morris
http://robots.org.uk/
 
PGP key id 1024D/5EA01078
3412 EA18 1277 354B 991B  C869 B219 7FDB 5EA0 1078
#3 lore raw
Quoted 11 lines · Sam Morris

While that works, the output looks like this:

Entering rescue mode...
error: out of disk

Quoted 1 line

_

Which does not present the information in the clearest possible way: it looks like the error happened in the rescue mode code, instead of the normal mode code.

Quoted 6 lines

Also, the error message could be lost if any of the code between the start of grub_enter_rescue_mode and its call to grub_print_error itself triggers an error.

For these reasons I think it's better to call grub_print_error from within grub_load_normal.

Agreed. See attached patch. Does this work as expected ?

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)

2008-02-08 Robert Millan <[email protected]>

* kern/main.c (grub_load_normal_mode): Do not reset `grub_errno'. Call grub_print_error() instead. This will let user know why we're entering rescue mode.
Based on suggestions from Sam Morris.

kern/main.c renamed from grub2/kern/main.c +2 -2
diff -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp -N ../grub2/kern/main.c ./kern/main.c
@@ -102,8 +102,8 @@ grub_load_normal_mode (void)
   /* Load the module.  */
   grub_dl_load ("normal");
   
-  /* Ignore any error, because we have the rescue mode anyway.  */
-  grub_errno = GRUB_ERR_NONE;
+  /* Something went wrong.  Print errors here to let user know why we're entering rescue mode.  */
+  grub_print_error ();
 }
 
 /* The main routine.  */
author
#4 lore raw
Quoted 12 lines · Robert Millan
Quoted 11 lines · Sam Morris

While that works, the output looks like this:

Entering rescue mode...
error: out of disk

Quoted 1 line

_

Which does not present the information in the clearest possible way: it looks like the error happened in the rescue mode code, instead of the normal mode code.

Quoted 8 lines
Quoted 6 lines

Also, the error message could be lost if any of the code between the start of grub_enter_rescue_mode and its call to grub_print_error itself triggers an error.

For these reasons I think it's better to call grub_print_error from within grub_load_normal.

Agreed. See attached patch. Does this work as expected ?

Yes, it works fine.

Signature · 5 lines
Sam Morris
http://robots.org.uk/
 
PGP key id 1024D/5EA01078
3412 EA18 1277 354B 991B  C869 B219 7FDB 5EA0 1078
#5 lore raw
Quoted 4 lines · Sam Morris
Quoted 2 lines

Agreed. See attached patch. Does this work as expected ?

Yes, it works fine.

Ok, committed.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)