[CRIU] crit: Avoid full exception trace when meeting unknown magic in image
Andrew Vagin
avagin at odin.com
Fri May 29 05:32:35 PDT 2015
On Fri, May 29, 2015 at 01:59:42AM +0300, Pavel Emelyanov wrote:
> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
>
> ---
>
> diff --git a/crit b/crit
> index 88f3b8e..9cdd1b4 100755
> --- a/crit
> +++ b/crit
> @@ -20,7 +20,14 @@ def outf(opts):
>
> def decode(opts):
> indent = None
> - img = pycriu.images.load(inf(opts), opts['pretty'])
> +
> + try:
> + img = pycriu.images.load(inf(opts), opts['pretty'])
> + except pycriu.images.MagicException as exc:
> + print "Unknown magic %#x.\n"\
> + "Maybe you are feeding me an image with "\
> + "raw data(i.e. pages.img)?" % exc.magic
We need to print errors on stderr
print >>sys.stderr, "
And criu must return non-zero code in this case
> + return
>
> if opts['pretty']:
> indent = 4
> diff --git a/pycriu/images/images.py b/pycriu/images/images.py
> index c8c2e9e..5efd60b 100644
> --- a/pycriu/images/images.py
> +++ b/pycriu/images/images.py
> @@ -50,6 +50,10 @@ import pb2dict
> import magic
> from pb import *
>
> +class MagicException(Exception):
> + def __init__(self, magic):
> + self.magic = magic
> +
> # Generic class to handle loading/dumping criu images entries from/to bin
> # format to/from dict(json).
> class entry_handler:
> @@ -300,9 +304,7 @@ def load(f, pretty = False):
> try:
> m = magic.by_val[img_magic]
> except:
> - raise Exception("Unknown magic "+str(img_magic)+".\n"\
> - "Maybe you are feeding me an image with "\
> - "raw data(i.e. pages.img)?")
> + raise MagicException(img_magic)
>
> try:
> handler = handlers[m]
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list