kern: Make it possible to subtract conditions from debug=
PATCH 9/10 kern: Make it possible to subtract conditions from debug=
From: Peter Jones <[email protected]>
This makes it so you can do set debug to "all,-scripting,-lexer" and get the obvious outcome. Any negation present will take preference over that conditional, so "all,-scripting,scripting" is the same thing as "all,-scripting".
---
grub-core/kern/misc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
grub-core/kern/misc.c +13 -1
@@ -162,12 +162,24 @@ int grub_debug_enabled (const char * condition) {const char *debug; +char *negcond; +int negated =0 ; debug =grub_env_get ("debug" );if (!debug)return 0 ; -if (grub_strword (debug,"all" ) ||grub_strword (debug, condition)) + negcond =grub_zalloc (grub_strlen (condition) +2 ); +if (negcond) + { +grub_strcpy (negcond,"-" ); +grub_strcpy (negcond+1 , condition); + negated =grub_strword (debug, negcond); +grub_free (negcond); + } + +if (!negated && + (grub_strword (debug,"all" ) ||grub_strword (debug, condition)))return 1 ;return 0 ;
Signature · 1 line
2.24.1
Quoted 22 lines · Javier Martinez Canillas
From: Peter Jones <[email protected]>
This makes it so you can do set debug to "all,-scripting,-lexer" and get the obvious outcome. Any negation present will take preference over that conditional, so "all,-scripting,scripting" is the same thing as "all,-scripting".
Signed-off-by Peter Jones <[email protected]>Signed-off-by Javier Martinez Canillas <[email protected]>---
grub-core/kern/misc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)grub-core/kern/misc.c +0
-0@@ -162,12 +162,24 @@ int grub_debug_enabled (const char * condition) {
grub-core/kern/misc.c int · line 172
Quoted 10 lines
grub-core/kern/misc.c +3
-1const char *debug; +char *negcond; +int negated =0 ; debug =grub_env_get ("debug" );if (!debug)return 0 ; -if (grub_strword (debug,"all" ) ||grub_strword (debug, condition)) + negcond =grub_zalloc (grub_strlen (condition) +2 );
I would use grub_malloc() here and zero last char... And in general I would try to avoid grub_malloc()/grub_free(). Static buffer? This is part of debug function and calling into memory allocator can have bad impact on debugging capabilities. So, it has to be simple as much as possible.
grub-core/kern/misc.c int · line 175
Quoted 3 lines
grub-core/kern/misc.c +3
-0+if (negcond) + { +grub_strcpy (negcond,"-" );
*negcond = '-';
The function can be called thousand times. So, this change can matter here.
grub-core/kern/misc.c int · line 176
Quoted 1 line
grub-core/kern/misc.c +1
-0+grub_strcpy (negcond+1 , condition);
negcond + 1
Or we can avoid copying at all by using grub_strword((debug, condition) and checking backwards for "-". Or maybe /,[ \t]*-/ (perlre)...
grub-core/kern/misc.c int · line 185
Quoted 9 lines
grub-core/kern/misc.c +6
-0+ negated =grub_strword (debug, negcond); +grub_free (negcond); + } + +if (!negated && + (grub_strword (debug,"all" ) ||grub_strword (debug, condition)))return 1 ;return 0 ;
Daniel