kern/err.c + disk/raid.c error handling fixes
PATCH 1/1 kern/err.c + disk/raid.c error handling fixes
As requested by Robert on IRC
here are now my 2 little recent patches merged into one
2008-08-12 Felix Zielcke <[email protected]>
* kern/err.c [GRUB_UTIL]: Include <stdio.h>.
[GRUB_UTIL] (grub_print_error): Use fprintf (stderr, ...) instead of grub_printf.
* disk/raid.c (GRUB_MOD_INIT): Use grub_print_error() to show RAID errors and reset grub_errno. Do not give errors to the upper layer.
err.c +7 -0
@@ -21,6 +21,9 @@#include <grub/misc.h> #include <stdarg.h> +#ifdef GRUB_UTIL +#include <stdio.h> +#endif #define GRUB_MAX_ERRMSG 256#define GRUB_ERROR_STACK_SIZE 10
@@ -121,7 +124,11 @@do { if (grub_errno != GRUB_ERR_NONE) +#ifdef GRUB_UTIL +fprintf (stderr,"error: %s\n" , grub_errmsg); +#else grub_printf ("error: %s\n" , grub_errmsg); +#endif }while (grub_error_pop ());
Am Dienstag, den 12.08.2008, 18:28 +0200 schrieb Felix Zielcke:
Ok naming the old patch kern_err.diff and the new one raid_err.diff isn't a good idea :(
2008-08-12 Felix Zielcke <[email protected]>
* kern/err.c [GRUB_UTIL]: Include <stdio.h>.
[GRUB_UTIL] (grub_print_error): Use fprintf (stderr, ...) instead of grub_printf.
* disk/raid.c (GRUB_MOD_INIT): Use grub_print_error() to show RAID errors and reset grub_errno. Do not give errors to the upper layer.
raid.c +2 -0
@@ -581,6 +581,8 @@ {grub_device_iterate (&grub_raid_scan_device);grub_disk_dev_register (&grub_raid_dev); +grub_print_error (); + grub_errno =GRUB_ERR_NONE ; }GRUB_MOD_FINI (raid)
err.c +7 -0
@@ -21,6 +21,9 @@#include <grub/misc.h> #include <stdarg.h> +#ifdef GRUB_UTIL +#include <stdio.h> +#endif #define GRUB_MAX_ERRMSG 256#define GRUB_ERROR_STACK_SIZE 10
@@ -121,7 +124,11 @@do { if (grub_errno != GRUB_ERR_NONE) +#ifdef GRUB_UTIL +fprintf (stderr,"error: %s\n" , grub_errmsg); +#else grub_printf ("error: %s\n" , grub_errmsg); +#endif }while (grub_error_pop ());
Quoted 9 lines · Felix Zielcke
Am Dienstag, den 12.08.2008, 18:28 +0200 schrieb Felix Zielcke:
Ok naming the old patch kern_err.diff and the new one raid_err.diff isn't a good idea :(
2008-08-12 Felix Zielcke <[email protected]>
*
kern/err.c[GRUB_UTIL]: Include <stdio.h>.
Please don't do this. Why do you want this?
Quoted 2 lines
[
GRUB_UTIL] (grub_print_error): Use fprintf (stderr, ...) instead ofgrub_printf.
Why?
It would be better to make a util/misc.c:grub_print_error instead of this
Quoted 2 lines
*
disk/raid.c(GRUB_MOD_INIT): Usegrub_print_error()to show RAID errors and resetgrub_errno. Do not give errors to the upper layer.
"...reset grub_errno. Do not..."
(double space)
raid.c line 581
Quoted 6 lines
Index:
disk/raid.c
===================================================================raid.c +0
-0@@ -581,6 +581,8 @@ {
Please use -up for diff, you can use:
$ svn diff --diff-cmd diff -x -up
Quoted 7 lines
raid.c +2
-0grub_device_iterate (&grub_raid_scan_device);grub_disk_dev_register (&grub_raid_dev); +grub_print_error (); + grub_errno =GRUB_ERR_NONE ; }GRUB_MOD_FINI (raid)
Quoted 6 lines · Marco Gerards
Quoted 2 lines
[
GRUB_UTIL] (grub_print_error): Use fprintf (stderr, ...) instead ofgrub_printf.Why?
It would be better to make a util/misc.c:grub_print_error instead of this
Problem is that kern/err.c is already included in grub-probe. So then we would have to add util/misc.c:grub_print_error _and_ disable grub_print_error.
Quoted 2 lines
Please use -up for diff, you can use:
$ svn diff --diff-cmd diff -x -up
Thanks for the tip, I've been looking for this ;-)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 3 lines · Marco Gerards
Quoted 1 line
*
kern/err.c[GRUB_UTIL]: Include <stdio.h>.Please don't do this. Why do you want this?
It's needed for fprintf, and fprintf is only useful for GRUB_UTIL.
Quoted 2 lines
Quoted 1 line
"...reset
grub_errno. Do not..."(double space)
Right, I should really pay more attention to these small little details.
Am Mittwoch, den 13.08.2008, 00:40 +0200 schrieb Robert Millan:
Quoted 5 lines
Quoted 2 lines
It would be better to make a util/misc.c:grub_print_error instead of this
Problem is that
kern/err.cis already included in grub-probe. So then we would have to add util/misc.c:grub_print_error _and_ disablegrub_print_error.
Thanks for your hint.
Quoted 5 lines
Quoted 2 lines
Please use -up for diff, you can use:
$ svn diff --diff-cmd diff -x -upThanks for the tip, I've been looking for this ;-)
I made now a svn-diff alias for this :)
I hope it's now better, but I was unsure about the `new function' in changelog it isn't really a new one more a modified one.
2008-08-13 Felix Zielcke <[email protected]>
* include/kern/err.h [! GRUB_UTIL]: Disable.
* kern/err.c [! GRUB_UTIL] (grub_print_error): Likewise.
* include/util/misc.h (grub_print_error): New function prototype.
* util/misc.c (grub_print_error): New function.
* disk/raid.c (GRUB_MOD_INIT): Use grub_print_error() to show RAID errors and reset grub_errno. Do not give errors to the upper layer.
err.c +2 -0
@@ -113,6 +113,7 @@ grub_error_pop (void) } } +#ifndef GRUB_UTIL void grub_print_error (void ) {
@@ -132,3 +133,4 @@ grub_print_error (void) grub_error_stack_assert = 0; } } +#endif
grub/err.h +3 -0
@@ -63,6 +63,9 @@ grub_err_t EXPORT_FUNC(grub_error) (grubvoid EXPORT_FUNC (grub_fatal ) (const char *fmt, ...) __attribute__ ((noreturn));void EXPORT_FUNC (grub_error_push ) (void );int EXPORT_FUNC (grub_error_pop ) (void ); + +#ifndef GRUB_UTIL void EXPORT_FUNC (grub_print_error ) (void ); +#endif #endif /* ! GRUB_ERR_HEADER */
grub/util/misc.h +1 -0
@@ -55,4 +55,5 @@ void grub_util_write_image_at (const voi FILE *out);char *grub_util_get_disk_name (int disk,char *name); +void grub_print_error (void );#endif /* ! GRUB_UTIL_MISC_HEADER */
misc.c +20 -0
@@ -300,3 +300,23 @@ grub_arch_sync_caches (void *address __a grub_size_t len __attribute__ ((unused))) { } + +void +grub_print_error (void ) +{ +/* Print error messages in reverse order. First print active error message +and then empty error stack. */ +do + { +if (grub_errno !=GRUB_ERR_NONE ) +fprintf (stderr ,"error: %s\n" , grub_errmsg); + } +while (grub_error_pop ()); + +/* If there was an assert while using error stack, report about it. */ +if (grub_error_stack_assert) + { +fprintf (stderr,"assert: error stack overflow detected!\n" ); + grub_error_stack_assert =0 ; + } +}
Quoted 6 lines · Felix Zielcke
Quoted 3 lines · Marco Gerards
Quoted 1 line
*
kern/err.c[GRUB_UTIL]: Include <stdio.h>.Please don't do this. Why do you want this?
It's needed for fprintf, and fprintf is only useful for
GRUB_UTIL.
I understood that. With this I meant "changing the kernel for GRUB_UTIL" :)
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
"...reset
grub_errno. Do not..."(double space)
Right, I should really pay more attention to these small little details.
:-)
Quoted 7 lines
Am Mittwoch, den 13.08.2008, 00:40 +0200 schrieb Robert Millan:
Quoted 5 lines
Quoted 2 lines
It would be better to make a util/misc.c:grub_print_error instead of this
Problem is that
kern/err.cis already included in grub-probe. So then we would have to add util/misc.c:grub_print_error _and_ disablegrub_print_error.
Quoted 8 lines
Thanks for your hint.
Quoted 5 lines
Quoted 2 lines
Please use -up for diff, you can use:
$ svn diff --diff-cmd diff -x -upThanks for the tip, I've been looking for this ;-)
I made now a svn-diff alias for this :)
Great :-)
Quoted 6 lines
I hope it's now better, but I was unsure about the `new function' in changelog it isn't really a new one more a modified one.
2008-08-13 Felix Zielcke <[email protected]>
*
include/kern/err.h[!GRUB_UTIL]: Disable.
Disable what?
BTW, this file does not exist.
Quoted 1 line
*
kern/err.c[!GRUB_UTIL] (grub_print_error): Likewise.
Why?
Quoted 1 line
*
include/util/misc.h(grub_print_error): New function prototype.
If you included <grub/err.h> here...
Quoted 28 lines
*
util/misc.c(grub_print_error): New function.*
disk/raid.c(GRUB_MOD_INIT): Usegrub_print_error()to show RAID errors and resetgrub_errno. Do not give errors to the upper layer.Index:
kern/err.c
===================================================================err.c +2
-0@@ -113,6 +113,7 @@ grub_error_pop (void) } } +#ifndef GRUB_UTIL void grub_print_error (void ) {@@ -132,3 +133,4 @@ grub_print_error (void) grub_error_stack_assert = 0; } } +#endif Index:
include/grub/err.h
===================================================================
grub/err.h grub_err_t EXPORT_FUNC(grub_error) (grub · line 69
Quoted 7 lines
grub/err.h +3
-0@@ -63,6 +63,9 @@ grub_err_t EXPORT_FUNC(grub_error) (grubvoid EXPORT_FUNC (grub_fatal ) (const char *fmt, ...) __attribute__ ((noreturn));void EXPORT_FUNC (grub_error_push ) (void );int EXPORT_FUNC (grub_error_pop ) (void ); + +#ifndef GRUB_UTIL void EXPORT_FUNC (grub_print_error ) (void ); +#endif
Why does this have to be conditional?
Quoted 39 lines
grub/err.h +0
-0#endif /* ! GRUB_ERR_HEADER */ Index:
include/grub/util/misc.h
===================================================================grub/util/misc.h +1
-0@@ -55,4 +55,5 @@ void grub_util_write_image_at (const voi FILE *out);char *grub_util_get_disk_name (int disk,char *name); +void grub_print_error (void );#endif /* ! GRUB_UTIL_MISC_HEADER */ Index:
util/misc.c
===================================================================misc.c +20
-0@@ -300,3 +300,23 @@ grub_arch_sync_caches (void *address __a grub_size_t len __attribute__ ((unused))) { } + +void +grub_print_error (void ) +{ +/* Print error messages in reverse order. First print active error message +and then empty error stack. */ +do + { +if (grub_errno !=GRUB_ERR_NONE ) +fprintf (stderr ,"error: %s\n" , grub_errmsg); + } +while (grub_error_pop ()); + +/* If there was an assert while using error stack, report about it. */ +if (grub_error_stack_assert) + { +fprintf (stderr,"assert: error stack overflow detected!\n" ); + grub_error_stack_assert =0 ; + } +}
Am Mittwoch, den 13.08.2008, 11:47 +0200 schrieb Marco Gerards:
Quoted 11 lines
Quoted 6 lines · Felix Zielcke
Quoted 3 lines · Marco Gerards
Quoted 1 line
*
kern/err.c[GRUB_UTIL]: Include <stdio.h>.Please don't do this. Why do you want this?
It's needed for fprintf, and fprintf is only useful for
GRUB_UTIL.I understood that. With this I meant "changing the kernel for
GRUB_UTIL" :)
I just did it first that way, because we need a simple and small patch for lenny (i.e. debian-release)
If I do it like you prefer duplicating it in util/misc.c then I need to remove the static from `int grub_error_stack_assert;' and having it prefixed with extern on grub/err.h
Yes this change is no problem, grub-probe now compiles fine But grub-mkimage not:
grub_mkimage-util_misc.o: In function `grub_print_error':/home/fz/grub/grub2.svn/util/misc.c:315: undefined reference to grub_error_pop' /home/fz/grub/grub2.svn/util/misc.c:312: undefined reference to grub_errno' /home/fz/grub/grub2.svn/util/misc.c:313: undefined reference to grub_errmsg' /home/fz/grub/grub2.svn/util/misc.c:313: undefined reference to grub_printf' /home/fz/grub/grub2.svn/util/misc.c:315: undefined reference to grub_error_pop' /home/fz/grub/grub2.svn/util/misc.c:320: undefined reference to grub_printf'
collect2: ld returned 1 exit status
make: *** [grub-mkimage] Error 1
So for me it seems kern/err.c has to be either doubled for the utils or, just like I did first, with just changing 2 grub_printf to fprintf for GRUB_UTIL
Am Mittwoch, den 13.08.2008, 22:31 +0200 schrieb Felix Zielcke:
Quoted 23 lines
Am Mittwoch, den 13.08.2008, 11:47 +0200 schrieb Marco Gerards:
Quoted 11 lines
Quoted 6 lines · Felix Zielcke
Quoted 3 lines · Marco Gerards
Quoted 1 line
*
kern/err.c[GRUB_UTIL]: Include <stdio.h>.Please don't do this. Why do you want this?
It's needed for fprintf, and fprintf is only useful for
GRUB_UTIL.I understood that. With this I meant "changing the kernel for
GRUB_UTIL" :)I just did it first that way, because we need a simple and small patch for lenny (i.e. debian-release)
If I do it like you prefer duplicating it in
util/misc.cthen I need to remove the static from `intgrub_error_stack_assert;' and having it prefixed with extern ongrub/err.hYes this change is no problem, grub-probe now compiles fine But grub-mkimage not:
Quoted 7 lines
grub_mkimage-util_misc.o: In function `grub_print_error':
/home/fz/grub/grub2.svn/util/misc.c:315: undefined reference togrub_error_pop' /home/fz/grub/grub2.svn/util/misc.c:312: undefined reference togrub_errno'/home/fz/grub/grub2.svn/util/misc.c:313: undefined reference togrub_errmsg' /home/fz/grub/grub2.svn/util/misc.c:313: undefined reference togrub_printf'/home/fz/grub/grub2.svn/util/misc.c:315: undefined reference togrub_error_pop' /home/fz/grub/grub2.svn/util/misc.c:320: undefined reference togrub_printf'
Sorry just copied the function from kern/err.c to util/misc.c without changing grub_printf () to fprintf () so just ignore these 2 lines please.
Quoted 13 lines
collect2: ld returned 1 exit status
make: *** [grub-mkimage] Error 1So for me it seems
kern/err.chas to be either doubled for the utils or, just like I did first, with just changing 2grub_printfto fprintf forGRUB_UTIL_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 11 lines · Felix Zielcke
Yes this change is no problem, grub-probe now compiles fine But grub-mkimage not:
grub_mkimage-util_misc.o: In function `grub_print_error':
/home/fz/grub/grub2.svn/util/misc.c:315: undefined reference togrub_error_pop' /home/fz/grub/grub2.svn/util/misc.c:312: undefined reference togrub_errno'/home/fz/grub/grub2.svn/util/misc.c:313: undefined reference togrub_errmsg' /home/fz/grub/grub2.svn/util/misc.c:315: undefined reference togrub_error_pop'
collect2: ld returned 1 exit status
make: *** [grub-mkimage] Error 1
This is because util/misc.c adds error handling to grub-mkimage, which wasn't there before.
If we can't do this in kern/err.c (although I really think it'd be simpler), adding a new util/err.c that can be used by grub-probe but not grub-mkimage would solve this.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Am Mittwoch, den 13.08.2008, 23:50 +0200 schrieb Robert Millan:
Quoted 3 lines
If we can't do this in
kern/err.c(although I really think it'd be simpler), adding a newutil/err.cthat can be used by grub-probe but not grub-mkimage would solve this.
Seems like I'm sometime really just too fast.
I should start to think more before I bother to change something :)
This time dear Marco I didn't bother to read through the changelog, it might be still not perfect and I'm even tired now.
But at least everything compiles now with that patch and yes I did ran ./autogen.sh before ;)
2008-08-14 Felix Zielcke <[email protected]>
* include/grub/err.h (grub_error_stack_assert): New variable declaration.
* kern/err.c (grub_error_stack_assert): Remove static. (grub_print_error) [! GRUB_UTIL]: Disable it because ...
* util/err.c: New file with grub_print_error () using fprintf (stderr, ...).
* conf/common.rmk: Add it for grub-probe.
common.rmk +1 -1
@@ -4,7 +4,7 @@ sbin_UTILITIES += grub-probe util/grub-probe.c_DEPENDENCIES = grub_probe_init.h grub_probe_SOURCES = util/grub-probe.c \ - util/biosdisk.c util/misc.c util/getroot.c \ + util/biosdisk.c util/misc.c util/getroot.c util/err.c \ kern/device.c kern/disk.c kern/err.c kern/misc.c \ kern/parser.c kern/partition.c kern/file.c \ \
err.c +3 -2
@@ -34,7 +34,7 @@ static struct } grub_error_stack_items[GRUB_ERROR_STACK_SIZE ];static int grub_error_stack_pos; -static int grub_error_stack_assert; +int grub_error_stack_assert;grub_err_t grub_error (grub_err_t n,const char *fmt, ...)
@@ -112,7 +112,7 @@ grub_error_pop (void)return 0 ; } } - +#ifndef GRUB_UTIL void grub_print_error (void ) {
@@ -132,3 +132,4 @@ grub_print_error (void) grub_error_stack_assert = 0; } } +#endif
grub/err.h +1 -0
@@ -58,6 +58,7 @@ grub_err_t;extern grub_err_t EXPORT_VAR (grub_errno );extern char EXPORT_VAR (grub_errmsg )[]; +extern int grub_error_stack_assert;grub_err_t EXPORT_FUNC (grub_error ) (grub_err_t n,const char *fmt, ...);void EXPORT_FUNC (grub_fatal ) (const char *fmt, ...) __attribute__ ((noreturn));
common.rmk +1 -1
@@ -4,7 +4,7 @@ sbin_UTILITIES += grub-probe util/grub-probe.c_DEPENDENCIES = grub_probe_init.h grub_probe_SOURCES = util/grub-probe.c \ - util/biosdisk.c util/misc.c util/getroot.c \ + util/biosdisk.c util/misc.c util/getroot.c util/err.c \ kern/device.c kern/disk.c kern/err.c kern/misc.c \ kern/parser.c kern/partition.c kern/file.c \ \
err.c +3 -2
@@ -34,7 +34,7 @@ static struct } grub_error_stack_items[GRUB_ERROR_STACK_SIZE ];static int grub_error_stack_pos; -static int grub_error_stack_assert; +int grub_error_stack_assert;grub_err_t grub_error (grub_err_t n,const char *fmt, ...)
@@ -112,7 +112,7 @@ grub_error_pop (void)return 0 ; } } - +#ifndef GRUB_UTIL void grub_print_error (void ) {
@@ -132,3 +132,4 @@ grub_print_error (void) grub_error_stack_assert = 0; } } +#endif
grub/err.h +1 -0
@@ -58,6 +58,7 @@ grub_err_t;extern grub_err_t EXPORT_VAR (grub_errno );extern char EXPORT_VAR (grub_errmsg )[]; +extern int grub_error_stack_assert;grub_err_t EXPORT_FUNC (grub_error ) (grub_err_t n,const char *fmt, ...);void EXPORT_FUNC (grub_fatal ) (const char *fmt, ...) __attribute__ ((noreturn));
err.c +41 -0
41 lines not on this page · raw message
Am Donnerstag, den 14.08.2008, 00:39 +0200 schrieb Felix Zielcke:
Quoted 3 lines
This time dear Marco I didn't bother to read through the changelog, it might be still not perfect and I'm even tired now.
I should have better gone to bed instead of making quickly a patch for this.
Well 2nd try now.
I forgot grub-fstest and I think I know now why you said `why' to one entry ;)
And I forgot to change the copyright year to 2008 for the new shiny util/err.c
2008-08-14 Felix Zielcke <[email protected]>
* include/grub/err.h (grub_error_stack_assert): New variable declaration.
* kern/err.c (grub_error_stack_assert): Remove static. (grub_print_error): Disable it for [GRUB_UTIL] because ...
* util/err.c: New file with grub_print_error () using fprintf (stderr, ...).
* conf/common.rmk: Add it for grub-probe.
common.rmk +2 -2
@@ -4,7 +4,7 @@ sbin_UTILITIES += grub-probe util/grub-probe.c_DEPENDENCIES = grub_probe_init.h grub_probe_SOURCES = util/grub-probe.c \ - util/biosdisk.c util/misc.c util/getroot.c \ + util/biosdisk.c util/misc.c util/getroot.c util/err.c \ kern/device.c kern/disk.c kern/err.c kern/misc.c \ kern/parser.c kern/partition.c kern/file.c \ \
@@ -23,7 +23,7 @@ endif # For grub-fstest. util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h -grub_fstest_SOURCES = util/grub-fstest.c util/hostfs.c util/misc.c \ +grub_fstest_SOURCES = util/grub-fstest.c util/hostfs.c util/misc.c util/err.c \ kern/file.c kern/device.c kern/disk.c kern/err.c kern/misc.c \ disk/host.c disk/loopback.c normal/arg.c normal/misc.c \ io/gzio.c lib/hexdump.c commands/blocklist.c commands/ls.c \
err.c +3 -2
@@ -34,7 +34,7 @@ static struct } grub_error_stack_items[GRUB_ERROR_STACK_SIZE ];static int grub_error_stack_pos; -static int grub_error_stack_assert; +int grub_error_stack_assert;grub_err_t grub_error (grub_err_t n,const char *fmt, ...)
@@ -112,7 +112,7 @@ grub_error_pop (void)return 0 ; } } - +#ifndef GRUB_UTIL void grub_print_error (void ) {
@@ -132,3 +132,4 @@ grub_print_error (void) grub_error_stack_assert = 0; } } +#endif
grub/err.h +1 -0
@@ -58,6 +58,7 @@ grub_err_t;extern grub_err_t EXPORT_VAR (grub_errno );extern char EXPORT_VAR (grub_errmsg )[]; +extern int grub_error_stack_assert;grub_err_t EXPORT_FUNC (grub_error ) (grub_err_t n,const char *fmt, ...);void EXPORT_FUNC (grub_fatal ) (const char *fmt, ...) __attribute__ ((noreturn));
err.c +41 -0
41 lines not on this page · raw message
Quoted 5 lines · Felix Zielcke
Am Donnerstag, den 14.08.2008, 00:39 +0200 schrieb Felix Zielcke:
Quoted 3 lines
This time dear Marco I didn't bother to read through the changelog, it might be still not perfect and I'm even tired now.
Quoted 7 lines
I should have better gone to bed instead of making quickly a patch for this.
Well 2nd try now.
I forgot grub-fstest and I think I know now why you said `why' to one entry ;)
And I forgot to change the copyright year to 2008 for the new shinyutil/err.c
So this patch isn't really required, but you want it for Lenny?
Quoted 8 lines
2008-08-14 Felix Zielcke <[email protected]>
*
include/grub/err.h(grub_error_stack_assert): New variable declaration.
*kern/err.c(grub_error_stack_assert): Remove static. (grub_print_error): Disable it for [GRUB_UTIL] because ...
*util/err.c: New file withgrub_print_error() using fprintf (stderr, ...).
Can you just use misc.c?
Quoted 1 line
* conf/common.rmk: Add it for grub-probe.
I have been thinking of an alternative way to fix this. A bit of a compromise between what you want and what I want and perhaps cleaner.
You could define a function grub_err_printf or something like that. Which you use in grub_print_error. You can redefine it for GRUB_UTIL to grub_util_error and to grub_print otherwise.
I didn't study the code. Will this be easier and cleaner?
--
Marco
Am Donnerstag, den 14.08.2008, 09:13 +0200 schrieb Marco Gerards:
Quoted 1 line
So this patch isn't really required, but you want it for Lenny?
[email protected]
That's the one Robert and me thought could be something for lenny.
I have forgotten to merge the disk/raid.c changes which Robert wanted to have in the last grub_print_error () patches.
As I already told you on IRC, I now start to believe like Robert that the idea isn't that bad to have a function for the utils which prints to stderr but it doestn't `exit ()' liek grub_util_error does.
Maybe not only raid.mod has a use for this but others too.
Quoted 10 lines
Quoted 8 lines
2008-08-14 Felix Zielcke <[email protected]>
*
include/grub/err.h(grub_error_stack_assert): New variable declaration.
*kern/err.c(grub_error_stack_assert): Remove static. (grub_print_error): Disable it for [GRUB_UTIL] because ...
*util/err.c: New file withgrub_print_error() using fprintf (stderr, ...).Can you just use
misc.c?
As already said on IRC
[email protected]
grub-mkimage would then need to have kern/err.c included.
Quoted 6 lines
Quoted 2 lines
* conf/common.rmk: Add it for grub-probe.
I have been thinking of an alternative way to fix this. A bit of a compromise between what you want and what I want and perhaps cleaner.
This whole problem, confuses me now myself.
Bean is rewriting the whole RAID code anyway and Robert and me would like to have a simple and small patch for lenny.
For upstream (i.e. you ;)) I want a clean solution, that's why I did now the RFC topic.
Maybe it's just better if I don't think now for lenny.
Quoted 5 lines
You could define a function
grub_err_printfor something like that. Which you use ingrub_print_error. You can redefine it forGRUB_UTILtogrub_util_errorand togrub_printotherwise.I didn't study the code. Will this be easier and cleaner?
Thanks to Robert for the hint with the copyright years.
As always with me, changelog and code is probable still not perfect ;) but I think the genereal idea behind it is a step to come nearer to a clean good solution for this whole problem ([email protected])
It does compile cleanly i.e. doestn't introduce any warnings at all and it works with the 2 raid/disk.c changes from msgid I said at the beginning of this mail.
2008-08-14 Felix Zielcke <[email protected]>
* include/grub.err.h (grub_err_printf): New function prototype.
* util/misc.c (grub_err_printf): New function.
* kern/misc.c [! GRUB_UTIL] (grub_err_printf): New alias for grub_printf.
* kern/err.c (grub_print_error): Use grub_err_printf.
err.c +3 -3
@@ -1,7 +1,7 @@/* err.c - error handling routines */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2005,2007 Free Software Foundation, Inc. +* Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -121,14 +121,14 @@ grub_print_error (void)do {if (grub_errno !=GRUB_ERR_NONE ) -grub_printf ("error: %s\n" , grub_errmsg); +grub_err_printf ("error: %s\n" , grub_errmsg); }while (grub_error_pop ());/* If there was an assert while using error stack, report about it. */ if (grub_error_stack_assert) { -grub_printf ("assert: error stack overflow detected!\n" ); +grub_err_printf ("assert: error stack overflow detected!\n" ); grub_error_stack_assert =0 ; } }
misc.c +4 -0
@@ -133,6 +133,10 @@ grub_printf (const char *fmt, ...)return ret; } +#ifndef GRUB_UTIL +int grub_err_printf (const char *fmt, ...) +__attribute__ ((alias ("grub_printf" ))); +#endif void grub_real_dprintf (const char *file, const int line, const char *condition,
grub/err.h +2 -1
@@ -1,7 +1,7 @@/* err.h - error numbers and prototypes */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2005,2007 Free Software Foundation, Inc. +* Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -64,5 +64,6 @@ void EXPORT_FUNC(grub_fatal) (const charvoid EXPORT_FUNC (grub_error_push ) (void );int EXPORT_FUNC (grub_error_pop ) (void );void EXPORT_FUNC (grub_print_error ) (void ); +int EXPORT_FUNC (grub_err_printf ) (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 )));#endif /* ! GRUB_ERR_HEADER */
misc.c +13 -1
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2003,2005,2006,2007 Free Software Foundation, Inc. +* Copyright (C) 2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -74,6 +74,18 @@ grub_util_error (const char *fmt, ...)exit (1 ); } +int +grub_err_printf (const char *fmt, ...) +{ +va_list ap; +int ret; + +va_start (ap, fmt); + ret =vfprintf (stderr, fmt, ap); +va_end (ap); + +return ret; +}void *xmalloc (size_t size) {
Quoted 4 lines · Felix Zielcke
misc.c +4
-0+int +grub_err_printf (const char *fmt, ...) +{ +va_list ap;
misc.c grub_util_error (const char *fmt, ...) · line 90
Quoted 10 lines
misc.c +8
-0+int ret; + +va_start (ap, fmt); + ret =vfprintf (stderr, fmt, ap); +va_end (ap); + +return ret; +}void *xmalloc (size_t size)
Please separate functions with an empty line. Anyway, no need to send a new patch just for this.
Marco, is it fine to you now?
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 19 lines · Robert Millan
Quoted 4 lines · Felix Zielcke
misc.c +4
-0+int +grub_err_printf (const char *fmt, ...) +{ +va_list ap;misc.c grub_util_error (const char *fmt, ...) · line 90
Quoted 10 lines
misc.c +8
-0+int ret; + +va_start (ap, fmt); + ret =vfprintf (stderr, fmt, ap); +va_end (ap); + +return ret; +}void *xmalloc (size_t size)Please separate functions with an empty line. Anyway, no need to send a new patch just for this.
Quoted 2 lines
Marco, is it fine to you now?
Please use grub's own string formatter.
Hi Felix,
Felix Zielcke <[email protected]> writes:
[...]
Quoted 3 lines
2008-08-14 Felix Zielcke <[email protected]>
*
include/grub.err.h(grub_err_printf): New function prototype.
grub.err.h -> grub/err.h
Quoted 4 lines
*
util/misc.c(grub_err_printf): New function.
*kern/misc.c[!GRUB_UTIL] (grub_err_printf): New alias forgrub_printf.
*kern/err.c(grub_print_error): Usegrub_err_printf.
Looks fine to me.
This patch looks clean enough for me :-). If you can correct the following (and previous ;)) comments, it is ready to be committed.
Quoted 59 lines
Index:
kern/err.c
===================================================================err.c +3
-3@@ -1,7 +1,7 @@/* err.c - error handling routines */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2005,2007 Free Software Foundation, Inc. +* Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -121,14 +121,14 @@ grub_print_error (void)do {if (grub_errno !=GRUB_ERR_NONE ) -grub_printf ("error: %s\n" , grub_errmsg); +grub_err_printf ("error: %s\n" , grub_errmsg); }while (grub_error_pop ());/* If there was an assert while using error stack, report about it. */ if (grub_error_stack_assert) { -grub_printf ("assert: error stack overflow detected!\n" ); +grub_err_printf ("assert: error stack overflow detected!\n" ); grub_error_stack_assert =0 ; } }Index:
kern/misc.c
===================================================================misc.c +4
-0@@ -133,6 +133,10 @@ grub_printf (const char *fmt, ...)return ret; } +#ifndef GRUB_UTIL +int grub_err_printf (const char *fmt, ...) +__attribute__ ((alias ("grub_printf" ))); +#endif void grub_real_dprintf (const char *file, const int line, const char *condition,Index:
include/grub/err.h
===================================================================grub/err.h +1
-1@@ -1,7 +1,7 @@/* err.h - error numbers and prototypes */ /* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2005,2007 Free Software Foundation, Inc. +* Copyright (C) 2002,2005,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
grub/err.h void EXPORT_FUNC(grub_fatal) (const char · line 67
Quoted 4 lines
grub/err.h +1
-0@@ -64,5 +64,6 @@ void EXPORT_FUNC(grub_fatal) (const charvoid EXPORT_FUNC (grub_error_push ) (void );int EXPORT_FUNC (grub_error_pop ) (void );void EXPORT_FUNC (grub_print_error ) (void ); +int EXPORT_FUNC (grub_err_printf ) (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 )));
Can you break the line somehow? It is too long.
Quoted 21 lines
grub/err.h +0
-0#endif /* ! GRUB_ERR_HEADER */ Index:
util/misc.c
===================================================================misc.c +5
-1@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2002,2003,2005,2006,2007 Free Software Foundation, Inc. +* Copyright (C) 2002,2003,2005,2006,2007,2008 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,6 +74,18 @@ grub_util_error (const char *fmt, ...)exit (1 ); } +int +grub_err_printf (const char *fmt, ...) +{ +va_list ap;
misc.c grub_util_error (const char *fmt, ...) · line 90
Quoted 10 lines
misc.c +8
-0+int ret; + +va_start (ap, fmt); + ret =vfprintf (stderr, fmt, ap); +va_end (ap); + +return ret; +}void *xmalloc (size_t size)
Missing newline between the functions above.
--
Marco
Am Donnerstag, den 14.08.2008, 20:27 +0200 schrieb Marco Gerards:
Quoted 3 lines
This patch looks clean enough for me :-). If you can correct the following (and previous ;)) comments, it is ready to be committed.
Commited.
Hurray.
err.c line 4
Quoted 7 lines · Felix Zielcke
err.c +4
-0@@ -0,0 +1,41 @@ +/* err.c - util error printing routine */ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2002,2005,2007 Free Software Foundation, Inc.
Remember to update copyright headers (in modified files as well)
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 10 lines · Robert Millan
Quoted 6 lines · Marco Gerards
Quoted 2 lines
[
GRUB_UTIL] (grub_print_error): Use fprintf (stderr, ...) instead ofgrub_printf.Why?
It would be better to make a util/misc.c:grub_print_error instead of this
Problem is that
kern/err.cis already included in grub-probe. So then we would have to add util/misc.c:grub_print_error _and_ disablegrub_print_error.
That might be better than adding fprintf to kern/ IMO.
Quoted 4 lines
Quoted 2 lines
Please use -up for diff, you can use:
$ svn diff --diff-cmd diff -x -upThanks for the tip, I've been looking for this ;-)
Now if only everyone would use this... :-)
--
Marco