]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/kern/err.c (GRUB_MAX_ERRMSG): Move to ...
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 5 Feb 2012 09:24:53 +0000 (10:24 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sun, 5 Feb 2012 09:24:53 +0000 (10:24 +0100)
* include/grub/err.h (GRUB_MAX_ERRMSG): ... here.
* include/grub/err.h (grub_error_saved): New struct.
(grub_errmsg): Make array size explicit.
* include/grub/misc.h (grub_error_save): New function.
(grub_error_load): Likewise.
* grub-core/kern/err.c (grub_error_stack_items): Use grub_error_saved.
(grub_error_push): Update `errno' member name.
(grub_error_pop): Likewise
* grub-core/net/tftp.c (tftp_data): New member save_err.
(tftp_receive): Save error.
(tftp_open): Restore error.

ChangeLog
grub-core/kern/err.c
grub-core/net/tftp.c
include/grub/err.h
include/grub/misc.h

index 09777c513573803dddf08c588111a21a2abfcead..6b6815483135e2fce04ebb45a1c0302ec5c27d8e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2012-02-05  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/kern/err.c (GRUB_MAX_ERRMSG): Move to ...
+       * include/grub/err.h (GRUB_MAX_ERRMSG): ... here.
+       * include/grub/err.h (grub_error_saved): New struct.
+       (grub_errmsg): Make array size explicit.
+       * include/grub/misc.h (grub_error_save): New function.
+       (grub_error_load): Likewise.
+       * grub-core/kern/err.c (grub_error_stack_items): Use grub_error_saved.
+       (grub_error_push): Update `errno' member name.
+       (grub_error_pop): Likewise
+       * grub-core/net/tftp.c (tftp_data): New member save_err.
+       (tftp_receive): Save error.
+       (tftp_open): Restore error.
+
 2012-02-05  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/lib/i386/relocator16.S (grub_relocator16_start): Move switch
index 74f3915aa77e7b90c751cacfe8943b300a794cdb..52ba6de62fae25dd7da595ed64b8f77b95dfb66f 100644 (file)
 #include <stdarg.h>
 #include <grub/i18n.h>
 
-#define GRUB_MAX_ERRMSG                256
 #define GRUB_ERROR_STACK_SIZE  10
 
 grub_err_t grub_errno;
 char grub_errmsg[GRUB_MAX_ERRMSG];
 int grub_err_printed_errors;
 
-static struct
-{
-  grub_err_t errno;
-  char errmsg[GRUB_MAX_ERRMSG];
-} grub_error_stack_items[GRUB_ERROR_STACK_SIZE];
+static struct grub_error_saved grub_error_stack_items[GRUB_ERROR_STACK_SIZE];
 
 static int grub_error_stack_pos;
 static int grub_error_stack_assert;
@@ -71,7 +66,7 @@ grub_error_push (void)
   if (grub_error_stack_pos < GRUB_ERROR_STACK_SIZE)
     {
       /* Copy active error message to stack.  */
-      grub_error_stack_items[grub_error_stack_pos].errno = grub_errno;
+      grub_error_stack_items[grub_error_stack_pos].grub_errno = grub_errno;
       grub_memcpy (grub_error_stack_items[grub_error_stack_pos].errmsg,
                    grub_errmsg,
                    sizeof (grub_errmsg));
@@ -99,7 +94,7 @@ grub_error_pop (void)
       /* Pop error message from error stack to current active error.  */
       grub_error_stack_pos--;
 
-      grub_errno = grub_error_stack_items[grub_error_stack_pos].errno;
+      grub_errno = grub_error_stack_items[grub_error_stack_pos].grub_errno;
       grub_memcpy (grub_errmsg,
                    grub_error_stack_items[grub_error_stack_pos].errmsg,
                    sizeof (grub_errmsg));
index 9704a345ba7fd20dfa2ff1c8a44555171d21bc8f..e374f6e9c66e6a8c046565b7a515f261e598d72e 100644 (file)
@@ -102,6 +102,7 @@ typedef struct tftp_data
   grub_uint64_t block;
   grub_uint32_t block_size;
   int have_oack;
+  struct grub_error_saved save_err;
   grub_net_udp_socket_t sock;
   grub_priority_queue_t pq;
 } *tftp_data_t;
@@ -181,6 +182,7 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
       data->block = 0;
       grub_netbuff_free (nb);
       err = ack (data->sock, 0);
+      grub_error_save (&data->save_err);
       if (err)
        return err;
       return GRUB_ERR_NONE;
@@ -246,8 +248,11 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
       }
       return GRUB_ERR_NONE;
     case TFTP_ERROR:
+      data->have_oack = 1;
       grub_netbuff_free (nb);
-      return grub_error (GRUB_ERR_IO, (char *) tftph->u.err.errmsg);
+      grub_error (GRUB_ERR_IO, (char *) tftph->u.err.errmsg);
+      grub_error_save (&data->save_err);
+      return GRUB_ERR_NONE;
     default:
       grub_netbuff_free (nb);
       return GRUB_ERR_NONE;
@@ -368,11 +373,16 @@ tftp_open (struct grub_file *file, const char *filename)
     }
 
   if (!data->have_oack)
+    grub_error (GRUB_ERR_TIMEOUT, "Time out opening tftp.");
+  else
+    grub_error_load (&data->save_err);
+  if (grub_errno)
     {
       grub_net_udp_close (data->sock);
       destroy_pq (data);
-      return grub_error (GRUB_ERR_TIMEOUT, "Time out opening tftp.");
+      return grub_errno;
     }
+
   file->size = data->file_size;
 
   return GRUB_ERR_NONE;
index 3a75f5698c04c92454edf8350502ee3d87f239e3..cf96cd563f831edaf396187450f353217b6b9eb5 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <grub/symbol.h>
 
+#define GRUB_MAX_ERRMSG                256
+
 typedef enum
   {
     GRUB_ERR_NONE = 0,
@@ -70,8 +72,14 @@ typedef enum
   }
 grub_err_t;
 
+struct grub_error_saved
+{
+  grub_err_t grub_errno;
+  char errmsg[GRUB_MAX_ERRMSG];
+};
+
 extern grub_err_t EXPORT_VAR(grub_errno);
-extern char EXPORT_VAR(grub_errmsg)[];
+extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG];
 
 grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...);
 void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn));
index 47607d3e3ae5002d92e42448704b1f47e39d1e85..3a62d447d5c9e8286337e05d370dc47096f85b6c 100644 (file)
@@ -424,4 +424,19 @@ extern int EXPORT_VAR(grub_no_autoload);
 #define grub_no_autoload 0
 #endif
 
+static inline void
+grub_error_save (struct grub_error_saved *save)
+{
+  grub_memcpy (save->errmsg, grub_errmsg, sizeof (save->errmsg));
+  save->grub_errno = grub_errno;
+  save->grub_errno = GRUB_ERR_NONE;
+}
+
+static inline void
+grub_error_load (const struct grub_error_saved *save)
+{
+  grub_memcpy (grub_errmsg, save->errmsg, sizeof (grub_errmsg));
+  grub_errno = save->grub_errno;
+}
+
 #endif /* ! GRUB_MISC_HEADER */