diff options
author | ngie <ngie@FreeBSD.org> | 2015-04-11 03:54:43 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2015-04-11 03:54:43 +0000 |
commit | 7abb75d23304a0b71812d828efc75d1f9640cafc (patch) | |
tree | 1fda663967c0c73bce7ba3f5e0a1038a3f836001 /tools | |
parent | 1d4bda01f8fabc16c9a6310129567a3ee517626f (diff) | |
download | FreeBSD-src-7abb75d23304a0b71812d828efc75d1f9640cafc.zip FreeBSD-src-7abb75d23304a0b71812d828efc75d1f9640cafc.tar.gz |
- Garbage collect argc/argv
- Use random paths instead of one in /tmp
MFC after: 1 week
Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'tools')
-rw-r--r-- | tools/regression/sockets/unix_sendtorace/Makefile | 2 | ||||
-rw-r--r-- | tools/regression/sockets/unix_sendtorace/unix_sendtorace.c | 23 |
2 files changed, 14 insertions, 11 deletions
diff --git a/tools/regression/sockets/unix_sendtorace/Makefile b/tools/regression/sockets/unix_sendtorace/Makefile index 0b18376..75e7b9f 100644 --- a/tools/regression/sockets/unix_sendtorace/Makefile +++ b/tools/regression/sockets/unix_sendtorace/Makefile @@ -2,6 +2,6 @@ PROG= unix_sendtorace MAN= -WARNS?= 3 +WARNS?= 6 .include <bsd.prog.mk> diff --git a/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c b/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c index 2445b81..9fd748d 100644 --- a/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c +++ b/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c @@ -45,9 +45,10 @@ #include <string.h> #include <unistd.h> -#define PATH "/tmp/123" #define ITERATIONS 1000000 +static char socket_path[] = "tmp.XXXXXX"; + static void stream_server(int listenfd) { @@ -75,7 +76,7 @@ stream_client(void) bzero(&sun, sizeof(sun)); sun.sun_len = sizeof(sun); sun.sun_family = AF_UNIX; - strcpy(sun.sun_path, PATH); + strcpy(sun.sun_path, socket_path); for (i = 0; i < ITERATIONS; i++) { fd = socket(PF_UNIX, SOCK_STREAM, 0); if (fd < 0) { @@ -104,7 +105,7 @@ stream_test(void) bzero(&sun, sizeof(sun)); sun.sun_len = sizeof(sun); sun.sun_family = AF_UNIX; - strcpy(sun.sun_path, PATH); + strcpy(sun.sun_path, socket_path); if (bind(listenfd, (struct sockaddr *)&sun, sizeof(sun)) < 0) err(-1, "stream_test: bind"); @@ -124,7 +125,7 @@ stream_test(void) } else stream_server(listenfd); - (void)unlink(PATH); + (void)unlink(socket_path); } static void @@ -151,7 +152,7 @@ datagram_client(void) bzero(&sun, sizeof(sun)); sun.sun_len = sizeof(sun); sun.sun_family = AF_UNIX; - strcpy(sun.sun_path, PATH); + strcpy(sun.sun_path, socket_path); for (i = 0; i < ITERATIONS; i++) { fd = socket(PF_UNIX, SOCK_DGRAM, 0); if (fd < 0) { @@ -180,7 +181,7 @@ datagram_test(void) bzero(&sun, sizeof(sun)); sun.sun_len = sizeof(sun); sun.sun_family = AF_UNIX; - strcpy(sun.sun_path, PATH); + strcpy(sun.sun_path, socket_path); if (bind(serverfd, (struct sockaddr *)&sun, sizeof(sun)) < 0) err(-1, "datagram_test: bind"); @@ -197,14 +198,16 @@ datagram_test(void) } else datagram_server(serverfd); - (void)unlink(PATH); + (void)unlink(socket_path); } int -main(int argc, char *argv[]) +main(void) { - - (void)unlink(PATH); + + if (mkstemp(socket_path) == -1) + err(1, "mkstemp failed"); + (void)unlink(socket_path); datagram_test(); if (0) stream_test(); |