Correct several nits/problems in the unix_close_race regression test.

Submitted by:	Mikolaj Golub <to.my.trociny at gmail.com>
MFC after:	3 days
This commit is contained in:
rwatson 2010-05-27 15:28:55 +00:00
parent c7e8976175
commit b7cd561c87

View File

@ -75,8 +75,8 @@ main(int argc, char **argv)
warnx("SMP not present, test may be unable to trigger race"); warnx("SMP not present, test may be unable to trigger race");
/* /*
* Create a UNIX domain socket that the parent will repeatedly * Create a UNIX domain socket that the child will repeatedly
* accept() from, and that the child will repeatedly connect() to. * accept() from, and that the parent will repeatedly connect() to.
*/ */
if ((listenfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) if ((listenfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0)
err(1, "parent: socket error"); err(1, "parent: socket error");
@ -104,13 +104,19 @@ main(int argc, char **argv)
servaddr.sun_family = AF_LOCAL; servaddr.sun_family = AF_LOCAL;
strcpy(servaddr.sun_path, UNIXSTR_PATH); strcpy(servaddr.sun_path, UNIXSTR_PATH);
for (counter = 0; counter < LOOPS; counter++) { for (counter = 0; counter < LOOPS; counter++) {
if ((connfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) if ((connfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
err(1, "child: socket error"); (void)kill(pid, SIGTERM);
err(1, "parent: socket error");
}
if (connect(connfd, (struct sockaddr *)&servaddr, if (connect(connfd, (struct sockaddr *)&servaddr,
sizeof(servaddr)) < 0) sizeof(servaddr)) < 0) {
err(1, "child: connect error"); (void)kill(pid, SIGTERM);
if (close(connfd) < 0) err(1, "parent: connect error");
err(1, "child: close error"); }
if (close(connfd) < 0) {
(void)kill(pid, SIGTERM);
err(1, "parent: close error");
}
usleep(USLEEP); usleep(USLEEP);
} }
(void)kill(pid, SIGTERM); (void)kill(pid, SIGTERM);
@ -122,9 +128,9 @@ main(int argc, char **argv)
for ( ; ; ) { for ( ; ; ) {
if ((connfd = accept(listenfd, if ((connfd = accept(listenfd,
(struct sockaddr *)NULL, NULL)) < 0) (struct sockaddr *)NULL, NULL)) < 0)
err(1, "parent: accept error"); err(1, "child: accept error");
if (close(connfd) < 0) if (close(connfd) < 0)
err(1, "parent: close error"); err(1, "child: close error");
} }
} }
printf("OK\n"); printf("OK\n");