bootctl: fix display of options with embedeed newlines
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 15 Jun 2019 14:37:55 +0000 (16:37 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Jun 2019 01:30:58 +0000 (10:30 +0900)
I have an .efi image with embedded newlinews. Now I don't even remember if it
was created for testing or by accident, but it doesn't really matter. We should
display such files correctly.

(This isn't a problem with normal BLS entries, because input is split into lines
so newlines are consumed.)

src/boot/bootctl.c

index e7ba8b4..2f195f1 100644 (file)
@@ -25,6 +25,7 @@
 #include "copy.h"
 #include "dirent-util.h"
 #include "efivars.h"
+#include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
@@ -377,13 +378,24 @@ static int boot_entry_show(const BootEntry *e, bool show_as_default) {
                                      *s,
                                      &status);
         if (!strv_isempty(e->options)) {
-                _cleanup_free_ char *t;
+                _cleanup_free_ char *t = NULL, *t2 = NULL;
+                _cleanup_strv_free_ char **ts = NULL;
 
                 t = strv_join(e->options, " ");
                 if (!t)
                         return log_oom();
 
-                printf("      options: %s\n", t);
+
+                ts = strv_split_newlines(t);
+                if (!ts)
+                        return log_oom();
+
+                t2 = strv_join(ts, "\n              ");
+                if (!t2)
+                        return log_oom();
+
+
+                printf("      options: %s\n", t2);
         }
         if (e->device_tree)
                 boot_entry_file_list("devicetree", e->root, e->device_tree, &status);