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

[Xen-devel] [XEN PATCH 2/3] read a grubenv file if it is next to the grub.cfg file


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "YOUNG, MICHAEL A." <m.a.young@xxxxxxxxxxxx>
  • Date: Fri, 25 Oct 2019 22:52:21 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=durham.ac.uk; dmarc=pass action=none header.from=durham.ac.uk; dkim=pass header.d=durham.ac.uk; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j7TaoTyM0pJll+A8glmDyS4mzp9+V71BAb5vP2iXglA=; b=WREPHqwU2O5LOVmxhiE22rcACpS6mz5PB4mjC1/Fku5jTO0bdsS2inePD65UZu2RCxBJlPvepcGKsRNlT10M9d4vJYSpqEx4aZuNlXgK+r/I49XOptDJaQhXYSBDKCggHi5GydKDJ+6rP4hbRth2Q0pz2J43cfXKAYSEB3GE5nZXDJegXEKfmJe9jbxMAcwsQYdEyPvwT7JetLPhOiurc5faVM8IA1e7919Indn4QHkqDR5+gxe9nAfW9mQA+pRxuL6hDcQ2GzMOMZgje4Rn8Vs/i2gesOVk3XYBCz0CB80NLJYTTIu1jX+sfvwjj26DWFq5LnBfmHyNY0m1ZIkUvQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XCmHEVol8SfXRVCPZ1zaFUQwK8iltlTA/2mJ2wxZ/gv6NL/ux6RNeg+Gk2dHZ2FaaSh8ZvNWLpHXPh1dqnzDvbuAx8TcA86F/BeAfzwRE68LvTmRbbX4Wwx5WubM5SGw01NOou2sIxdB6SDqxsngblVYyMQu665xZWG/IT+/2uv6zBfEN9z/4+3hEhcRs3gYKaEfPufmOIbC5I6Xt/iB4HtDid5UdYl8tToV+xl+M8ZUu//fTzgAJn2M9aPtdtIakJN2Wuex+fDwlAt7TaXuhNUGD++DSKRxJDmdzDnldwEMPsJoIk5x3+bibjqDXopBfYYJhBfLSRsDB8jyq9TBtw==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=m.a.young@xxxxxxxxxxxx;
  • Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "YOUNG, MICHAEL A." <m.a.young@xxxxxxxxxxxx>
  • Delivery-date: Fri, 25 Oct 2019 22:52:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVi4bcsVc5X9HnfkOVxxCiimkx9Q==
  • Thread-topic: [XEN PATCH 2/3] read a grubenv file if it is next to the grub.cfg file

When a grub.cfg file is found this patch checks if there is grubenv
file in the same directory as the grub.cfg file. If there is it
passes the contents to parse().

Signed-off-by: Michael Young <m.a.young@xxxxxxxxxxxx>
---
 tools/pygrub/src/pygrub | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index ce7ab0eb8c..53a0803817 100755
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -457,10 +457,25 @@ class Grub:
         # limit read size to avoid pathological cases
         buf = f.read(FS_READ_MAX)
         del f
-        if sys.version_info[0] < 3:
-            self.cf.parse(buf)
+        # check for a grubenv file next to the grub.cfg file
+        (fdir, fsep, ffile) = self.cf.filename.rpartition("/")
+        if fdir != "" and ffile == "grub.cfg":
+            fenv = fdir + "/grubenv"
         else:
-            self.cf.parse(buf.decode())
+            fenv = ""
+        if fenv != "" and fs.file_exists(fenv):
+            fenvf = fs.open_file(fenv)
+            grubenv = fenvf.read(FS_READ_MAX)
+            del fenvf
+            if sys.version_info[0] < 3:
+                self.cf.parse(buf, grubenv)
+            else:
+                self.cf.parse(buf.decode(), grubenv.decode())
+        else:
+            if sys.version_info[0] < 3:
+                self.cf.parse(buf)
+            else:
+                self.cf.parse(buf.decode())
 
     def image_index(self):
         if isinstance(self.cf.default, int):
-- 
2.21.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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