[CRIU] [PATCH 1/2] criu: initialize logging for libraries from log_set_loglevel()
Adrian Reber
areber at redhat.com
Fri Apr 6 17:34:15 MSK 2018
Makes sense.
Series Acked-by: Adrian Reber <areber at redhat.com>
On Fri, Apr 06, 2018 at 10:49:08AM +0300, Andrei Vagin wrote:
> We have three code paths, where we call log_set_loglevel() and in all
> these places, we need to initialize libraries logging engines, so it is
> better to do this from one function. For example, currently we forgot to
> initialize soccr logging for criu swrk.
>
> Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
> ---
> criu/crtools.c | 26 --------------------------
> criu/log.c | 28 ++++++++++++++++++++++++++++
> 2 files changed, 28 insertions(+), 26 deletions(-)
>
> diff --git a/criu/crtools.c b/criu/crtools.c
> index 17e16ce86..01da7c9b5 100644
> --- a/criu/crtools.c
> +++ b/criu/crtools.c
> @@ -56,8 +56,6 @@
> #include "sysctl.h"
> #include "img-remote.h"
>
> -#include "../soccr/soccr.h"
> -
> struct cr_options opts;
> char **global_conf = NULL;
> char **user_conf = NULL;
> @@ -214,28 +212,6 @@ bool deprecated_ok(char *what)
> return false;
> }
>
> -static void soccr_print_on_level(unsigned int loglevel, const char *format, ...)
> -{
> - va_list args;
> - int lv;
> -
> - switch (loglevel) {
> - case SOCCR_LOG_DBG:
> - lv = LOG_DEBUG;
> - break;
> - case SOCCR_LOG_ERR:
> - lv = LOG_ERROR;
> - break;
> - default:
> - lv = LOG_INFO;
> - break;
> - }
> -
> - va_start(args, format);
> - vprint_on_level(lv, format, args);
> - va_end(args);
> -}
> -
> static void rlimit_unlimit_nofile_self(void)
> {
> struct rlimit new;
> @@ -963,8 +939,6 @@ int main(int argc, char *argv[], char *envp[])
>
> if (log_init(opts.output))
> return 1;
> - libsoccr_set_log(log_level, soccr_print_on_level);
> - compel_log_init(vprint_on_level, log_get_loglevel());
>
> print_versions();
>
> diff --git a/criu/log.c b/criu/log.c
> index be3e4499e..22c6f2950 100644
> --- a/criu/log.c
> +++ b/criu/log.c
> @@ -20,6 +20,9 @@
> #include "rst-malloc.h"
> #include "common/lock.h"
> #include "string.h"
> +#include "../soccr/soccr.h"
> +#include "compel/log.h"
> +
>
> #define DEFAULT_LOGFD STDERR_FILENO
> /* Enable timestamps if verbosity is increased from default */
> @@ -199,9 +202,34 @@ void log_fini(void)
> close_service_fd(LOG_FD_OFF);
> }
>
> +static void soccr_print_on_level(unsigned int loglevel, const char *format, ...)
> +{
> + va_list args;
> + int lv;
> +
> + switch (loglevel) {
> + case SOCCR_LOG_DBG:
> + lv = LOG_DEBUG;
> + break;
> + case SOCCR_LOG_ERR:
> + lv = LOG_ERROR;
> + break;
> + default:
> + lv = LOG_INFO;
> + break;
> + }
> +
> + va_start(args, format);
> + vprint_on_level(lv, format, args);
> + va_end(args);
> +}
> +
> void log_set_loglevel(unsigned int level)
> {
> current_loglevel = level;
> +
> + libsoccr_set_log(level, soccr_print_on_level);
> + compel_log_init(vprint_on_level, level);
> }
>
> unsigned int log_get_loglevel(void)
> --
> 2.14.3
>
More information about the CRIU
mailing list