Commit 38736194 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Andrei Vagin

criu: pie,log -- Prepate to move into compel std plugin

 - Add uapi header and start using it
 - Add std_ prefix into functions and constants
 - Drop unneeded headers

travis-ci: success for compel: The final infect move and install target
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent b46e5ec1
#ifndef COMPEL_PLUGIN_STD_LOG_H__
#define COMPEL_PLUGIN_STD_LOG_H__
#define STD_LOG_SIMPLE_CHUNK 79
extern void std_log_set_fd(int fd);
extern void std_log_set_loglevel(unsigned int level);
extern int std_vprint_num(char *buf, int blen, int num, char **ps);
extern void std_sprintf(char output[STD_LOG_SIMPLE_CHUNK], const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
extern void print_on_level(unsigned int loglevel, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
#endif /* COMPEL_PLUGIN_STD_LOG_H__ */
...@@ -72,15 +72,6 @@ extern void print_on_level(unsigned int loglevel, const char *format, ...) ...@@ -72,15 +72,6 @@ extern void print_on_level(unsigned int loglevel, const char *format, ...)
#define pr_perror(fmt, ...) \ #define pr_perror(fmt, ...) \
pr_err(fmt ": %s\n", ##__VA_ARGS__, strerror(errno)) pr_err(fmt ": %s\n", ##__VA_ARGS__, strerror(errno))
#else
#define LOG_SIMPLE_CHUNK 79
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)));
#endif /* CR_NOGLIBC */ #endif /* CR_NOGLIBC */
#endif /* __CR_LOG_H__ */ #endif /* __CR_LOG_H__ */
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "int.h" #include "int.h"
#include "util-pie.h" #include "util-pie.h"
#include <compel/plugins/std/log.h>
#include "criu-log.h" #include "criu-log.h"
#include "common/bug.h" #include "common/bug.h"
#include "sigframe.h" #include "sigframe.h"
...@@ -79,7 +80,7 @@ static int fini(void) ...@@ -79,7 +80,7 @@ static int fini(void)
new_sp, RT_SIGFRAME_REGIP(sigframe)); new_sp, RT_SIGFRAME_REGIP(sigframe));
sys_close(tsock); sys_close(tsock);
log_set_fd(-1); std_log_set_fd(-1);
fini_sigreturn(new_sp); fini_sigreturn(new_sp);
...@@ -168,8 +169,8 @@ static noinline __used int parasite_init_daemon(void *data) ...@@ -168,8 +169,8 @@ static noinline __used int parasite_init_daemon(void *data)
ret = recv_fd(tsock); ret = recv_fd(tsock);
if (ret >= 0) { if (ret >= 0) {
log_set_fd(ret); std_log_set_fd(ret);
log_set_loglevel(args->log_level); std_log_set_loglevel(args->log_level);
ret = 0; ret = 0;
} else } else
goto err; goto err;
......
#include <stdarg.h> #include <stdarg.h>
#include "int.h"
#include "types.h"
#include "string.h" #include "string.h"
#include "common/bitsperlong.h" #include "common/bitsperlong.h"
#include <compel/plugins/std/syscall.h> #include <compel/plugins/std/syscall.h>
#include "log.h" #include <compel/plugins/std/log.h>
#include <compel/loglevels.h>
struct simple_buf { struct simple_buf {
char buf[LOG_SIMPLE_CHUNK]; char buf[STD_LOG_SIMPLE_CHUNK];
char *bp; char *bp;
int prefix_len; int prefix_len;
void (*flush)(struct simple_buf *b); void (*flush)(struct simple_buf *b);
...@@ -59,7 +58,7 @@ static void sbuf_log_init(struct simple_buf *b) ...@@ -59,7 +58,7 @@ static void sbuf_log_init(struct simple_buf *b)
timediff(&start, &now); timediff(&start, &now);
/* Seconds */ /* Seconds */
n = vprint_num(pbuf, sizeof(pbuf), (unsigned)now.tv_sec, &s); n = std_vprint_num(pbuf, sizeof(pbuf), (unsigned)now.tv_sec, &s);
pad_num(&s, &n, 2); pad_num(&s, &n, 2);
b->bp[0] = '('; b->bp[0] = '(';
memcpy(b->bp + 1, s, n); memcpy(b->bp + 1, s, n);
...@@ -67,14 +66,14 @@ static void sbuf_log_init(struct simple_buf *b) ...@@ -67,14 +66,14 @@ static void sbuf_log_init(struct simple_buf *b)
b->bp += n + 2; b->bp += n + 2;
/* Mu-seconds */ /* Mu-seconds */
n = vprint_num(pbuf, sizeof(pbuf), (unsigned)now.tv_usec, &s); n = std_vprint_num(pbuf, sizeof(pbuf), (unsigned)now.tv_usec, &s);
pad_num(&s, &n, 6); pad_num(&s, &n, 6);
memcpy(b->bp, s, n); memcpy(b->bp, s, n);
b->bp[n] = ')'; b->bp[n] = ')';
b->bp += n + 1; b->bp += n + 1;
} }
n = vprint_num(pbuf, sizeof(pbuf), sys_gettid(), &s); n = std_vprint_num(pbuf, sizeof(pbuf), sys_gettid(), &s);
b->bp[0] = 'p'; b->bp[0] = 'p';
b->bp[1] = 'i'; b->bp[1] = 'i';
b->bp[2] = 'e'; b->bp[2] = 'e';
...@@ -100,12 +99,12 @@ static void sbuf_log_flush(struct simple_buf *b) ...@@ -100,12 +99,12 @@ static void sbuf_log_flush(struct simple_buf *b)
static void sbuf_putc(struct simple_buf *b, char c) static void sbuf_putc(struct simple_buf *b, char c)
{ {
/* TODO: maybe some warning or error here? */ /* TODO: maybe some warning or error here? */
if (b->bp - b->buf >= LOG_SIMPLE_CHUNK) if (b->bp - b->buf >= STD_LOG_SIMPLE_CHUNK)
return; return;
*b->bp = c; *b->bp = c;
b->bp++; b->bp++;
if (b->bp - b->buf >= LOG_SIMPLE_CHUNK - 2) { if (b->bp - b->buf >= STD_LOG_SIMPLE_CHUNK - 2) {
b->bp[0] = '>'; b->bp[0] = '>';
b->bp[1] = '\n'; b->bp[1] = '\n';
b->bp += 2; b->bp += 2;
...@@ -114,13 +113,13 @@ static void sbuf_putc(struct simple_buf *b, char c) ...@@ -114,13 +113,13 @@ static void sbuf_putc(struct simple_buf *b, char c)
} }
} }
void log_set_fd(int fd) void std_log_set_fd(int fd)
{ {
sys_close(logfd); sys_close(logfd);
logfd = fd; logfd = fd;
} }
void log_set_loglevel(unsigned int level) void std_log_set_loglevel(unsigned int level)
{ {
cur_loglevel = level; cur_loglevel = level;
} }
...@@ -138,7 +137,7 @@ static void print_string(const char *msg, struct simple_buf *b) ...@@ -138,7 +137,7 @@ static void print_string(const char *msg, struct simple_buf *b)
} }
} }
int vprint_num(char *buf, int blen, int num, char **ps) int std_vprint_num(char *buf, int blen, int num, char **ps)
{ {
int neg = 0; int neg = 0;
char *s; char *s;
...@@ -175,7 +174,7 @@ static void print_num(int num, struct simple_buf *b) ...@@ -175,7 +174,7 @@ static void print_num(int num, struct simple_buf *b)
char buf[12], *s; char buf[12], *s;
buf[11] = '\0'; buf[11] = '\0';
vprint_num(buf, sizeof(buf) - 1, num, &s); std_vprint_num(buf, sizeof(buf) - 1, num, &s);
print_string(s, b); print_string(s, b);
} }
...@@ -341,7 +340,7 @@ void print_on_level(unsigned int loglevel, const char *format, ...) ...@@ -341,7 +340,7 @@ void print_on_level(unsigned int loglevel, const char *format, ...)
sbuf_log_flush(&b); sbuf_log_flush(&b);
} }
void simple_sprintf(char output[LOG_SIMPLE_CHUNK], const char *format, ...) void std_sprintf(char output[STD_LOG_SIMPLE_CHUNK], const char *format, ...)
{ {
va_list args; va_list args;
struct simple_buf b; struct simple_buf b;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "common/compiler.h" #include "common/compiler.h"
#include "string.h" #include "string.h"
#include <compel/plugins/std/syscall.h> #include <compel/plugins/std/syscall.h>
#include <compel/plugins/std/log.h>
#include <compel/ksigset.h> #include <compel/ksigset.h>
#include "signal.h" #include "signal.h"
#include "config.h" #include "config.h"
...@@ -103,14 +104,14 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data) ...@@ -103,14 +104,14 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
static int lsm_set_label(char *label, int procfd) static int lsm_set_label(char *label, int procfd)
{ {
int ret = -1, len, lsmfd; int ret = -1, len, lsmfd;
char path[LOG_SIMPLE_CHUNK]; char path[STD_LOG_SIMPLE_CHUNK];
if (!label) if (!label)
return 0; return 0;
pr_info("restoring lsm profile %s\n", label); pr_info("restoring lsm profile %s\n", label);
simple_sprintf(path, "self/task/%ld/attr/current", sys_gettid()); std_sprintf(path, "self/task/%ld/attr/current", sys_gettid());
lsmfd = sys_openat(procfd, path, O_WRONLY, 0); lsmfd = sys_openat(procfd, path, O_WRONLY, 0);
if (lsmfd < 0) { if (lsmfd < 0) {
...@@ -1087,9 +1088,9 @@ long __export_restore_task(struct task_restore_args *args) ...@@ -1087,9 +1088,9 @@ long __export_restore_task(struct task_restore_args *args)
ksigaddset(&to_block, SIGCHLD); ksigaddset(&to_block, SIGCHLD);
ret = sys_sigprocmask(SIG_UNBLOCK, &to_block, NULL, sizeof(k_rtsigset_t)); ret = sys_sigprocmask(SIG_UNBLOCK, &to_block, NULL, sizeof(k_rtsigset_t));
log_set_fd(args->logfd); std_log_set_fd(args->logfd);
log_set_loglevel(args->loglevel); std_log_set_loglevel(args->loglevel);
log_set_start(&args->logstart); std_log_set_start(&args->logstart);
pr_info("Switched to the restorer %d\n", my_pid); pr_info("Switched to the restorer %d\n", my_pid);
...@@ -1357,7 +1358,7 @@ long __export_restore_task(struct task_restore_args *args) ...@@ -1357,7 +1358,7 @@ long __export_restore_task(struct task_restore_args *args)
continue; continue;
new_sp = restorer_stack(thread_args[i].mz); new_sp = restorer_stack(thread_args[i].mz);
last_pid_len = vprint_num(last_pid_buf, sizeof(last_pid_buf), thread_args[i].pid - 1, &s); last_pid_len = std_vprint_num(last_pid_buf, sizeof(last_pid_buf), thread_args[i].pid - 1, &s);
sys_lseek(fd, 0, SEEK_SET); sys_lseek(fd, 0, SEEK_SET);
ret = sys_write(fd, s, last_pid_len); ret = sys_write(fd, s, last_pid_len);
if (ret < 0) { if (ret < 0) {
...@@ -1470,7 +1471,7 @@ long __export_restore_task(struct task_restore_args *args) ...@@ -1470,7 +1471,7 @@ long __export_restore_task(struct task_restore_args *args)
futex_wait_while_gt(&thread_inprogress, 1); futex_wait_while_gt(&thread_inprogress, 1);
sys_close(args->proc_fd); sys_close(args->proc_fd);
log_set_fd(-1); std_log_set_fd(-1);
/* /*
* The code that prepared the itimers makes shure the * The code that prepared the itimers makes shure the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment