summaryrefslogtreecommitdiffstats
path: root/tools/regression/sockets/socketpair/socketpair.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/regression/sockets/socketpair/socketpair.c')
-rw-r--r--tools/regression/sockets/socketpair/socketpair.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/regression/sockets/socketpair/socketpair.c b/tools/regression/sockets/socketpair/socketpair.c
index a1d0946..5f46476 100644
--- a/tools/regression/sockets/socketpair/socketpair.c
+++ b/tools/regression/sockets/socketpair/socketpair.c
@@ -49,6 +49,7 @@
int
main(int argc, char *argv[])
{
+ int fd1, fd2, fd3;
int sv[2];
/*
@@ -123,6 +124,38 @@ main(int argc, char *argv[])
fprintf(stderr, "FAIL\n");
}
+ /*
+ * Check for sequential fd allocation, and give up early if not.
+ */
+ fd1 = dup(STDIN_FILENO);
+ fd2 = dup(STDIN_FILENO);
+ if (fd2 != fd1 + 1) {
+ fprintf(stderr, "Non-sequential fd allocation\n");
+ fprintf(stderr, "FAIL\n");
+ exit(-1);
+ }
+
+ /* Allocate a socketpair using a bad destination address. */
+ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, NULL) == 0) {
+ fprintf(stderr, "socketpair(PF_UNIX, SOCK_DGRAM, NULL): opened\n");
+ fprintf(stderr, "FAIL\n");
+ exit(-1);
+ }
+ if (errno != EFAULT) {
+ fprintf(stderr, "socketpair(PF_UNIX, SOCK_DGRAM, NULL): %s\n",
+ strerror(errno));
+ fprintf(stderr, "FAIL\n");
+ exit(-1);
+ }
+
+ /* Allocate a file descriptor and make sure it's fd2+1. */
+ fd3 = dup(STDIN_FILENO);
+ if (fd3 != fd2 + 1) {
+ fprintf(stderr, "socketpair(..., NULL) allocated descriptors\n");
+ fprintf(stderr, "FAIL\n");
+ exit(-1);
+ }
+
fprintf(stderr, "PASS\n");
exit(0);
}
OpenPOWER on IntegriCloud