[1/2] criu: initialize logging for libraries from log_set_loglevel()

Submitted by Andrey Vagin on April 6, 2018, 7:49 a.m.

Details

Message ID 20180406074909.20412-1-avagin@virtuozzo.com
State Accepted
Series "Series without cover letter"
Commit 621a80fccfdd1e560ed7f1756332049a51dcae26
Headers show

Commit Message

Andrey Vagin April 6, 2018, 7:49 a.m.
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@virtuozzo.com>
---
 criu/crtools.c | 26 --------------------------
 criu/log.c     | 28 ++++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 26 deletions(-)

Patch hide | download patch | download mbox

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)

Comments

Dmitry Safonov April 6, 2018, 1:47 p.m.
2018-04-06 8:49 GMT+01:00 Andrei Vagin <avagin@virtuozzo.com>:
> 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@virtuozzo.com>

LGTM,
Reviewed-by: Dmitry Safonov <0x7f454c46@gmail.com>
Adrian Reber April 6, 2018, 2:34 p.m.
Makes sense.

Series Acked-by: Adrian Reber <areber@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@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
>