diff --git a/ChangeLog b/ChangeLog index 09777c513..6b6815483 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2012-02-05 Vladimir Serbinenko + + * 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 * grub-core/lib/i386/relocator16.S (grub_relocator16_start): Move switch diff --git a/grub-core/kern/err.c b/grub-core/kern/err.c index 74f3915aa..52ba6de62 100644 --- a/grub-core/kern/err.c +++ b/grub-core/kern/err.c @@ -22,18 +22,13 @@ #include #include -#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)); diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c index 9704a345b..e374f6e9c 100644 --- a/grub-core/net/tftp.c +++ b/grub-core/net/tftp.c @@ -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; diff --git a/include/grub/err.h b/include/grub/err.h index 3a75f5698..cf96cd563 100644 --- a/include/grub/err.h +++ b/include/grub/err.h @@ -22,6 +22,8 @@ #include +#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)); diff --git a/include/grub/misc.h b/include/grub/misc.h index 47607d3e3..3a62d447d 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -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 */