[CRIU] [PATCH 4/5] plugin: allow to use logging function in plugins

Andrey Wagin avagin at gmail.com
Thu Dec 5 10:19:41 PST 2013


2013/12/5 Pavel Emelyanov <xemul at parallels.com>:
> On 12/05/2013 09:58 PM, Andrey Vagin wrote:
>
> Some comment would be great. In particular -- what this allowance mean?
> Just moving the stuff into headers? Why does it help?

criu-plugin.h is a "public" header. It contains prototypes of
functions, which can be used by plugins. A plugin is linked with criu,
so it can call any function of criu.

>
>> Signed-off-by: Andrey Vagin <avagin at openvz.org>
>> ---
>>  include/criu-plugin.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>  include/log-levels.h  | 12 ------------
>>  include/log.h         | 43 +------------------------------------------
>>  pie/log-simple.c      |  1 -
>>  4 files changed, 51 insertions(+), 55 deletions(-)
>>  delete mode 100644 include/log-levels.h
>>
>> diff --git a/include/criu-plugin.h b/include/criu-plugin.h
>> index 963d1d0..3e46c69 100644
>> --- a/include/criu-plugin.h
>> +++ b/include/criu-plugin.h
>> @@ -35,4 +35,54 @@ typedef void (cr_plugin_fini_t)(void);
>>  typedef int (cr_plugin_dump_unix_sk_t)(int fd, int ino, int peer_ino);
>>  typedef int (cr_plugin_restore_unix_sk_t)(int ino, char *name, int len);
>>
>> +
>> +extern void print_on_level(unsigned int loglevel, const char *format, ...)
>> +     __attribute__ ((__format__ (__printf__, 2, 3)));
>> +
>> +#define LOG_MSG              (0) /* Print message regardless of log level */
>> +#define LOG_ERROR    (1) /* Errors only, when we're in trouble */
>> +#define LOG_WARN     (2) /* Warnings, dazen and confused but trying to continue */
>> +#define LOG_INFO     (3) /* Informative, everything is fine */
>> +#define LOG_DEBUG    (4) /* Debug only */
>> +
>> +#define DEFAULT_LOGLEVEL     LOG_WARN
>> +
>> +#ifndef LOG_PREFIX
>> +# define LOG_PREFIX
>> +#endif
>> +
>> +#define pr_msg(fmt, ...)                                                     \
>> +     print_on_level(LOG_MSG,                                                 \
>> +                    fmt, ##__VA_ARGS__)
>> +
>> +#define pr_info(fmt, ...)                                                    \
>> +     print_on_level(LOG_INFO,                                                \
>> +                    LOG_PREFIX fmt, ##__VA_ARGS__)
>> +
>> +#define pr_err(fmt, ...)                                                     \
>> +     print_on_level(LOG_ERROR,                                               \
>> +                    "Error (%s:%d): " LOG_PREFIX fmt,                        \
>> +                    __FILE__, __LINE__, ##__VA_ARGS__)
>> +
>> +#define pr_err_once(fmt, ...)                                                        \
>> +     do {                                                                    \
>> +             static bool __printed;                                          \
>> +             if (!__printed) {                                               \
>> +                     pr_err(fmt, ##__VA_ARGS__);                             \
>> +                     __printed = 1;                                          \
>> +             }                                                               \
>> +     } while (0)
>> +
>> +#define pr_warn(fmt, ...)                                                    \
>> +     print_on_level(LOG_WARN,                                                \
>> +                    "Warn  (%s:%d): " LOG_PREFIX fmt,                        \
>> +                    __FILE__, __LINE__, ##__VA_ARGS__)
>> +
>> +#define pr_debug(fmt, ...)                                                   \
>> +     print_on_level(LOG_DEBUG,                                               \
>> +                    LOG_PREFIX fmt, ##__VA_ARGS__)
>> +
>> +#define pr_perror(fmt, ...)                                                  \
>> +     pr_err(fmt ": %m\n", ##__VA_ARGS__)
>> +
>>  #endif
>> diff --git a/include/log-levels.h b/include/log-levels.h
>> deleted file mode 100644
>> index 3e6753f..0000000
>> --- a/include/log-levels.h
>> +++ /dev/null
>> @@ -1,12 +0,0 @@
>> -#ifndef __CR_LOG_LEVELS_H__
>> -#define __CR_LOG_LEVELS_H__
>> -
>> -#define LOG_MSG              (0) /* Print message regardless of log level */
>> -#define LOG_ERROR    (1) /* Errors only, when we're in trouble */
>> -#define LOG_WARN     (2) /* Warnings, dazen and confused but trying to continue */
>> -#define LOG_INFO     (3) /* Informative, everything is fine */
>> -#define LOG_DEBUG    (4) /* Debug only */
>> -
>> -#define DEFAULT_LOGLEVEL     LOG_WARN
>> -
>> -#endif /* __CR_LOG_LEVELS_H__ */
>> diff --git a/include/log.h b/include/log.h
>> index 1060254..4f26fc9 100644
>> --- a/include/log.h
>> +++ b/include/log.h
>> @@ -1,7 +1,7 @@
>>  #ifndef __CR_LOG_H__
>>  #define __CR_LOG_H__
>>
>> -#include "log-levels.h"
>> +#include "criu-plugin.h"
>>
>>  extern int log_init(const char *output);
>>  extern void log_fini(void);
>> @@ -16,49 +16,8 @@ extern unsigned int log_get_loglevel(void);
>>
>>  extern int vprint_num(char *buf, int blen, int num, char **ps);
>>
>> -extern void print_on_level(unsigned int loglevel, const char *format, ...)
>> -     __attribute__ ((__format__ (__printf__, 2, 3)));
>> -
>>  extern int write_pidfile(int pid);
>>
>> -#ifndef LOG_PREFIX
>> -# define LOG_PREFIX
>> -#endif
>> -
>> -#define pr_msg(fmt, ...)                                                     \
>> -     print_on_level(LOG_MSG,                                                 \
>> -                    fmt, ##__VA_ARGS__)
>> -
>> -#define pr_info(fmt, ...)                                                    \
>> -     print_on_level(LOG_INFO,                                                \
>> -                    LOG_PREFIX fmt, ##__VA_ARGS__)
>> -
>> -#define pr_err(fmt, ...)                                                     \
>> -     print_on_level(LOG_ERROR,                                               \
>> -                    "Error (%s:%d): " LOG_PREFIX fmt,                        \
>> -                    __FILE__, __LINE__, ##__VA_ARGS__)
>> -
>> -#define pr_err_once(fmt, ...)                                                        \
>> -     do {                                                                    \
>> -             static bool __printed;                                          \
>> -             if (!__printed) {                                               \
>> -                     pr_err(fmt, ##__VA_ARGS__);                             \
>> -                     __printed = 1;                                          \
>> -             }                                                               \
>> -     } while (0)
>> -
>> -#define pr_warn(fmt, ...)                                                    \
>> -     print_on_level(LOG_WARN,                                                \
>> -                    "Warn  (%s:%d): " LOG_PREFIX fmt,                        \
>> -                    __FILE__, __LINE__, ##__VA_ARGS__)
>> -
>> -#define pr_debug(fmt, ...)                                                   \
>> -     print_on_level(LOG_DEBUG,                                               \
>> -                    LOG_PREFIX fmt, ##__VA_ARGS__)
>> -
>> -#define pr_perror(fmt, ...)                                                  \
>> -     pr_err(fmt ": %m\n", ##__VA_ARGS__)
>> -
>>  #define DEFAULT_LOG_FILENAME "criu.log"
>>
>>  extern void print_data(unsigned long addr, unsigned char *data, size_t size);
>> diff --git a/pie/log-simple.c b/pie/log-simple.c
>> index 701740d..6a9c6ae 100644
>> --- a/pie/log-simple.c
>> +++ b/pie/log-simple.c
>> @@ -4,7 +4,6 @@
>>
>>  #include "syscall.h"
>>  #include "log.h"
>> -#include "log-levels.h"
>>
>>  #define LOG_SIMPLE_CHUNK     72
>>
>>
>
>


More information about the CRIU mailing list