]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
util/grub-install-common: Minor improvements to printing of grub-mkimage command
authorGlenn Washburn <development@efficientek.com>
Fri, 22 Sep 2023 19:34:17 +0000 (14:34 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 3 Oct 2023 13:35:24 +0000 (15:35 +0200)
This is a preparatory patch to make the following patch less cluttered. The
only visible change made here is to not print extra spaces when either or
both --note or --disable-shim-lock are not given and to not print an extra
space at the end of the command. The latter is done by constructing the
trailing argument string with spaces in front of each argument rather than
trailing. The allocation of the argument string is made precise, which has
the benefit of saving a few bytes, but more importantly self-documenting
what the needed allocated bytes are. Also, unneeded braces are removed from
an if block.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
util/grub-install-common.c

index 52a29d1cb8e05d0811746d71808f5906db3f801a..f9b9201c894e18da7d51b0064fb4197c54f0c55b 100644 (file)
@@ -617,60 +617,58 @@ 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);
 
   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++ = '\'';
-      *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' "
+  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);
+                 "--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);
   free (s);
 
   tgt = grub_install_get_image_target (mkimage_target);