summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorpluknet <pluknet@FreeBSD.org>2015-07-29 13:49:34 +0000
committerpluknet <pluknet@FreeBSD.org>2015-07-29 13:49:34 +0000
commitbb208e16c0bc79c4af732d04a91a568577392238 (patch)
tree6c12087abf4172fcfe9c4550af90d462a0c154b1 /tests
parent25c00d1c25dda00fa64be84a8ae9ce143a81398f (diff)
downloadFreeBSD-src-bb208e16c0bc79c4af732d04a91a568577392238.zip
FreeBSD-src-bb208e16c0bc79c4af732d04a91a568577392238.tar.gz
Fixed shutdown(2) unix(4) tests for SOCK_SEQPACKET after r285910 (by ed).
Diffstat (limited to 'tests')
-rw-r--r--tests/sys/kern/unix_seqpacket_test.c60
1 files changed, 52 insertions, 8 deletions
diff --git a/tests/sys/kern/unix_seqpacket_test.c b/tests/sys/kern/unix_seqpacket_test.c
index ccbacaf..986b70e 100644
--- a/tests/sys/kern/unix_seqpacket_test.c
+++ b/tests/sys/kern/unix_seqpacket_test.c
@@ -751,35 +751,79 @@ ATF_TC_BODY(send_recv_with_connect, tc)
ATF_TC_WITHOUT_HEAD(shutdown_send);
ATF_TC_BODY(shutdown_send, tc)
{
- int s;
- const char data[] = "data";
+ struct sockaddr_un sun;
+ /* ATF's isolation mechanisms will guarantee uniqueness of this file */
+ const char *path = "sock";
+ const char *data = "data";
ssize_t ssize;
+ int s, err, s2;
s = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
ATF_REQUIRE(s >= 0);
- ATF_CHECK_EQ(0, shutdown(s, SHUT_RDWR));
+
+ bzero(&sun, sizeof(sun));
+ sun.sun_family = AF_LOCAL;
+ sun.sun_len = sizeof(sun);
+ strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
+ err = bind(s, (struct sockaddr *)&sun, sizeof(sun));
+ err = listen(s, -1);
+ ATF_CHECK_EQ(0, err);
+
+ /* Create the other socket */
+ s2 = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
+ ATF_REQUIRE(s2 >= 0);
+ err = connect(s2, (struct sockaddr*)&sun, sizeof(sun));
+ if (err != 0) {
+ perror("connect");
+ atf_tc_fail("connect(2) failed");
+ }
+
+ ATF_CHECK_EQ(0, shutdown(s2, SHUT_RDWR));
/* USE MSG_NOSIGNAL so we don't get SIGPIPE */
- ssize = send(s, data, sizeof(data), MSG_EOR | MSG_NOSIGNAL);
+ ssize = send(s2, data, sizeof(data), MSG_EOR | MSG_NOSIGNAL);
ATF_CHECK_EQ(EPIPE, errno);
ATF_CHECK_EQ(-1, ssize);
close(s);
+ close(s2);
}
/* send(2) should cause SIGPIPE on a shutdown socket */
ATF_TC_WITHOUT_HEAD(shutdown_send_sigpipe);
ATF_TC_BODY(shutdown_send_sigpipe, tc)
{
- int s;
- const char data[] = "data";
+ struct sockaddr_un sun;
+ /* ATF's isolation mechanisms will guarantee uniqueness of this file */
+ const char *path = "sock";
+ const char *data = "data";
ssize_t ssize;
+ int s, err, s2;
s = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
ATF_REQUIRE(s >= 0);
- ATF_CHECK_EQ(0, shutdown(s, SHUT_RDWR));
+
+ bzero(&sun, sizeof(sun));
+ sun.sun_family = AF_LOCAL;
+ sun.sun_len = sizeof(sun);
+ strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
+ err = bind(s, (struct sockaddr *)&sun, sizeof(sun));
+ err = listen(s, -1);
+ ATF_CHECK_EQ(0, err);
+
+ /* Create the other socket */
+ s2 = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
+ ATF_REQUIRE(s2 >= 0);
+ err = connect(s2, (struct sockaddr*)&sun, sizeof(sun));
+ if (err != 0) {
+ perror("connect");
+ atf_tc_fail("connect(2) failed");
+ }
+
+ ATF_CHECK_EQ(0, shutdown(s2, SHUT_RDWR));
ATF_REQUIRE(SIG_ERR != signal(SIGPIPE, shutdown_send_sigpipe_handler));
- ssize = send(s, data, sizeof(data), MSG_EOR);
+ ssize = send(s2, data, sizeof(data), MSG_EOR);
ATF_CHECK_EQ(1, got_sigpipe);
close(s);
+ close(s2);
}
/* nonblocking send(2) and recv(2) a single short record */
OpenPOWER on IntegriCloud