svn commit: r281400 - head/tools/regression/sockets/unix_close_race
Garrett Cooper
ngie at FreeBSD.org
Sat Apr 11 03:43:45 UTC 2015
Author: ngie
Date: Sat Apr 11 03:43:43 2015
New Revision: 281400
URL: https://svnweb.freebsd.org/changeset/base/281400
Log:
- Garbage collect argc/argv; bump WARNS to 6
- Make the socket path random and move it out of /tmp as that's outside ATF's
prescribed path
MFC after: 1 week
Sponsored by: EMC / Isilon Storage Division
Modified:
head/tools/regression/sockets/unix_close_race/Makefile
head/tools/regression/sockets/unix_close_race/unix_close_race.c
Modified: head/tools/regression/sockets/unix_close_race/Makefile
==============================================================================
--- head/tools/regression/sockets/unix_close_race/Makefile Sat Apr 11 03:38:49 2015 (r281399)
+++ head/tools/regression/sockets/unix_close_race/Makefile Sat Apr 11 03:43:43 2015 (r281400)
@@ -2,6 +2,6 @@
PROG= unix_close_race
MAN=
-WARNS?= 3
+WARNS?= 6
.include <bsd.prog.mk>
Modified: head/tools/regression/sockets/unix_close_race/unix_close_race.c
==============================================================================
--- head/tools/regression/sockets/unix_close_race/unix_close_race.c Sat Apr 11 03:38:49 2015 (r281399)
+++ head/tools/regression/sockets/unix_close_race/unix_close_race.c Sat Apr 11 03:43:43 2015 (r281400)
@@ -54,12 +54,13 @@
#include <unistd.h>
#include <err.h>
-#define UNIXSTR_PATH "/tmp/mytest.socket"
+static char socket_path[] = "tmp.XXXXXXXX";
+
#define USLEEP 100
#define LOOPS 100000
int
-main(int argc, char **argv)
+main(void)
{
struct sockaddr_un servaddr;
int listenfd, connfd, pid;
@@ -74,16 +75,20 @@ main(int argc, char **argv)
if (ncpus < 2)
warnx("SMP not present, test may be unable to trigger race");
+ if (mkstemp(socket_path) == -1)
+ err(1, "mkstemp failed");
+ unlink(socket_path);
+
/*
* Create a UNIX domain socket that the child will repeatedly
* accept() from, and that the parent will repeatedly connect() to.
*/
if ((listenfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0)
err(1, "parent: socket error");
- (void)unlink(UNIXSTR_PATH);
+ (void)unlink(socket_path);
bzero(&servaddr, sizeof(servaddr));
servaddr.sun_family = AF_LOCAL;
- strcpy(servaddr.sun_path, UNIXSTR_PATH);
+ strcpy(servaddr.sun_path, socket_path);
if (bind(listenfd, (struct sockaddr *) &servaddr,
sizeof(servaddr)) < 0)
err(1, "parent: bind error");
@@ -102,7 +107,7 @@ main(int argc, char **argv)
sleep(1);
bzero(&servaddr, sizeof(servaddr));
servaddr.sun_family = AF_LOCAL;
- strcpy(servaddr.sun_path, UNIXSTR_PATH);
+ strcpy(servaddr.sun_path, socket_path);
for (counter = 0; counter < LOOPS; counter++) {
if ((connfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
(void)kill(pid, SIGTERM);
More information about the svn-src-head
mailing list