2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00

util: allow to run criu under strace

fork_and_ptrace_attach has to fork a child with CLONE_UNTRACED,
so that strace doesn't trace it.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
This commit is contained in:
Andrei Vagin
2023-09-28 21:26:41 +00:00
parent c9fdd355f6
commit 4c9d23d33d

View File

@@ -661,40 +661,54 @@ out:
return ret;
}
struct child_args {
int *sk_pair;
int (*child_setup)(void);
};
static int child_func(void *_args)
{
struct child_args *args = _args;
int sk, *sk_pair = args->sk_pair;
char c = 0;
sk = sk_pair[1];
close(sk_pair[0]);
if (args->child_setup && args->child_setup() != 0)
exit(1);
if (write(sk, &c, 1) != 1) {
pr_perror("write");
exit(1);
}
while (1)
sleep(1000);
exit(1);
}
pid_t fork_and_ptrace_attach(int (*child_setup)(void))
{
pid_t pid;
int sk_pair[2], sk;
char c = 0;
struct child_args cargs = {
.sk_pair = sk_pair,
.child_setup = child_setup,
};
if (socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sk_pair)) {
pr_perror("socketpair");
return -1;
}
pid = fork();
pid = clone_noasan(child_func, CLONE_UNTRACED | SIGCHLD, &cargs);
if (pid < 0) {
pr_perror("fork");
return -1;
}
if (pid == 0) {
sk = sk_pair[1];
close(sk_pair[0]);
if (child_setup && child_setup() != 0)
exit(1);
if (write(sk, &c, 1) != 1) {
pr_perror("write");
exit(1);
}
while (1)
sleep(1000);
exit(1);
}
sk = sk_pair[0];
close(sk_pair[1]);