All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org, Daniel Kiper <dkiper@net-space.pl>
Cc: Glenn Washburn <development@efficientek.com>
Subject: [PATCH] util/grub-install-common: Print usable grub-mkimage command
Date: Fri,  1 Sep 2023 23:33:03 -0500	[thread overview]
Message-ID: <20230902043303.3528342-1-development@efficientek.com> (raw)

When grub-install is run with the verbose option, it will print a log
message indicating the grub-mkimage command and arguments used.
GRUB no longer calls the grub-mkimage binary internally, however the
command logged is a command that if run should effectively be what
grub-install used. However, as this has changed some of the newer
options have been incorrectly added so that the printed command fails
when run seperately. This change makes the output command run as
intended. While here, improve the string allocation code to be more
precise.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 util/grub-install-common.c | 49 ++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/util/grub-install-common.c b/util/grub-install-common.c
index 52a29d1cb8e0..014741945e15 100644
--- a/util/grub-install-common.c
+++ b/util/grub-install-common.c
@@ -617,60 +617,73 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix,
   int dc = decompressors ();
 
   if (memdisk_path)
-    slen += 20 + grub_strlen (memdisk_path);
+    slen += sizeof (" --memdisk ''") + grub_strlen (memdisk_path);
   if (config_path)
-    slen += 20 + grub_strlen (config_path);
+    slen += sizeof (" --config ''") + grub_strlen (config_path);
+  if (dtb)
+    slen += sizeof (" --dtb ''") + grub_strlen (dtb);
+  if (sbat)
+    slen += sizeof (" --sbat ''") + grub_strlen (sbat);
 
   for (pk = pubkeys; pk < pubkeys + npubkeys; pk++)
-    slen += 20 + grub_strlen (*pk);
+    slen += sizeof (" --pubkey ''") + grub_strlen (*pk);
 
   for (md = modules.entries; *md; md++)
-    {
-      slen += 10 + grub_strlen (*md);
-    }
+    slen += sizeof (" ''") + grub_strlen (*md);
 
   p = s = xmalloc (slen);
   if (memdisk_path)
     {
+      *p++ = ' ';
       p = grub_stpcpy (p, "--memdisk '");
       p = grub_stpcpy (p, memdisk_path);
       *p++ = '\'';
-      *p++ = ' ';
     }
   if (config_path)
     {
+      *p++ = ' ';
       p = grub_stpcpy (p, "--config '");
       p = grub_stpcpy (p, config_path);
       *p++ = '\'';
+    }
+  if (dtb)
+    {
+      *p++ = ' ';
+      p = grub_stpcpy (p, "--dtb '");
+      p = grub_stpcpy (p, dtb);
+      *p++ = '\'';
+    }
+  if (sbat)
+    {
       *p++ = ' ';
+      p = grub_stpcpy (p, "--sbat '");
+      p = grub_stpcpy (p, dtb);
+      *p++ = '\'';
     }
   for (pk = pubkeys; pk < pubkeys + npubkeys; pk++)
     {
+      *p++ = ' ';
       p = grub_stpcpy (p, "--pubkey '");
       p = grub_stpcpy (p, *pk);
       *p++ = '\'';
-      *p++ = ' ';
     }
 
   for (md = modules.entries; *md; md++)
     {
+      *p++ = ' ';
       *p++ = '\'';
       p = grub_stpcpy (p, *md);
       *p++ = '\'';
-      *p++ = ' ';
     }
 
   *p = '\0';
 
-  grub_util_info ("grub-mkimage --directory '%s' --prefix '%s'"
-		  " --output '%s' "
-		  " --dtb '%s' "
-		  "--sbat '%s' "
-		  "--format '%s' --compression '%s' %s %s %s\n",
-		  dir, prefix,
-		  outname, dtb ? : "", sbat ? : "", mkimage_target,
-		  compnames[compression], note ? "--note" : "",
-		  disable_shim_lock ? "--disable-shim-lock" : "", s);
+  grub_util_info ("grub-mkimage --directory '%s' --prefix '%s' --output '%s'"
+		  " --format '%s' --compression '%s'%s%s%s\n",
+		  dir, prefix, outname,
+		  mkimage_target, compnames[compression],
+		  note ? " --note" : "",
+		  disable_shim_lock ? " --disable-shim-lock" : "", s);
   free (s);
 
   tgt = grub_install_get_image_target (mkimage_target);
-- 
2.34.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

             reply	other threads:[~2023-09-02  4:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-02  4:33 Glenn Washburn [this message]
2023-09-02 18:34 ` [PATCH] util/grub-install-common: Print usable grub-mkimage command Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230902043303.3528342-1-development@efficientek.com \
    --to=development@efficientek.com \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.