mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 07:45:17 +00:00
Move seize related functions into seize.[ch]
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
1
Makefile
1
Makefile
@@ -66,6 +66,7 @@ OBJS += cr-show.o
|
|||||||
OBJS += util.o
|
OBJS += util.o
|
||||||
OBJS += rbtree.o
|
OBJS += rbtree.o
|
||||||
OBJS += elf.o
|
OBJS += elf.o
|
||||||
|
OBJS += seize.o
|
||||||
|
|
||||||
DEPS := $(patsubst %.o,%.d,$(OBJS))
|
DEPS := $(patsubst %.o,%.d,$(OBJS))
|
||||||
|
|
||||||
|
9
include/seize.h
Normal file
9
include/seize.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef SEIZE_H_
|
||||||
|
#define SEIZE_H_
|
||||||
|
|
||||||
|
#include <sys/ptrace.h>
|
||||||
|
|
||||||
|
int seize_task(pid_t pid);
|
||||||
|
int unseize_task(pid_t pid);
|
||||||
|
|
||||||
|
#endif /* SEIZE_H_ */
|
88
seize.c
Normal file
88
seize.c
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/ptrace.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <sys/vfs.h>
|
||||||
|
#include <sys/ptrace.h>
|
||||||
|
#include <sys/user.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
#include "types.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "seize.h"
|
||||||
|
|
||||||
|
#include "crtools.h"
|
||||||
|
|
||||||
|
int unseize_task(pid_t pid)
|
||||||
|
{
|
||||||
|
return ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This routine seizes task putting it into a special
|
||||||
|
* state where we can manipulate the task via ptrace
|
||||||
|
* inteface, and finally we can detach ptrace out of
|
||||||
|
* of it so the task would not know if it was saddled
|
||||||
|
* up with someone else.
|
||||||
|
*/
|
||||||
|
int seize_task(pid_t pid)
|
||||||
|
{
|
||||||
|
siginfo_t si;
|
||||||
|
int status;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
jerr_rc(ptrace(PTRACE_SEIZE, pid, NULL,
|
||||||
|
(void *)(unsigned long)PTRACE_SEIZE_DEVEL), ret, err);
|
||||||
|
jerr_rc(ptrace(PTRACE_INTERRUPT, pid, NULL, NULL), ret, err);
|
||||||
|
|
||||||
|
ret = -10;
|
||||||
|
if (wait4(pid, &status, __WALL, NULL) != pid)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
ret = -20;
|
||||||
|
if (!WIFSTOPPED(status))
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
jerr_rc(ptrace(PTRACE_GETSIGINFO, pid, NULL, &si), ret, err_cont);
|
||||||
|
|
||||||
|
ret = -30;
|
||||||
|
if ((si.si_code >> 8) != PTRACE_EVENT_STOP)
|
||||||
|
goto err_cont;
|
||||||
|
|
||||||
|
jerr_rc(ptrace(PTRACE_SETOPTIONS, pid, NULL,
|
||||||
|
(void *)(unsigned long)PTRACE_O_TRACEEXIT), ret, err_cont);
|
||||||
|
|
||||||
|
err:
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
err_cont:
|
||||||
|
continue_task(pid);
|
||||||
|
goto err;
|
||||||
|
}
|
47
util.c
47
util.c
@@ -187,53 +187,6 @@ void printk_vma(struct vma_area *vma_area)
|
|||||||
((vma_area->vma.status & VMA_AREA_VDSO) ? "vdso" : "n")))));
|
((vma_area->vma.status & VMA_AREA_VDSO) ? "vdso" : "n")))));
|
||||||
}
|
}
|
||||||
|
|
||||||
int unseize_task(pid_t pid)
|
|
||||||
{
|
|
||||||
return ptrace(PTRACE_DETACH, pid, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This routine seizes task putting it into a special
|
|
||||||
* state where we can manipulate the task via ptrace
|
|
||||||
* inteface, and finally we can detach ptrace out of
|
|
||||||
* of it so the task would not know if it was saddled
|
|
||||||
* up with someone else.
|
|
||||||
*/
|
|
||||||
int seize_task(pid_t pid)
|
|
||||||
{
|
|
||||||
siginfo_t si;
|
|
||||||
int status;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
jerr_rc(ptrace(PTRACE_SEIZE, pid, NULL,
|
|
||||||
(void *)(unsigned long)PTRACE_SEIZE_DEVEL), ret, err);
|
|
||||||
jerr_rc(ptrace(PTRACE_INTERRUPT, pid, NULL, NULL), ret, err);
|
|
||||||
|
|
||||||
ret = -10;
|
|
||||||
if (wait4(pid, &status, __WALL, NULL) != pid)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
ret = -20;
|
|
||||||
if (!WIFSTOPPED(status))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
jerr_rc(ptrace(PTRACE_GETSIGINFO, pid, NULL, &si), ret, err_cont);
|
|
||||||
|
|
||||||
ret = -30;
|
|
||||||
if ((si.si_code >> 8) != PTRACE_EVENT_STOP)
|
|
||||||
goto err_cont;
|
|
||||||
|
|
||||||
jerr_rc(ptrace(PTRACE_SETOPTIONS, pid, NULL,
|
|
||||||
(void *)(unsigned long)PTRACE_O_TRACEEXIT), ret, err_cont);
|
|
||||||
|
|
||||||
err:
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
err_cont:
|
|
||||||
continue_task(pid);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int close_safe(int *fd)
|
int close_safe(int *fd)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
Reference in New Issue
Block a user