[lxc-devel] [PATCH 2/2] python3: Handle invalid global config keys

Stéphane Graber stgraber at ubuntu.com
Tue Jun 10 20:20:13 UTC 2014


On Tue, Jun 10, 2014 at 12:08:59PM -0400, Chuck Short wrote:
> 

> From ca1d20fd125bc63f8b0e04c80c1032f5bdb580b8 Mon Sep 17 00:00:00 2001
> From: Chuck Short <chuck.short at canonical.com>
> Date: Tue, 10 Jun 2014 12:05:58 -0400
> Subject: [PATCH 2/2] python3: Handle invalid global config keys
> 
> Signed-off-by: Chuck Short <chuck.short at canonical.com>

Acked-by: Stéphane Graber <stgraber at ubuntu.com>

I also pushed a third change to the python2-lxc branch so that it's now
fully back in sync with the python3 version of the binding.

> ---
>  lxc.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/lxc.c b/lxc.c
> index 6fb5f43..43b019a 100644
> --- a/lxc.c
> +++ b/lxc.c
> @@ -325,12 +325,20 @@ LXC_get_global_config_item(PyObject *self, PyObject *args, PyObject *kwds)
>  {
>      static char *kwlist[] = {"key", NULL};
>      char* key = NULL;
> +    const char* value = NULL;
>  
>      if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist,
>                                        &key))
>          return NULL;
>  
> -    return PyUnicode_FromString(lxc_get_global_config_item(key));
> +    value = lxc_get_global_config_item(key);
> +
> +    if (!value) {
> +        PyErr_SetString(PyExc_KeyError, "Invalid configuration key");
> +        return NULL;
> +    }
> +
> +    return PyUnicode_FromString(value);
>  }
>  
>  static PyObject *
> -- 
> 2.0.0
> 

> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140610/0d8eeff6/attachment.sig>


More information about the lxc-devel mailing list