From patchwork Fri Oct 21 12:50:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [4/9] log: Swap contents of criu-log and log headers From: Pavel Emelyanov X-Patchwork-Id: 2112 Message-Id: <580A0F1D.5060001@virtuozzo.com> To: CRIU Date: Fri, 21 Oct 2016 15:50:37 +0300 The former one (criu-log.h) is now for service functions like logfile management, pidfile and alike. It's only needed by files that set up logging and for users that want specific functions like log_get_fd or pr_quelled. The latter (log.h) is purely for those who need pr_xxx helpers only. Signed-off-by: Pavel Emelyanov --- criu/cgroup.c | 1 + criu/cr-restore.c | 2 +- criu/cr-service.c | 2 +- criu/crtools.c | 1 + criu/fsnotify.c | 2 +- criu/include/criu-log.h | 78 ++++++++++------------------------------------ criu/include/log.h | 82 ++++++++++++++++++++++++++++++++++++++----------- criu/page-pipe.c | 1 + criu/parasite-syscall.c | 1 + criu/pie/parasite.c | 2 +- criu/pie/restorer.c | 2 +- criu/seize.c | 1 + criu/util.c | 2 +- 13 files changed, 92 insertions(+), 85 deletions(-) diff --git a/criu/cgroup.c b/criu/cgroup.c index f543627..caa8033 100644 --- a/criu/cgroup.c +++ b/criu/cgroup.c @@ -13,6 +13,7 @@ #include "cgroup-props.h" #include "cr_options.h" #include "pstree.h" +#include "criu-log.h" #include "util.h" #include "imgset.h" #include "util-pie.h" diff --git a/criu/cr-restore.c b/criu/cr-restore.c index d4bacc4..9629c7b 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -32,7 +32,7 @@ #include "image.h" #include "util.h" #include "util-pie.h" -#include "log.h" +#include "criu-log.h" #include "restorer.h" #include "sockets.h" #include "sk-packet.h" diff --git a/criu/cr-service.c b/criu/cr-service.c index 3030caa..adfffa0 100644 --- a/criu/cr-service.c +++ b/criu/cr-service.c @@ -20,7 +20,7 @@ #include "cr_options.h" #include "external.h" #include "util.h" -#include "log.h" +#include "criu-log.h" #include "cpu.h" #include "files.h" #include "pstree.h" diff --git a/criu/crtools.c b/criu/crtools.c index c1688f8..6d588f5 100644 --- a/criu/crtools.c +++ b/criu/crtools.c @@ -36,6 +36,7 @@ #include "file-lock.h" #include "cr-service.h" #include "plugin.h" +#include "criu-log.h" #include "mount.h" #include "filesystems.h" #include "namespaces.h" diff --git a/criu/fsnotify.c b/criu/fsnotify.c index c8ea0e5..04e3ccf 100644 --- a/criu/fsnotify.c +++ b/criu/fsnotify.c @@ -33,7 +33,7 @@ #include "files.h" #include "files-reg.h" #include "file-ids.h" -#include "log.h" +#include "criu-log.h" #include "common/list.h" #include "lock.h" #include "irmap.h" diff --git a/criu/include/criu-log.h b/criu/include/criu-log.h index 3f16d01..d20e50d 100644 --- a/criu/include/criu-log.h +++ b/criu/include/criu-log.h @@ -20,71 +20,27 @@ #ifndef __CRIU_LOG_H__ #define __CRIU_LOG_H__ -#ifndef CR_NOGLIBC +#include "log.h" -#include -#include +extern int log_init(const char *output); +extern void log_fini(void); +extern int log_init_by_pid(void); +extern void log_closedir(void); +extern int log_keep_err(void); +extern char *log_first_err(void); -#endif /* CR_NOGLIBC */ +extern void log_set_fd(int fd); +extern int log_get_fd(void); -#define LOG_UNSET (-1) -#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 */ +extern void log_set_loglevel(unsigned int loglevel); +extern unsigned int log_get_loglevel(void); -#define DEFAULT_LOGLEVEL LOG_WARN +extern int write_pidfile(int pid); -extern void print_on_level(unsigned int loglevel, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); - -#ifndef LOG_PREFIX -# define LOG_PREFIX -#endif - -#define print_once(loglevel, fmt, ...) \ - do { \ - static bool __printed; \ - if (!__printed) { \ - print_on_level(loglevel, fmt, ##__VA_ARGS__); \ - __printed = 1; \ - } \ - } while (0) - -#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, ...) \ - print_once(LOG_ERROR, fmt, ##__VA_ARGS__) - -#define pr_warn(fmt, ...) \ - print_on_level(LOG_WARN, \ - "Warn (%s:%d): " LOG_PREFIX fmt, \ - __FILE__, __LINE__, ##__VA_ARGS__) - -#define pr_warn_once(fmt, ...) \ - print_once(LOG_WARN, fmt, ##__VA_ARGS__) - -#define pr_debug(fmt, ...) \ - print_on_level(LOG_DEBUG, \ - LOG_PREFIX fmt, ##__VA_ARGS__) - -#ifndef CR_NOGLIBC - -#define pr_perror(fmt, ...) \ - pr_err(fmt ": %s\n", ##__VA_ARGS__, strerror(errno)) - -#endif /* CR_NOGLIBC */ +#define DEFAULT_LOG_FILENAME "criu.log" +static inline int pr_quelled(unsigned int loglevel) +{ + return log_get_loglevel() < loglevel && loglevel != LOG_MSG; +} #endif /* __CR_LOG_LEVELS_H__ */ diff --git a/criu/include/log.h b/criu/include/log.h index c93b8e7..055e8d6 100644 --- a/criu/include/log.h +++ b/criu/include/log.h @@ -3,20 +3,72 @@ #include -#include "criu-log.h" +#ifndef CR_NOGLIBC -extern int log_init(const char *output); -extern void log_fini(void); -extern int log_init_by_pid(void); -extern void log_closedir(void); -extern int log_keep_err(void); -extern char *log_first_err(void); +#include +#include -extern void log_set_fd(int fd); -extern int log_get_fd(void); +#endif /* CR_NOGLIBC */ -extern void log_set_loglevel(unsigned int loglevel); -extern unsigned int log_get_loglevel(void); +#define LOG_UNSET (-1) +#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 + +extern void print_on_level(unsigned int loglevel, const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); + +#ifndef LOG_PREFIX +# define LOG_PREFIX +#endif + +#define print_once(loglevel, fmt, ...) \ + do { \ + static bool __printed; \ + if (!__printed) { \ + print_on_level(loglevel, fmt, ##__VA_ARGS__); \ + __printed = 1; \ + } \ + } while (0) + +#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, ...) \ + print_once(LOG_ERROR, fmt, ##__VA_ARGS__) + +#define pr_warn(fmt, ...) \ + print_on_level(LOG_WARN, \ + "Warn (%s:%d): " LOG_PREFIX fmt, \ + __FILE__, __LINE__, ##__VA_ARGS__) + +#define pr_warn_once(fmt, ...) \ + print_once(LOG_WARN, fmt, ##__VA_ARGS__) + +#define pr_debug(fmt, ...) \ + print_on_level(LOG_DEBUG, \ + LOG_PREFIX fmt, ##__VA_ARGS__) + +#ifndef CR_NOGLIBC + +#define pr_perror(fmt, ...) \ + pr_err(fmt ": %s\n", ##__VA_ARGS__, strerror(errno)) + +#else #define LOG_SIMPLE_CHUNK 72 @@ -24,13 +76,7 @@ extern int vprint_num(char *buf, int blen, int num, char **ps); extern void simple_sprintf(char output[LOG_SIMPLE_CHUNK], const char *format, ...) __attribute__ ((__format__ (__printf__, 2, 3))); -extern int write_pidfile(int pid); - -#define DEFAULT_LOG_FILENAME "criu.log" +#endif /* CR_NOGLIBC */ -static inline int pr_quelled(unsigned int loglevel) -{ - return log_get_loglevel() < loglevel && loglevel != LOG_MSG; -} #endif /* __CR_LOG_H__ */ diff --git a/criu/page-pipe.c b/criu/page-pipe.c index c67e073..6675313 100644 --- a/criu/page-pipe.c +++ b/criu/page-pipe.c @@ -7,6 +7,7 @@ #include "page.h" #include "config.h" #include "util.h" +#include "criu-log.h" #include "page-pipe.h" #include "fcntl.h" diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c index 6f30580..e5b1ba3 100644 --- a/criu/parasite-syscall.c +++ b/criu/parasite-syscall.c @@ -25,6 +25,7 @@ #include "pstree.h" #include "posix-timer.h" #include "mem.h" +#include "criu-log.h" #include "vma.h" #include "proc_parse.h" #include "aio.h" diff --git a/criu/pie/parasite.c b/criu/pie/parasite.c index 5ef518d..665f62b 100644 --- a/criu/pie/parasite.c +++ b/criu/pie/parasite.c @@ -15,7 +15,7 @@ #include "prctl.h" #include "lock.h" #include "parasite-vdso.h" -#include "log.h" +#include "criu-log.h" #include "tty.h" #include "aio.h" diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c index 04e54f1..361aff2 100644 --- a/criu/pie/restorer.c +++ b/criu/pie/restorer.c @@ -25,7 +25,7 @@ #include "signal.h" #include "config.h" #include "prctl.h" -#include "log.h" +#include "criu-log.h" #include "util.h" #include "image.h" #include "sk-inet.h" diff --git a/criu/seize.c b/criu/seize.c index b1c150f..8f878e7 100644 --- a/criu/seize.c +++ b/criu/seize.c @@ -14,6 +14,7 @@ #include "cr_options.h" #include "cr-errno.h" #include "pstree.h" +#include "criu-log.h" #include "ptrace.h" #include "seize.h" #include "stats.h" diff --git a/criu/util.c b/criu/util.c index 63bf706..42a6b16 100644 --- a/criu/util.c +++ b/criu/util.c @@ -46,7 +46,7 @@ #include "vma.h" #include "mem.h" #include "namespaces.h" -#include "log.h" +#include "criu-log.h" #include "cr_options.h" #include "servicefd.h"