diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index b7fb79643c..679e4bc416 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -268,6 +268,7 @@ TST_NOFILE := \ sigtrap \ sigtrap01 \ change_mnt_context \ + pidfd00 \ # jobctl00 \ PKG_CONFIG ?= pkg-config diff --git a/test/zdtm/static/pidfd00.c b/test/zdtm/static/pidfd00.c new file mode 100644 index 0000000000..db70badee9 --- /dev/null +++ b/test/zdtm/static/pidfd00.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 "; + +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; +}