dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0245-Make-blscfg-debug-messages-more-useful.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Peter Jones <pjones@redhat.com>
d9d99f
Date: Fri, 19 Oct 2018 10:03:28 -0400
d9d99f
Subject: [PATCH] Make blscfg debug messages more useful
d9d99f
d9d99f
Related: rhbz#1640979
d9d99f
Signed-off-by: Peter Jones <pjones@redhat.com>
d9d99f
---
d9d99f
 grub-core/commands/blscfg.c    | 12 +++++-------
d9d99f
 grub-core/commands/legacycfg.c |  4 ++--
d9d99f
 grub-core/commands/menuentry.c | 18 ++++++++++++++----
d9d99f
 include/grub/normal.h          |  2 +-
d9d99f
 4 files changed, 22 insertions(+), 14 deletions(-)
d9d99f
d9d99f
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
d9d99f
index 347128c9ddd..42892cbfd55 100644
d9d99f
--- a/grub-core/commands/blscfg.c
d9d99f
+++ b/grub-core/commands/blscfg.c
d9d99f
@@ -46,8 +46,6 @@ GRUB_MOD_LICENSE ("GPLv3+");
d9d99f
 #define GRUB_BOOT_DEVICE "($root)"
d9d99f
 #endif
d9d99f
 
d9d99f
-#define grub_free(x) ({grub_dprintf("blscfg", "%s freeing %p\n", __func__, x); grub_free(x); })
d9d99f
-
d9d99f
 struct keyval
d9d99f
 {
d9d99f
   const char *key;
d9d99f
@@ -134,7 +132,7 @@ static int bls_add_keyval(struct bls_entry *entry, char *key, char *val)
d9d99f
   kv->val = v;
d9d99f
 
d9d99f
   entry->keyvals[entry->nkeyvals] = kv;
d9d99f
-  grub_dprintf("blscfg", "new keyval at %p:%p:%p\n", entry->keyvals[entry->nkeyvals], k, v);
d9d99f
+  grub_dprintf("blscfg", "new keyval at %p:%s:%s\n", entry->keyvals[entry->nkeyvals], k, v);
d9d99f
   entry->nkeyvals = new_n;
d9d99f
 
d9d99f
   return 0;
d9d99f
@@ -144,7 +142,6 @@ static void bls_free_entry(struct bls_entry *entry)
d9d99f
 {
d9d99f
   int i;
d9d99f
 
d9d99f
-  grub_dprintf("blscfg", "%s got here\n", __func__);
d9d99f
   for (i = 0; i < entry->nkeyvals; i++)
d9d99f
     {
d9d99f
       struct keyval *kv = entry->keyvals[i];
d9d99f
@@ -206,7 +203,7 @@ static int vercmp(const char * a, const char * b)
d9d99f
     int isnum;
d9d99f
     int ret = 0;
d9d99f
 
d9d99f
-    grub_dprintf("blscfg", "%s got here\n", __func__);
d9d99f
+    grub_dprintf("blscfg", "%s comparing %s and %s\n", __func__, a, b);
d9d99f
     if (!grub_strcmp(a, b))
d9d99f
 	    return 0;
d9d99f
 
d9d99f
@@ -682,7 +679,7 @@ static void create_entry (struct bls_entry *entry)
d9d99f
   char **args = NULL;
d9d99f
 
d9d99f
   char *src = NULL;
d9d99f
-  int i;
d9d99f
+  int i, index;
d9d99f
 
d9d99f
   grub_dprintf("blscfg", "%s got here\n", __func__);
d9d99f
   clinux = bls_get_val (entry, "linux", NULL);
d9d99f
@@ -756,7 +753,8 @@ static void create_entry (struct bls_entry *entry)
d9d99f
 			GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "",
d9d99f
 			initrd ? initrd : "");
d9d99f
 
d9d99f
-  grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0);
d9d99f
+  grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0, &index);
d9d99f
+  grub_dprintf ("blscfg", "Added entry %d id:\"%s\"\n", index, id);
d9d99f
 
d9d99f
 finish:
d9d99f
   grub_free (initrd);
d9d99f
diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c
d9d99f
index b32f3c74cb1..f9d7627bdc3 100644
d9d99f
--- a/grub-core/commands/legacycfg.c
d9d99f
+++ b/grub-core/commands/legacycfg.c
d9d99f
@@ -133,7 +133,7 @@ legacy_file (const char *filename)
d9d99f
 	    args[0] = oldname;
d9d99f
 	    grub_normal_add_menu_entry (1, args, NULL, NULL, "legacy",
d9d99f
 					NULL, NULL,
d9d99f
-					entrysrc, 0);
d9d99f
+					entrysrc, 0, NULL);
d9d99f
 	    grub_free (args);
d9d99f
 	    entrysrc[0] = 0;
d9d99f
 	    grub_free (oldname);
d9d99f
@@ -186,7 +186,7 @@ legacy_file (const char *filename)
d9d99f
 	}
d9d99f
       args[0] = entryname;
d9d99f
       grub_normal_add_menu_entry (1, args, NULL, NULL, NULL,
d9d99f
-				  NULL, NULL, entrysrc, 0);
d9d99f
+				  NULL, NULL, entrysrc, 0, NULL);
d9d99f
       grub_free (args);
d9d99f
     }
d9d99f
 
d9d99f
diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c
d9d99f
index 2c5363da7f5..8d242b0187e 100644
d9d99f
--- a/grub-core/commands/menuentry.c
d9d99f
+++ b/grub-core/commands/menuentry.c
d9d99f
@@ -78,7 +78,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
d9d99f
 			    char **classes, const char *id,
d9d99f
 			    const char *users, const char *hotkey,
d9d99f
 			    const char *prefix, const char *sourcecode,
d9d99f
-			    int submenu)
d9d99f
+			    int submenu, int *index)
d9d99f
 {
d9d99f
   int menu_hotkey = 0;
d9d99f
   char **menu_args = NULL;
d9d99f
@@ -149,9 +149,12 @@ grub_normal_add_menu_entry (int argc, const char **args,
d9d99f
   if (! menu_title)
d9d99f
     goto fail;
d9d99f
 
d9d99f
+  grub_dprintf ("menu", "id:\"%s\"\n", id);
d9d99f
+  grub_dprintf ("menu", "title:\"%s\"\n", menu_title);
d9d99f
   menu_id = grub_strdup (id ? : menu_title);
d9d99f
   if (! menu_id)
d9d99f
     goto fail;
d9d99f
+  grub_dprintf ("menu", "menu_id:\"%s\"\n", menu_id);
d9d99f
 
d9d99f
   /* Save argc, args to pass as parameters to block arg later. */
d9d99f
   menu_args = grub_malloc (sizeof (char*) * (argc + 1));
d9d99f
@@ -170,8 +173,12 @@ grub_normal_add_menu_entry (int argc, const char **args,
d9d99f
   }
d9d99f
 
d9d99f
   /* Add the menu entry at the end of the list.  */
d9d99f
+  int ind=0;
d9d99f
   while (*last)
d9d99f
-    last = &(*last)->next;
d9d99f
+    {
d9d99f
+      ind++;
d9d99f
+      last = &(*last)->next;
d9d99f
+    }
d9d99f
 
d9d99f
   *last = grub_zalloc (sizeof (**last));
d9d99f
   if (! *last)
d9d99f
@@ -190,6 +197,8 @@ grub_normal_add_menu_entry (int argc, const char **args,
d9d99f
   (*last)->submenu = submenu;
d9d99f
 
d9d99f
   menu->size++;
d9d99f
+  if (index)
d9d99f
+    *index = ind;
d9d99f
   return GRUB_ERR_NONE;
d9d99f
 
d9d99f
  fail:
d9d99f
@@ -286,7 +295,8 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
d9d99f
 				       users,
d9d99f
 				       ctxt->state[2].arg, 0,
d9d99f
 				       ctxt->state[3].arg,
d9d99f
-				       ctxt->extcmd->cmd->name[0] == 's');
d9d99f
+				       ctxt->extcmd->cmd->name[0] == 's',
d9d99f
+				       NULL);
d9d99f
 
d9d99f
   src = args[argc - 1];
d9d99f
   args[argc - 1] = NULL;
d9d99f
@@ -303,7 +313,7 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
d9d99f
 				  ctxt->state[0].args, ctxt->state[4].arg,
d9d99f
 				  users,
d9d99f
 				  ctxt->state[2].arg, prefix, src + 1,
d9d99f
-				  ctxt->extcmd->cmd->name[0] == 's');
d9d99f
+				  ctxt->extcmd->cmd->name[0] == 's', NULL);
d9d99f
 
d9d99f
   src[len - 1] = ch;
d9d99f
   args[argc - 1] = src;
d9d99f
diff --git a/include/grub/normal.h b/include/grub/normal.h
d9d99f
index 218cbabccaf..cb9901f41b3 100644
d9d99f
--- a/include/grub/normal.h
d9d99f
+++ b/include/grub/normal.h
d9d99f
@@ -145,7 +145,7 @@ grub_normal_add_menu_entry (int argc, const char **args, char **classes,
d9d99f
 			    const char *id,
d9d99f
 			    const char *users, const char *hotkey,
d9d99f
 			    const char *prefix, const char *sourcecode,
d9d99f
-			    int submenu);
d9d99f
+			    int submenu, int *index);
d9d99f
 
d9d99f
 grub_err_t
d9d99f
 grub_normal_set_password (const char *user, const char *password);