[lxc-devel] [PATCH] Fix handling of empty config keys

Serge Hallyn serge.hallyn at ubuntu.com
Thu Jan 23 00:22:04 UTC 2014


Quoting Stéphane Graber (stgraber at ubuntu.com):
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  src/lxc/lxc_info.c   | 6 ++++--
>  src/python-lxc/lxc.c | 4 ++++
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c
> index 2bd695e..ee45c58 100644
> --- a/src/lxc/lxc_info.c
> +++ b/src/lxc/lxc_info.c
> @@ -332,7 +332,7 @@ static int print_info(const char *name, const char *lxcpath)
>  	for(i = 0; i < keys; i++) {
>  		int len = c->get_config_item(c, key[i], NULL, 0);
>  
> -		if (len >= 0) {
> +		if (len > 0) {
>  			char *val = (char*) malloc(sizeof(char)*len + 1);
>  
>  			if (c->get_config_item(c, key[i], val, len + 1) != len) {
> @@ -341,8 +341,10 @@ static int print_info(const char *name, const char *lxcpath)
>  				printf("%s = %s\n", key[i], val);
>  			}
>  			free(val);
> +		} else if (len == 0) {
> +			printf("%s =\n", key[i]);
>  		} else {
> -			fprintf(stderr, "%s unset or invalid\n", key[i]);
> +			fprintf(stderr, "%s invalid\n", key[i]);
>  		}
>  	}
>  
> diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
> index 33b3e41..05727bf 100644
> --- a/src/python-lxc/lxc.c
> +++ b/src/python-lxc/lxc.c
> @@ -843,6 +843,10 @@ Container_get_config_item(Container *self, PyObject *args, PyObject *kwds)
>          return NULL;
>      }
>  
> +    if (len == 0) {
> +        return PyUnicode_FromString("");
> +    }
> +
>      char* value = (char*) malloc(sizeof(char)*len + 1);
>      if (value == NULL)
>          return PyErr_NoMemory();
> -- 
> 1.8.5.3
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list