2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 14:25:49 +00:00

dump: Factor out img header dumping

Move common code for tasks and threads dumping into routine. It will be
used for zombies as well.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
Pavel Emelyanov
2012-01-22 20:21:35 +04:00
committed by Cyrill Gorcunov
parent 164ccc095f
commit dd495ba18a

View File

@@ -560,11 +560,29 @@ err:
return ret;
}
static int dump_task_core(struct core_entry *core, struct cr_fdset *fdset)
{
int fd_core = fdset->fds[CR_FD_CORE];
int ret;
lseek(fd_core, MAGIC_OFFSET, SEEK_SET);
pr_info("Dumping header ... ");
core->header.version = HEADER_VERSION;
core->header.arch = HEADER_ARCH_X86_64;
core->header.flags = 0;
ret = write_img(fd_core, core);
free(core);
return ret;
}
static int dump_task_core_seized(pid_t pid, int pid_dir, struct proc_pid_stat *stat,
struct cr_fdset *cr_fdset)
{
struct core_entry *core = xzalloc(sizeof(*core));
int fd_core = cr_fdset->fds[CR_FD_CORE];
int ret = -1;
unsigned long brk;
@@ -575,8 +593,6 @@ static int dump_task_core_seized(pid_t pid, int pid_dir, struct proc_pid_stat *s
if (!core)
goto err;
lseek(fd_core, MAGIC_OFFSET, SEEK_SET);
pr_info("Dumping GP/FPU registers ... ");
ret = get_task_regs(pid, core);
if (ret)
@@ -610,16 +626,7 @@ static int dump_task_core_seized(pid_t pid, int pid_dir, struct proc_pid_stat *s
core->tc.mm_brk = brk;
pr_info("OK\n");
pr_info("Dumping header ... ");
core->header.version = HEADER_VERSION;
core->header.arch = HEADER_ARCH_X86_64;
core->header.flags = 0;
if (write_img(fd_core, core))
goto err_free;
pr_info("OK\n");
ret = 0;
return dump_task_core(core, cr_fdset);
err_free:
free(core);
@@ -981,7 +988,6 @@ err_strno:
static int dump_task_thread(pid_t pid, struct cr_fdset *cr_fdset)
{
struct core_entry *core = xzalloc(sizeof(*core));
int fd_core = cr_fdset->fds[CR_FD_CORE];
int ret = -1;
pr_info("\n");
@@ -991,8 +997,6 @@ static int dump_task_thread(pid_t pid, struct cr_fdset *cr_fdset)
if (!core)
goto err;
lseek(fd_core, MAGIC_OFFSET, SEEK_SET);
ret = seize_task(pid);
if (ret) {
pr_err("Failed to seize thread (pid: %d) with %d\n",
@@ -1012,16 +1016,7 @@ static int dump_task_thread(pid_t pid, struct cr_fdset *cr_fdset)
goto err_free;
}
pr_info("Dumping header ... ");
core->header.version = HEADER_VERSION;
core->header.arch = HEADER_ARCH_X86_64;
core->header.flags = 0;
if (write_img(fd_core, core))
goto err_free;
pr_info("OK\n");
ret = 0;
return dump_task_core(core, cr_fdset);
err_free:
free(core);