Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: allow to run criu under strace #2273

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions criu/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,40 +661,54 @@ int cr_system_userns(int in, int out, int err, char *cmd, char *const argv[], un
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]);

Expand Down
Loading