pygrub: fix extlinux parsing
PATCH 1/1 pygrub: fix extlinux parsing
# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1325501151 -3600
# Node ID bd59a07ed41187bcafc4dd5214f0744c66ef2069 # Parent 3e02aa9670b3265e36bdddbd4760415cd87d047b
pygrub: fix extlinux parsing
pygrub was unable to parse extlinux config files correctly, exactly the ones like:
LABEL grsec
KERNEL vmlinuz-3.0.10-grsec
APPEND initrd=initramfs-3.0.10-grsec
root=UUID=cfd4a7b4-8c40-4025-b877-8205f1c622ee
modules=sd-mod,usb-storage,ext4 xen quiet
This patch fixes it, adding a new case when parsing the "append" line, that searches for the initrd image.
tools/pygrub/src/ExtLinuxConf.py +10 -1
@@ -60,6 +60,13 @@ class ExtLinuxImage(object): # Bypass regular self.commands handling com = None + elif arg.find(" "): + # find initrd image in append line + args = arg.strip().split(" ") + for a in args: + if a.lower().startswith("initrd"): + setattr(self, "initrd", a.replace("initrd=", "")) + arg = arg.replace(a, "") if com is not None and self.commands.has_key(com): if self.commands[com] is not None:
@@ -86,10 +93,12 @@ class ExtLinuxImage(object): self._args = args def get_kernel(self): return self._kernel + def set_args(self, val): + self._args = val def get_args(self): return self._args kernel = property(get_kernel, set_kernel) - args = property(get_args) + args = property(get_args, set_args) def set_initrd(self, val): self._initrd = (None,val)
Quoted 16 lines · Roger Pau Monne
# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1325501151 -3600
# Node IDbd59a07ed41187bcafc4dd5214f0744c66ef2069# Parent3e02aa9670b3265e36bdddbd4760415cd87d047b
pygrub: fix extlinux parsingpygrub was unable to parse extlinux config files correctly, exactly the ones like:
LABEL grsec
KERNEL vmlinuz-3.0.10-grsec
APPEND initrd=initramfs-3.0.10-grsec
root=UUID=cfd4a7b4-8c40-4025-b877-8205f1c622ee
modules=sd-mod,usb-storage,ext4 xen quiet
Quoted 4 lines
This patch fixes it, adding a new case when parsing the "append" line, that searches for the initrd image.
Signed-off-by Roger Pau Monne <[email protected]>
Please could you also supply an example file for your platform as a patch to tools/pygrub/examples.
tools/pygrub/src/ExtLinuxConf.py class ExtLinuxImage(object): · line 67
Quoted 12 lines
diff -r
3e02aa9670b3-rbd59a07ed411tools/pygrub/src/ExtLinuxConf.pytools/pygrub/src/ExtLinuxConf.py +5
-0@@ -60,6 +60,13 @@ class ExtLinuxImage(object): # Bypass regular self.commands handling com = None + elif arg.find(" "): + # find initrd image in append line + args = arg.strip().split(" ") + for a in args: + if a.lower().startswith("initrd"):
Should check for "initrd=" here?
Or perhaps:
* check for "="
* split into "k = v"
* check that k is precisely "initrd"
the first two are probably doable in the same str.split invocation if you handle the exception correctly.
Quoted 6 lines
tools/pygrub/src/ExtLinuxConf.py +2
-0+ setattr(self, "initrd", a.replace("initrd=", "")) + arg = arg.replace(a, "") if com is not None and self.commands.has_key(com): if self.commands[com] is not None:
tools/pygrub/src/ExtLinuxConf.py class ExtLinuxImage(object): · line 101
Quoted 10 lines
tools/pygrub/src/ExtLinuxConf.py +3
-1@@ -86,10 +93,12 @@ class ExtLinuxImage(object): self._args = args def get_kernel(self): return self._kernel + def set_args(self, val): + self._args = val def get_args(self): return self._args kernel = property(get_kernel, set_kernel) - args = property(get_args) + args = property(get_args, set_args)
Are these something required by arg.replace?
Ian.
2012/1/3 Ian Campbell <[email protected]>:
Quoted 17 lines · Roger Pau Monne
Quoted 16 lines
# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1325501151 -3600
# Node IDbd59a07ed41187bcafc4dd5214f0744c66ef2069# Parent 3e02aa9670b3265e36bdddbd4760415cd87d047b
pygrub: fix extlinux parsingpygrub was unable to parse extlinux config files correctly, exactly the ones like:
LABEL grsec
KERNEL vmlinuz-3.0.10-grsec
APPEND initrd=initramfs-3.0.10-grsec
root=UUID=cfd4a7b4-8c40-4025-b877-8205f1c622ee
modules=sd-mod,usb-storage,ext4 xen quiet
Quoted 7 lines
Quoted 4 lines
This patch fixes it, adding a new case when parsing the "append" line, that searches for the initrd image.
Signed-off-by Roger Pau Monne <[email protected]>Please could you also supply an example file for your platform as a patch to
tools/pygrub/examples.
Done.
Quoted 5 lines
Quoted 5 lines
diff -r
3e02aa9670b3-rbd59a07ed411tools/pygrub/src/ExtLinuxConf.pytools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +0
-0@@ -60,6 +60,13 @@ class ExtLinuxImage(object):
Quoted 9 lines
Quoted 7 lines
tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +0
-0# Bypass regular self.commands handlingcom = None
+ elifarg.find(" "):
+ # find initrd image in append line
+ args = arg.strip().split(" ")
+ for a in args:
+ if a.lower().startswith("initrd"):Should check for "initrd=" here?
Yes
Quoted 6 lines
Or perhaps:
* check for "="
* split into "k = v"
* check that k is precisely "initrd"
the first two are probably doable in the same str.split invocation if you handle the exception correctly.
I'm not really sure about splitting '=', some args, like root, are root=UUID=XXXX, which might be difficult to parse in a single split (at least for me). Will look at it later and post an updated patch.
Quoted 18 lines
Quoted 8 lines
+ setattr(self, "initrd",
a.replace("initrd=", ""))
+ arg =arg.replace(a, "")if com is not None and
self.commands.has_key(com):
if self.commands[com] is not None:tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +0
-0@@ -86,10 +93,12 @@ class ExtLinuxImage(object):self._args = args
defget_kernel(self):Quoted 8 lines
return self._kernel
+ defset_args(self, val):
+ self._args = val
defget_args(self):
return self._args
kernel =property(get_kernel, set_kernel)
- args =property(get_args)
+ args =property(get_args, set_args)Are these something required by arg.replace?
args was set when setting kernel in previous version, because it assumed the line was:
append <kernel> <args> --- <initrd>
So args where obtained when the kernel was parsed, but you can also have
kernel <kernel>
append <args>
And <args> contain the initrd path, I remove the "initrd=XXX" from the args and process them normally.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 52 lines · Roger Pau Monné
2012/1/3 Ian Campbell <[email protected]>:
Quoted 17 lines · Roger Pau Monne
Quoted 16 lines
# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1325501151 -3600
# Node IDbd59a07ed41187bcafc4dd5214f0744c66ef2069# Parent3e02aa9670b3265e36bdddbd4760415cd87d047b
pygrub: fix extlinux parsingpygrub was unable to parse extlinux config files correctly, exactly the ones like:
LABEL grsec
KERNEL vmlinuz-3.0.10-grsec
APPEND initrd=initramfs-3.0.10-grsec
root=UUID=cfd4a7b4-8c40-4025-b877-8205f1c622ee
modules=sd-mod,usb-storage,ext4 xen quietQuoted 7 lines
Quoted 4 lines
This patch fixes it, adding a new case when parsing the "append" line, that searches for the initrd image.
Signed-off-by Roger Pau Monne <[email protected]>Please could you also supply an example file for your platform as a patch to
tools/pygrub/examples.Done.
Quoted 5 lines
Quoted 5 lines
diff -r
3e02aa9670b3-rbd59a07ed411tools/pygrub/src/ExtLinuxConf.pytools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +0
-0@@ -60,6 +60,13 @@ class ExtLinuxImage(object):Quoted 9 lines
tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 class ExtLinuxImage(object): · line 67
Quoted 7 lines
tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +5
-0# Bypass regular self.commands handling com = None + elif arg.find(" "): + # find initrd image in append line + args = arg.strip().split(" ") + for a in args: + if a.lower().startswith("initrd"):Should check for "initrd=" here?
Yes
Quoted 6 lines
Or perhaps:
* check for "="
* split into "k = v"
* check that k is precisely "initrd"
the first two are probably doable in the same str.split invocation if you handle the exception correctly.
Quoted 3 lines
I'm not really sure about splitting '=', some args, like root, are root=UUID=XXXX, which might be difficult to parse in a single split (at least for me). Will look at it later and post an updated patch.
I think you need to always split on the first =.
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +2
-0+ setattr(self, "initrd", a.replace("initrd=", "")) + arg = arg.replace(a, "")Quoted 15 lines
tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 class ExtLinuxImage(object): · line 101
Quoted 13 lines
tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +3
-1if com is not None and self.commands.has_key(com): if self.commands[com] is not None:@@ -86,10 +93,12 @@ class ExtLinuxImage(object): self._args = args def get_kernel(self): return self._kernel + def set_args(self, val): + self._args = val def get_args(self): return self._args kernel = property(get_kernel, set_kernel) - args = property(get_args) + args = property(get_args, set_args)Are these something required by arg.replace?
Quoted 4 lines
args was set when setting kernel in previous version, because it assumed the line was:
append <kernel> <args> --- <initrd>
Ah, right. This is the mboot.c32 syntax (i.e. it is always associated with "kernel mboot.c32"). IIRC it is actually
append <hypervisor> <args> --- <kernel> <args> --- <initrd>
Or more generally "[<thing> <args> ---]+"
Perhaps this ought to key off the presence of kernel mboot.c32 specifically?
Quoted 4 lines
So args where obtained when the kernel was parsed, but you can also have
kernel <kernel>
append <args>
This is actually the "normal" extlinux syntax.
Quoted 2 lines
And <args> contain the initrd path, I remove the "initrd=XXX" from the args and process them normally.
Right.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
2012/1/3 Ian Campbell <[email protected]>:
Quoted 53 lines · Roger Pau Monné
Quoted 52 lines
2012/1/3 Ian Campbell <[email protected]>:
Quoted 17 lines · Roger Pau Monne
Quoted 16 lines
# HG changeset patch
# User Roger Pau Monne <[email protected]> # Date 1325501151 -3600
# Node IDbd59a07ed41187bcafc4dd5214f0744c66ef2069# Parent 3e02aa9670b3265e36bdddbd4760415cd87d047b
pygrub: fix extlinux parsingpygrub was unable to parse extlinux config files correctly, exactly the ones like:
LABEL grsec
KERNEL vmlinuz-3.0.10-grsec
APPEND initrd=initramfs-3.0.10-grsec
root=UUID=cfd4a7b4-8c40-4025-b877-8205f1c622ee
modules=sd-mod,usb-storage,ext4 xen quietQuoted 7 lines
Quoted 4 lines
This patch fixes it, adding a new case when parsing the "append" line, that searches for the initrd image.
Signed-off-by Roger Pau Monne <[email protected]>Please could you also supply an example file for your platform as a patch to
tools/pygrub/examples.Done.
Quoted 5 lines
Quoted 5 lines
diff -r
3e02aa9670b3-rbd59a07ed411tools/pygrub/src/ExtLinuxConf.pytools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +0
-0@@ -60,6 +60,13 @@ class ExtLinuxImage(object):Quoted 9 lines
Quoted 7 lines
tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +0
-0# Bypass regular self.commands handlingcom = None
+ elifarg.find(" "):
+ # find initrd image in append line
+ args = arg.strip().split(" ")
+ for a in args:
+ if a.lower().startswith("initrd"):Should check for "initrd=" here?
Yes
Quoted 6 lines
Or perhaps:
* check for "="
* split into "k = v"
* check that k is precisely "initrd"
the first two are probably doable in the same str.split invocation if you handle the exception correctly.
Quoted 5 lines
Quoted 3 lines
I'm not really sure about splitting '=', some args, like root, are root=UUID=XXXX, which might be difficult to parse in a single split (at least for me). Will look at it later and post an updated patch.
I think you need to always split on the first =.
I was not really sure if args could be like "root=XXX initrd=XXX" or if initrd should be the first one. Anyway, I've sent an updated version that I think is safer.
Quoted 25 lines
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
+ setattr(self, "initrd",
a.replace("initrd=", ""))
+ arg =arg.replace(a, "")Quoted 15 lines
Quoted 5 lines
if com is not None and
self.commands.has_key(com):
if self.commands[com] is not None:tools/pygrub/src/ExtLinuxConf.py Mon Jan 02 11:45:51 2012 +0100 renamed from tools/pygrub/src/ExtLinuxConf.py Thu Dec 15 18:55:46 2011 +0100 +0
-0@@ -86,10 +93,12 @@ class ExtLinuxImage(object):self._args = args
defget_kernel(self):Quoted 8 lines
return self._kernel
+ defset_args(self, val):
+ self._args = val
defget_args(self):
return self._args
kernel =property(get_kernel, set_kernel)
- args =property(get_args)
+ args =property(get_args, set_args)Are these something required by arg.replace?
Quoted 4 lines
args was set when setting kernel in previous version, because it assumed the line was:
append <kernel> <args> --- <initrd>
Quoted 7 lines
Ah, right. This is the mboot.c32 syntax (i.e. it is always associated with "kernel mboot.c32"). IIRC it is actually
append <hypervisor> <args> --- <kernel> <args> --- <initrd> Or more generally "[<thing> <args> ---]+"Perhaps this ought to key off the presence of kernel mboot.c32 specifically?
It is handled in a previous "if".
Quoted 5 lines
Quoted 4 lines
So args where obtained when the kernel was parsed, but you can also have
kernel <kernel>
append <args>
Quoted 8 lines
This is actually the "normal" extlinux syntax.
Quoted 2 lines
And <args> contain the initrd path, I remove the "initrd=XXX" from the args and process them normally.
Right.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel