From a9a06eb97bcc567460940d026d44738ae57b14cb Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Fri, 1 Feb 2013 16:04:10 +0400 Subject: [PATCH] zdtm: check unshared descriptors for one end of a pipe Signed-off-by: Andrey Vagin --- test/zdtm/live/static/Makefile | 1 + test/zdtm/live/static/pipe02.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 test/zdtm/live/static/pipe02.c diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile index 64d3c15..b67cbbd 100644 --- a/test/zdtm/live/static/Makefile +++ b/test/zdtm/live/static/Makefile @@ -33,6 +33,7 @@ TST_NOFILE = \ ptrace_sig \ pipe00 \ pipe01 \ + pipe02 \ pthread00 \ vdso00 \ utsname \ diff --git a/test/zdtm/live/static/pipe02.c b/test/zdtm/live/static/pipe02.c new file mode 100644 index 0000000..a970e0a --- /dev/null +++ b/test/zdtm/live/static/pipe02.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +const char *test_doc = "Lock inversion"; +const char *test_author = "Andrey Vagin "; + +int main(int argc, char ** argv) +{ + int p[2], fd; + int ret; + char path[PATH_MAX]; + int flags; + + test_init(argc, argv); + + ret = pipe(p); + if (ret) + return 1; + + snprintf(path, sizeof(path), "/proc/self/fd/%d", p[0]); + + fd = open(path, O_RDONLY); + if (fd == -1) { + err("open"); + return 1; + }; + + if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) == -1) { + err("fcntl"); + return 1; + } + + test_daemon(); + + test_waitsig(); + + flags = fcntl(fd, F_GETFL, 0); + if ((flags & O_NONBLOCK) == 0) { + fail("O_NONBLOCK are not restored for %d", fd); + return 1; + } + + flags = fcntl(p[0], F_GETFL, 0); + if ((flags & O_NONBLOCK) != 0) { + fail("Unexpected O_NONBLOCK on %d", p[0]); + return 1; + } + + pass(); + + return 0; +} -- 1.7.11.7