mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-30 05:21:57 +00:00
When "make test" is executed, CFLAGS is exported from the root Makefile.
These flags define _GNU_SOURCE, so we don't need to define it in the
souce file.
In addition unistd.h isn't included, so a few functions are shown as undeclared.
make zdtm_ns
make[3]: Entering directory `/root/criu/test'
gcc -O2 -Wall -Werror -DCONFIG_X86_64 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE zdtm_ct.c -o zdtm_ct
zdtm_ct.c:1:0: error: "_GNU_SOURCE" redefined [-Werror]
#define _GNU_SOURCE
^
<command-line>:0:0: note: this is the location of the previous definition
zdtm_ct.c: In function ‘main’:
zdtm_ct.c:21:2: error: implicit declaration of function ‘fork’ [-Werror=implicit-function-declaration]
pid = fork();
^
zdtm_ct.c:23:3: error: implicit declaration of function ‘setsid’ [-Werror=implicit-function-declaration]
if (setsid() == -1) {
^
zdtm_ct.c:49:3: error: implicit declaration of function ‘execv’ [-Werror=implicit-function-declaration]
execv(argv[1], argv + 1);
^
zdtm_ct.c:62:3: error: implicit declaration of function ‘getpid’ [-Werror=implicit-function-declaration]
kill(getpid(), WTERMSIG(status));
^
cc1: all warnings being treated as errors
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Tested-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
67 lines
1.5 KiB
C
67 lines
1.5 KiB
C
#include <sched.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <sys/mount.h>
|
|
#include <unistd.h>
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
pid_t pid;
|
|
int status;
|
|
|
|
/*
|
|
*pidns is used to avoid conflicts
|
|
* mntns is used to mount /proc
|
|
* net is used to avoid conflicts of parasite sockets
|
|
*/
|
|
if (unshare(CLONE_NEWNS | CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC))
|
|
return 1;
|
|
pid = fork();
|
|
if (pid == 0) {
|
|
if (setsid() == -1) {
|
|
fprintf(stderr, "setsid: %m\n");
|
|
return 1;
|
|
}
|
|
|
|
if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
|
|
fprintf(stderr, "mount(/, S_REC | MS_PRIVATE)): %m");
|
|
return 1;
|
|
}
|
|
umount2("/proc", MNT_DETACH);
|
|
umount2("/dev/pts", MNT_DETACH);
|
|
if (mount("zdtm_proc", "/proc", "proc", 0, NULL)) {
|
|
fprintf(stderr, "mount(/proc): %m");
|
|
return 1;
|
|
}
|
|
if (mount("zdtm_devpts", "/dev/pts", "devpts", 0,
|
|
"newinstance,ptmxmode=0666")) {
|
|
fprintf(stderr, "mount(pts): %m");
|
|
return 1;
|
|
}
|
|
if (mount("/dev/pts/ptmx", "/dev/ptmx", NULL, MS_BIND, NULL)) {
|
|
fprintf(stderr, "mount(ptmx): %m");
|
|
return 1;
|
|
}
|
|
if (system("ip link set up dev lo"))
|
|
return 1;
|
|
execv(argv[1], argv + 1);
|
|
fprintf(stderr, "execve: %m");
|
|
return 1;
|
|
}
|
|
|
|
if (waitpid(pid, &status, 0) != pid) {
|
|
fprintf(stderr, "waitpid: %m");
|
|
return 1;
|
|
}
|
|
|
|
if (WIFEXITED(status))
|
|
return WEXITSTATUS(status);
|
|
else if (WIFSIGNALED(status))
|
|
kill(getpid(), WTERMSIG(status));
|
|
else
|
|
fprintf(stderr, "Unexpected exit status: %x\n", status);
|
|
|
|
return 1;
|
|
}
|