-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Suraj Shirvankar <[email protected]>
- Loading branch information
1 parent
defd37a
commit 0d46cc3
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <errno.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <signal.h> | ||
#include <string.h> | ||
#include <sys/syscall.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
#include <poll.h> | ||
|
||
#include "zdtmtst.h" | ||
|
||
static int pidfd_open(pid_t pid, unsigned int flags) { | ||
return syscall(SYS_pidfd_open, pid, flags); | ||
} | ||
|
||
const char *test_doc = "Pidfd "; | ||
const char *test_author = "Suraj Shirvankar <[email protected]>"; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int pidfd, errcode = 42; | ||
int status; | ||
int ret; | ||
struct pollfd pollfd; | ||
|
||
test_init(argc, argv); | ||
|
||
pidfd = pidfd_open(1, 0); | ||
if (pidfd == -1) { | ||
perror("Couldnt open pidfd"); | ||
exit(1); | ||
} | ||
|
||
test_daemon(); | ||
test_waitsig(); | ||
|
||
pollfd.fd = pidfd; | ||
pollfd.events = POLLIN; | ||
|
||
ret = poll(&pollfd, 1, -1); | ||
if (ret == -1){ | ||
pr_perror("Poll error"); | ||
fail(); | ||
} | ||
|
||
if(pollfd.revents & POLLIN) { | ||
if(read(pidfd, &status, sizeof(status)) != sizeof(status)) { | ||
fail("pidfd read error"); | ||
} | ||
if(status == errcode){ | ||
printf("Status code is %d", status); | ||
pass(); | ||
}else { | ||
fail("Exit code mismatch"); | ||
} | ||
} | ||
|
||
return 0; | ||
} |