Quoting Qiang Huang (h.huangqi...@huawei.com):
> Right now if we use lxc-execute without log level set, we get error:
> lxc: invalid log priority NOTSET.
> Because we set log level manually in execute_start(), but didn't
> check if we have a valid log level or not, so fix it.
> 
> Signed-off-by: Qiang Huang <h.huangqi...@huawei.com>

Acked-by: Serge E. Hallyn <serge.hal...@ubuntu.com>

thanks,
-serge

> ---
>  src/lxc/execute.c | 15 +++++++++++----
>  src/lxc/log.c     |  8 ++++++++
>  src/lxc/log.h     |  2 ++
>  3 files changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lxc/execute.c b/src/lxc/execute.c
> index 9bf33ca..ec5cd29 100644
> --- a/src/lxc/execute.c
> +++ b/src/lxc/execute.c
> @@ -96,8 +96,11 @@ static int execute_start(struct lxc_handler *handler, 
> void* data)
>       argc_add = 4;
>       if (my_args->quiet)
>               argc_add++;
> -     if (!handler->conf->rootfs.path)
> -             argc_add+=6;
> +     if (!handler->conf->rootfs.path) {
> +             argc_add += 4;
> +             if (lxc_log_has_valid_level())
> +                     argc_add += 2;
> +     }
> 
>       argv = malloc((argc + argc_add) * sizeof(*argv));
>       if (!argv)
> @@ -116,8 +119,12 @@ static int execute_start(struct lxc_handler *handler, 
> void* data)
>               argv[i++] = (char *)handler->name;
>               argv[i++] = "--lxcpath";
>               argv[i++] = (char *)handler->lxcpath;
> -             argv[i++] = "--logpriority";
> -             argv[i++] = (char 
> *)lxc_log_priority_to_string(lxc_log_get_level());
> +
> +             if (lxc_log_has_valid_level()) {
> +                     argv[i++] = "--logpriority";
> +                     argv[i++] = (char *)
> +                             lxc_log_priority_to_string(lxc_log_get_level());
> +             }
>       }
>       argv[i++] = "--";
>       for (j = 0; j < argc; j++)
> diff --git a/src/lxc/log.c b/src/lxc/log.c
> index d49a544..6c275ac 100644
> --- a/src/lxc/log.c
> +++ b/src/lxc/log.c
> @@ -370,6 +370,14 @@ extern int lxc_log_get_level(void)
>       return lxc_log_category_lxc.priority;
>  }
> 
> +extern bool lxc_log_has_valid_level(void)
> +{
> +     int log_level = lxc_log_get_level();
> +     if (log_level < 0 || log_level >= LXC_LOG_PRIORITY_NOTSET)
> +             return false;
> +     return true;
> +}
> +
>  /*
>   * This is called when we read a lxc.logfile entry in a lxc.conf file.  This
>   * happens after processing command line arguments, which override the .conf
> diff --git a/src/lxc/log.h b/src/lxc/log.h
> index 2fd4050..03dd569 100644
> --- a/src/lxc/log.h
> +++ b/src/lxc/log.h
> @@ -28,6 +28,7 @@
>  #include <stdio.h>
>  #include <sys/time.h>
>  #include <string.h>
> +#include <stdbool.h>
> 
>  #ifndef O_CLOEXEC
>  #define O_CLOEXEC 02000000
> @@ -296,5 +297,6 @@ extern int lxc_log_set_level(int level);
>  extern void lxc_log_set_prefix(const char *prefix);
>  extern const char *lxc_log_get_file(void);
>  extern int lxc_log_get_level(void);
> +extern bool lxc_log_has_valid_level(void);
>  extern const char *lxc_log_get_prefix(void);
>  #endif
> -- 
> 1.8.3
> 

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to