Skip to content

Commit 4cec03a

Browse files
bsach64avagin
authored andcommitted
zdtm: Check pidfd can send signal after C/R
Ensure `pidfd_send_signal()` syscall works as expected after C/R. Signed-off-by: Bhavik Sachdev <[email protected]>
1 parent 005a331 commit 4cec03a

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

test/zdtm/static/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ TST_NOFILE := \
5454
shm-mp \
5555
ptrace_sig \
5656
pidfd_self \
57+
pidfd_child \
5758
pipe00 \
5859
pipe01 \
5960
pipe02 \

test/zdtm/static/pidfd_child.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <sys/syscall.h>
2+
#include <unistd.h>
3+
#include <sys/wait.h>
4+
5+
#include "zdtmtst.h"
6+
7+
const char *test_doc = "Checks pidfd sends signal to child process after restore\n";
8+
const char *test_author = "Bhavik Sachdev <[email protected]>";
9+
10+
static int pidfd_open(pid_t pid, unsigned int flags)
11+
{
12+
return syscall(__NR_pidfd_open, pid, flags);
13+
}
14+
15+
static int pidfd_send_signal(int pidfd, int sig, siginfo_t* info, unsigned int flags)
16+
{
17+
return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
18+
}
19+
20+
int main(int argc, char* argv[])
21+
{
22+
int pidfd, status;
23+
pid_t child;
24+
25+
test_init(argc, argv);
26+
27+
child = fork();
28+
if (child < 0) {
29+
pr_perror("Unable to fork a new process");
30+
return 1;
31+
} else if (child == 0) {
32+
test_waitsig();
33+
return 0;
34+
}
35+
36+
pidfd = pidfd_open(child, 0);
37+
if (pidfd < 0) {
38+
pr_perror("pidfd_open failed");
39+
return 1;
40+
}
41+
42+
test_daemon();
43+
test_waitsig();
44+
45+
if (pidfd_send_signal(pidfd, SIGTERM, NULL, 0)) {
46+
fail("Could not send signal");
47+
goto err_close;
48+
}
49+
50+
if (waitpid(child, &status, 0) != child) {
51+
pr_perror("waitpid()");
52+
goto err_close;
53+
}
54+
55+
if (status != 0) {
56+
fail("%d:%d:%d:%d", WIFEXITED(status), WEXITSTATUS(status), WIFSIGNALED(status), WTERMSIG(status));
57+
goto err_close;
58+
}
59+
60+
pass();
61+
close(pidfd);
62+
return 0;
63+
err_close:
64+
close(pidfd);
65+
return 1;
66+
}

0 commit comments

Comments
 (0)