[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [OSSTEST PATCH 22/24] host examination: bootloader: Do not use ed



These ed runes are what I used to develop this approach, but they are
rather opaque to those very few programmers who are not proficient
users of ed, the standard text editor.

Also, using target_editfile_root means we keep a record of the
bootloader config in the logs, which is desirable.

The regexps used to edit the grub2 confiug are slightly more
sophisticated than the ed ones were.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 ts-examine-serial-pre | 49 ++++++++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/ts-examine-serial-pre b/ts-examine-serial-pre
index 26fbc56..86f332f 100755
--- a/ts-examine-serial-pre
+++ b/ts-examine-serial-pre
@@ -61,35 +61,34 @@ END
 
 sub bootloader () {
     my $c = get_cookie('bootloader');
-    my $ed = sub {
-       my ($file,$script) = @_;
-       my $cmd = <<END;
-            ed $file <<EOF
-$script
-w
-q
-EOF
-END
-       $cmd .= setupboot_bootloader_edited_rune($ho);
-       target_cmd_root($ho, $cmd, 200);
+    my $edit = sub {
+       my ($file,$editor) = @_;
+       target_editfile_root($ho,$file,$editor);
+       target_cmd_root($ho, setupboot_bootloader_edited_rune($ho), 200);
     };
     my $edscript;
     if ($ho->{Flags}{'need-uboot-bootscr'}) {
-       $ed->('/boot/boot.xen',<<END)
-/^echo Loaded
-i
-echo osstest uboot $c
-.
-END
+       $edit->('/boot/boot.xen', sub {
+            my $done;
+            while (<::EI>) {
+               if (m/^echo Loaded/ && !$done++) {
+                   print ::EO "echo osstest uboot $c\n";
+               }
+               print ::EO;
+           }
+       });
     } else {
-       $ed->('/boot/grub/grub.cfg',<<END); # no support for grub1
-1 
-/^ *menuentry  *
-s/'\([^']*\)'/'$c \1'
-1
-/^ *submenu  *
-s
-END
+       # no support for grub1
+       $edit->('/boot/grub/grub.cfg', sub {
+            my %done;
+            while (<::EI>) {
+               s{^(\s* ( menuentry | submenu ) \s+
+                     (['"]) )( [^'"]+ \3) }{
+                    $done{$2}++ ? $& : "$1$c $4"
+                }xe;
+               print ::EO;
+           }
+       });
     }
 }
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.