From 5a3935b6d66c1810125b0a92a0f26e207236f6fb Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Sat, 11 Apr 2015 03:54:43 +0000 Subject: [PATCH] - Garbage collect argc/argv - Use random paths instead of one in /tmp MFC after: 1 week Sponsored by: EMC / Isilon Storage Division --- .../sockets/unix_sendtorace/Makefile | 2 +- .../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 0b183760bb1b..75e7b9f0b606 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 diff --git a/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c b/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c index 2445b81752e6..9fd748d6f7bb 100644 --- a/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c +++ b/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c @@ -45,9 +45,10 @@ #include #include -#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();