From: Ian Campbell Subject: Re: pygrub: verify chosen kernel really exists Date: Mon, 25 Jun 2012 10:07:46 +0100 Message-ID: <1340615266.3832.12.camel@zakaz.uk.xensource.com> References: <4FE4BB5F.5000103@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4FE4BB5F.5000103@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On Fri, 2012-06-22 at 19:37 +0100, Andrew Cooper wrote: > > diff -r 32034d1914a6 tools/pygrub/src/pygrub > --- a/tools/pygrub/src/pygrub > +++ b/tools/pygrub/src/pygrub > @@ -821,10 +821,15 @@ if __name__ == "__main__": > if not fs: > raise RuntimeError, "Unable to find partition containing > kernel" > > + # Does the chosen kernel really exist ? > + try: > + data = fs.open_file(chosencfg["kernel"]).read() If you make this use .exists() and left the open/read where it was that would be more in keeping with the intended meaning of the not_really flag. > + except: > + raise RuntimeError, "The chosen kernel does not exist" > + > if not_really: > bootcfg["kernel"] = "" % chosencfg["kernel"] > else: > - data = fs.open_file(chosencfg["kernel"]).read() > (tfd, bootcfg["kernel"]) = > tempfile.mkstemp(prefix="boot_kernel.", > > dir=output_directory) > os.write(tfd, data)