mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
restorer: move log descriptor from crtools (v2)
v2: add FIXME for linking restorer-log.c and restorer.c by ld I don't know how to do it now. Signed-off-by: Andrey Vagin <avagin@openvz.org> Acked-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
@@ -1530,6 +1530,7 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
|
||||
task_args->pid = pid;
|
||||
task_args->fd_core = fd_core;
|
||||
task_args->fd_self_vmas = fd_self_vmas;
|
||||
task_args->logfd = get_logfd();
|
||||
|
||||
cr_mutex_init(&task_args->rst_lock);
|
||||
|
||||
@@ -1586,7 +1587,6 @@ static void sigreturn_restore(pid_t pstree_pid, pid_t pid)
|
||||
task_args->thread_args);
|
||||
|
||||
close_safe(&fd_pstree);
|
||||
fini_log();
|
||||
|
||||
/*
|
||||
* An indirect call to task_restore, note it never resturns
|
||||
|
11
include/restorer-log.h
Normal file
11
include/restorer-log.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef RESTORER_LOG_H__
|
||||
#define RESTORER_LOG_H__
|
||||
extern long vprint_num(char *buf, long num);
|
||||
|
||||
extern void write_hex_n(unsigned long num);
|
||||
extern void write_num_n(long num);
|
||||
extern void write_num(long num);
|
||||
extern void write_string_n(char *str);
|
||||
extern void write_string(char *str);
|
||||
extern void set_logfd(int fd);
|
||||
#endif
|
@@ -67,6 +67,7 @@ struct task_restore_core_args {
|
||||
int fd_core; /* opened core file */
|
||||
int fd_self_vmas; /* opened file with running VMAs to unmap */
|
||||
char ns_last_pid_path[sizeof(LAST_PID_PATH) + 1];
|
||||
int logfd;
|
||||
bool restore_threads; /* if to restore threads */
|
||||
u32 rst_lock;
|
||||
|
||||
@@ -173,118 +174,6 @@ struct rt_sigframe {
|
||||
/* fp state follows here */
|
||||
};
|
||||
|
||||
#define add_ord(c) \
|
||||
do { \
|
||||
if (c < 10) \
|
||||
c += '0'; \
|
||||
else \
|
||||
c += 'a' - 10; \
|
||||
} while (0)
|
||||
|
||||
static void always_inline write_char(char c)
|
||||
{
|
||||
sys_write(STDERR_FILENO, &c, 1);
|
||||
}
|
||||
|
||||
static void always_inline write_string(char *str)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
while (str[len])
|
||||
len++;
|
||||
|
||||
sys_write(STDERR_FILENO, str, len);
|
||||
}
|
||||
|
||||
static void always_inline write_string_n(char *str)
|
||||
{
|
||||
char new_line = '\n';
|
||||
|
||||
write_string(str);
|
||||
sys_write(STDERR_FILENO, &new_line, 1);
|
||||
}
|
||||
|
||||
static void always_inline write_num_n(long num)
|
||||
{
|
||||
unsigned long d = 1000000000000000000;
|
||||
unsigned int started = 0;
|
||||
unsigned int minus = 0;
|
||||
unsigned int c;
|
||||
|
||||
if (num < 0) {
|
||||
num = -num;
|
||||
c = '-';
|
||||
sys_write(STDERR_FILENO, &c, 1);
|
||||
}
|
||||
|
||||
while (d) {
|
||||
c = num / d;
|
||||
num -= d * c;
|
||||
d /= 10;
|
||||
if (!c && !started)
|
||||
continue;
|
||||
if (!started)
|
||||
started = 1;
|
||||
add_ord(c);
|
||||
sys_write(STDERR_FILENO, &c, 1);
|
||||
|
||||
}
|
||||
c = '\n';
|
||||
sys_write(STDERR_FILENO, &c, 1);
|
||||
}
|
||||
|
||||
static long always_inline vprint_num(char *buf, long num)
|
||||
{
|
||||
unsigned long d = 1000000000000000000;
|
||||
unsigned int started = 0;
|
||||
unsigned int minus = 0;
|
||||
unsigned int i = 0;
|
||||
unsigned int c;
|
||||
|
||||
if (num < 0) {
|
||||
num = -num;
|
||||
buf[i++] = '-';
|
||||
}
|
||||
|
||||
while (d) {
|
||||
c = num / d;
|
||||
num -= d * c;
|
||||
d /= 10;
|
||||
if (!c && !started)
|
||||
continue;
|
||||
if (!started)
|
||||
started = 1;
|
||||
add_ord(c);
|
||||
buf[i++] = c;
|
||||
|
||||
}
|
||||
|
||||
buf[i++] = 0;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static void always_inline write_hex_n(unsigned long num)
|
||||
{
|
||||
unsigned char *s = (unsigned char *)#
|
||||
unsigned char c;
|
||||
int i;
|
||||
|
||||
c = 'x';
|
||||
sys_write(STDERR_FILENO, &c, 1);
|
||||
for (i = sizeof(long)/sizeof(char) - 1; i >= 0; i--) {
|
||||
c = (s[i] & 0xf0) >> 4;
|
||||
add_ord(c);
|
||||
sys_write(STDERR_FILENO, &c, 1);
|
||||
|
||||
c = (s[i] & 0x0f);
|
||||
add_ord(c);
|
||||
sys_write(STDERR_FILENO, &c, 1);
|
||||
}
|
||||
|
||||
c = '\n';
|
||||
sys_write(STDERR_FILENO, &c, 1);
|
||||
}
|
||||
|
||||
#define SHMEMS_SIZE 4096
|
||||
|
||||
|
128
restorer-log.c
Normal file
128
restorer-log.c
Normal file
@@ -0,0 +1,128 @@
|
||||
#include "restorer-log.h"
|
||||
#include "syscall.h"
|
||||
|
||||
static int logfd;
|
||||
|
||||
void set_logfd(int fd)
|
||||
{
|
||||
logfd = fd;
|
||||
}
|
||||
|
||||
#define add_ord(c) \
|
||||
do { \
|
||||
if (c < 10) \
|
||||
c += '0'; \
|
||||
else \
|
||||
c += 'a' - 10; \
|
||||
} while (0)
|
||||
|
||||
static void always_inline write_char(char c)
|
||||
{
|
||||
sys_write(logfd, &c, 1);
|
||||
}
|
||||
|
||||
void always_inline write_string(char *str)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
while (str[len])
|
||||
len++;
|
||||
|
||||
sys_write(logfd, str, len);
|
||||
}
|
||||
|
||||
void always_inline write_string_n(char *str)
|
||||
{
|
||||
char new_line = '\n';
|
||||
|
||||
write_string(str);
|
||||
sys_write(logfd, &new_line, 1);
|
||||
}
|
||||
|
||||
void always_inline write_num(long num)
|
||||
{
|
||||
unsigned long d = 1000000000000000000;
|
||||
unsigned int started = 0;
|
||||
unsigned int minus = 0;
|
||||
unsigned int c;
|
||||
|
||||
if (num < 0) {
|
||||
num = -num;
|
||||
c = '-';
|
||||
sys_write(logfd, &c, 1);
|
||||
}
|
||||
|
||||
while (d) {
|
||||
c = num / d;
|
||||
num -= d * c;
|
||||
d /= 10;
|
||||
if (!c && !started)
|
||||
continue;
|
||||
if (!started)
|
||||
started = 1;
|
||||
add_ord(c);
|
||||
sys_write(logfd, &c, 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void always_inline write_num_n(long num)
|
||||
{
|
||||
unsigned char c;
|
||||
write_num(num);
|
||||
c = '\n';
|
||||
sys_write(logfd, &c, sizeof(c));
|
||||
}
|
||||
|
||||
long always_inline vprint_num(char *buf, long num)
|
||||
{
|
||||
unsigned long d = 1000000000000000000;
|
||||
unsigned int started = 0;
|
||||
unsigned int minus = 0;
|
||||
unsigned int i = 0;
|
||||
unsigned int c;
|
||||
|
||||
if (num < 0) {
|
||||
num = -num;
|
||||
buf[i++] = '-';
|
||||
}
|
||||
|
||||
while (d) {
|
||||
c = num / d;
|
||||
num -= d * c;
|
||||
d /= 10;
|
||||
if (!c && !started)
|
||||
continue;
|
||||
if (!started)
|
||||
started = 1;
|
||||
add_ord(c);
|
||||
buf[i++] = c;
|
||||
|
||||
}
|
||||
|
||||
buf[i++] = 0;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void always_inline write_hex_n(unsigned long num)
|
||||
{
|
||||
unsigned char *s = (unsigned char *)#
|
||||
unsigned char c;
|
||||
int i;
|
||||
|
||||
c = 'x';
|
||||
sys_write(logfd, &c, 1);
|
||||
for (i = sizeof(long)/sizeof(char) - 1; i >= 0; i--) {
|
||||
c = (s[i] & 0xf0) >> 4;
|
||||
add_ord(c);
|
||||
sys_write(logfd, &c, 1);
|
||||
|
||||
c = (s[i] & 0x0f);
|
||||
add_ord(c);
|
||||
sys_write(logfd, &c, 1);
|
||||
}
|
||||
|
||||
c = '\n';
|
||||
sys_write(logfd, &c, 1);
|
||||
}
|
@@ -16,6 +16,7 @@
|
||||
#include "image.h"
|
||||
|
||||
#include "crtools.h"
|
||||
#include "restorer-log.h"
|
||||
#include "lock.h"
|
||||
#include "restorer.h"
|
||||
|
||||
@@ -131,6 +132,8 @@ long restore_task(struct task_restore_core_args *args)
|
||||
unsigned long new_sp, fsgs_base;
|
||||
pid_t my_pid = sys_getpid();
|
||||
|
||||
set_logfd(args->logfd);
|
||||
|
||||
core_entry = first_on_heap(core_entry, args->mem_zone.heap);
|
||||
vma_entry = next_on_heap(vma_entry, core_entry);
|
||||
|
||||
@@ -514,6 +517,8 @@ long restore_task(struct task_restore_core_args *args)
|
||||
goto core_restore_end;
|
||||
}
|
||||
|
||||
sys_close(args->logfd);
|
||||
|
||||
/*
|
||||
* Sigframe stack.
|
||||
*/
|
||||
@@ -540,3 +545,6 @@ core_restore_end:
|
||||
local_sleep(5);
|
||||
sys_exit(0);
|
||||
}
|
||||
|
||||
/* FIXME Need link this .o with ld */
|
||||
#include "restorer-log.c"
|
||||
|
Reference in New Issue
Block a user