Date: Sat, 25 Apr 2015 05:31:53 +0000 (UTC) From: Garrett Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r281974 - in stable/10/tools/regression/sockets: accept_fd_leak accf_data_attach fstat kqueue listen_backlog listenclose pr_atomic reconnect rtsocket sblock sendfile shutdown sigpipe so... Message-ID: <201504250531.t3P5Vrrn078878@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Sat Apr 25 05:31:52 2015 New Revision: 281974 URL: https://svnweb.freebsd.org/changeset/base/281974 Log: MFC r261550,r281354,r281355,r281356,r281358,r281359,r281360,r281361,r281362,r281391,r281392,r281393,r281394,r281395,r281397,r281398,r281399,r281400,r281401,r281402,r281403,r281404,r281407,r281408,r281409,r281410,r281411: r261550 (by glebius): Add test case for kern/181741. Right now test fails. PR: 181741 Sponsored by: Nginx, Inc. r281354: Fix warnings, fix a typo in a testcase description, bump WARNS to 3 - Remove argc/argv (-Wunused) - Cast len in comparison to size_t (-Wsign-compare) Sponsored by: EMC / Isilon Storage Division r281355: Fix -Wunused warnings, bump WARNS to 6 The testcase fails today on subtest # 9 The output is still broken if prove -rv is run and the testcase aborts prematurely (the testcase doesn't really conform to TAP protocol properly, except when it completes fully) Sponsored by: EMC / Isilon Storage Division r281356: Fix -Wunused warnings, bump WARNS to 6 The output is still broken if prove -rv is run and the testcase aborts prematurely with fail_assertion (the testcase doesn't really conform to TAP protocol properly, except when it completes fully) Sponsored by: EMC / Isilon Storage Division r281358: - Parameterize out the number of accept/connect attempts - Randomize the bind port to allow 2+ consecutive calls in < 10 minutes, and to also not fail if (for instance) there's a server already listening on port 8080 - Don't leak the listening socket / fds into the child process - Fix warnings: -- Remove argc/argv (-Wunused) -- Mark sig __unused (-Wunused) -- Mark quit static (-Wmissing-variable-declarations) Sponsored by: EMC / Isilon Storage Division r281359: Remove argc/argv (-Wunused) Sponsored by: EMC / Isilon Storage Division r281360: Fix warnings - Remove argc/argv (-Wunused) - Mark some parameters to socket_listen_update __unused (-Wunused) Sponsored by: EMC / Isilon Storage Division r281361: Remove argc/argv (-Wunused) Sponsored by: EMC / Isilon Storage Division r281362: Use _exit, not exit in forked process Sponsored by: EMC / Isilon Storage Division r281391: - Use static buffers for temporary file paths instead of strdup of constant strings - Don't use /tmp because it's outside ATF's prescribed sandbox - Use mkstemp instead of mktemp to eliminate warning Sponsored by: EMC / Isilon Storage Division r281392: - Garbage collect argc/argv (-Wunused) - Bump WARNS to 6 Sponsored by: EMC / Isilon Storage Division r281393: Fix warnings and bump WARNS to 6 - Garbage collect argc/argv (-Wunused) - sleep(3) will always return an unsigned int; don't check for return codes <0 (-Wsign-compare) Sponsored by: EMC / Isilon Storage Division r281394: - Don't use /tmp because it's outside ATF's prescribed sandbox - Replace a hardcoded PATH_MAX value with sizeof(path) - Use path like an array, not a pointer, and always try to unlink it in cleanup Sponsored by: EMC / Isilon Storage Division r281395: Fix a -Wuninitialized warning by setting the socket to -1 and bump WARNS to 6 Sponsored by: EMC / Isilon Storage Division r281397: Mark signum unused in signal_handler; bump WARNS to 6 Sponsored by: EMC / Isilon Storage Division r281398: Garbage collect argc/argv and bump WARNS to 6 Sponsored by: EMC / Isilon Storage Division r281399: Fix warnings and bump WARNS to 6 - Staticize variables as needed - Garbage collect argc/argv - Fix -Wsign-compare warnings by casting small sizeof to (int) Sponsored by: EMC / Isilon Storage Division r281400: - 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 Sponsored by: EMC / Isilon Storage Division r281401: - Garbage collect argc/argv - Use random paths instead of one in /tmp Sponsored by: EMC / Isilon Storage Division r281402: Garbage collect argc/argv and bump WARNS to 6 Sponsored by: EMC / Isilon Storage Division r281403: Garbage collect argc/argv and bump WARNS to 6 Sponsored by: EMC / Isilon Storage Division r281404: Generate temporary files with mkstemp instead of mktemp Sponsored by: EMC / Isilon Storage Division r281407: Fix the knob twiddling to work properly per src.opts.mk Sponsored by: EMC / Isilon Storage Division r281408: - Remove the .t wrapper and put the "magic" of determining the number of testcases into the .c file - Require root for now because it fails with SOCK_RAW without root privileges - Increment the test count properly on socket create failure Sponsored by: EMC / Isilon Storage Division r281409: Fix warnings, bump WARNS to 6, and use a temporary socket instead of one in /tmp Sponsored by: EMC / Isilon Storage Division r281410: Fix more warnings I didn't catch in the first go-around Sponsored by: EMC / Isilon Storage Division r281411: Fix even more warnings.. Sponsored by: EMC / Isilon Storage Division Deleted: stable/10/tools/regression/sockets/so_setfib/so_setfib.t Modified: stable/10/tools/regression/sockets/accept_fd_leak/Makefile stable/10/tools/regression/sockets/accept_fd_leak/accept_fd_leak.c stable/10/tools/regression/sockets/accf_data_attach/Makefile stable/10/tools/regression/sockets/accf_data_attach/accf_data_attach.c stable/10/tools/regression/sockets/fstat/Makefile stable/10/tools/regression/sockets/fstat/fstat.c stable/10/tools/regression/sockets/kqueue/Makefile stable/10/tools/regression/sockets/kqueue/kqueue.c stable/10/tools/regression/sockets/listen_backlog/Makefile stable/10/tools/regression/sockets/listen_backlog/listen_backlog.c stable/10/tools/regression/sockets/listenclose/Makefile stable/10/tools/regression/sockets/listenclose/listenclose.c stable/10/tools/regression/sockets/pr_atomic/Makefile stable/10/tools/regression/sockets/pr_atomic/pr_atomic.c stable/10/tools/regression/sockets/reconnect/Makefile stable/10/tools/regression/sockets/reconnect/reconnect.c stable/10/tools/regression/sockets/rtsocket/Makefile stable/10/tools/regression/sockets/rtsocket/rtsocket.c stable/10/tools/regression/sockets/sblock/Makefile stable/10/tools/regression/sockets/sblock/sblock.c stable/10/tools/regression/sockets/sendfile/sendfile.c stable/10/tools/regression/sockets/shutdown/Makefile stable/10/tools/regression/sockets/shutdown/shutdown.c stable/10/tools/regression/sockets/sigpipe/Makefile stable/10/tools/regression/sockets/sigpipe/sigpipe.c stable/10/tools/regression/sockets/so_setfib/Makefile stable/10/tools/regression/sockets/so_setfib/so_setfib.c stable/10/tools/regression/sockets/socketpair/Makefile stable/10/tools/regression/sockets/socketpair/socketpair.c stable/10/tools/regression/sockets/unix_bindconnect/Makefile stable/10/tools/regression/sockets/unix_bindconnect/unix_bindconnect.c stable/10/tools/regression/sockets/unix_close_race/Makefile stable/10/tools/regression/sockets/unix_close_race/unix_close_race.c stable/10/tools/regression/sockets/unix_passfd/Makefile stable/10/tools/regression/sockets/unix_passfd/unix_passfd.c stable/10/tools/regression/sockets/unix_sendtorace/Makefile stable/10/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c stable/10/tools/regression/sockets/unix_socket/Makefile stable/10/tools/regression/sockets/unix_socket/unix_socket.c stable/10/tools/regression/sockets/unix_sorflush/Makefile stable/10/tools/regression/sockets/unix_sorflush/unix_sorflush.c stable/10/tools/regression/sockets/zerosend/zerosend.c Directory Properties: stable/10/ (props changed) Modified: stable/10/tools/regression/sockets/accept_fd_leak/Makefile ============================================================================== --- stable/10/tools/regression/sockets/accept_fd_leak/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/accept_fd_leak/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,8 +4,6 @@ PROG= accept_fd_leak MAN= - -regress: - ./accept_fd_leak +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/accept_fd_leak/accept_fd_leak.c ============================================================================== --- stable/10/tools/regression/sockets/accept_fd_leak/accept_fd_leak.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/accept_fd_leak/accept_fd_leak.c Sat Apr 25 05:31:52 2015 (r281974) @@ -26,7 +26,7 @@ * $FreeBSD$ */ -#include <sys/types.h> +#include <sys/param.h> #include <sys/socket.h> #include <sys/wait.h> @@ -41,13 +41,16 @@ #include <string.h> #include <unistd.h> +#define BIND_ATTEMPTS 10 #define LOOPS 500 +#define NUM_ATTEMPTS 1000 -volatile int quit; +static volatile int quit; static void -child_died(int sig) +child_died(int sig __unused) { + quit = 1; } @@ -59,13 +62,12 @@ child_died(int sig) * briefly before beginning (not 100% reliable, but a good start). */ int -main(int argc, char *argv[]) +main(void) { struct sockaddr_in sin; socklen_t size; pid_t child; - int fd1, fd2, fd3, i, s; - int status; + int fd1, fd2, fd3, i, listen_port, s, status; printf("1..2\n"); @@ -85,10 +87,22 @@ main(int argc, char *argv[]) sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - sin.sin_port = htons(8080); - if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) != 0) - errx(-1, "bind: %s", strerror(errno)); + srandomdev(); + + for (i = 0; i < BIND_ATTEMPTS; i++) { + /* Pick a random unprivileged port 1025-65535 */ + listen_port = MAX((int)random() % 65535, 1025); + sin.sin_port = htons(listen_port); + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == 0) + break; + warn("bind with %d failed", listen_port); + usleep(1000); + } + if (i >= BIND_ATTEMPTS) { + printf("Bail out!\n"); + exit(1); + } if (listen(s, -1) != 0) errx(-1, "listen: %s", strerror(errno)); @@ -134,16 +148,20 @@ main(int argc, char *argv[]) errx(-1, "fork: %s", strerror(errno)); /* - * Child process does 1000 connect's. + * Child process does `NUM_ATTEMPTS` connects. */ if (child == 0) { + close(fd1); + close(fd2); + close(s); + bzero(&sin, sizeof(sin)); sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - sin.sin_port = htons(8080); + sin.sin_port = htons(listen_port); - for (i = 0; i < 1000; i++) { + for (i = 0; i < NUM_ATTEMPTS; i++) { s = socket(PF_INET, SOCK_STREAM, 0); if (s == -1) errx(-1, "socket: %s", strerror(errno)); @@ -152,7 +170,7 @@ main(int argc, char *argv[]) errx(-1, "connect: %s", strerror(errno)); close(s); } - exit(0); + _exit(0); } /* Reset back to a blocking socket. */ @@ -167,9 +185,9 @@ main(int argc, char *argv[]) errx(-1, "ioctl(F_GETFL): %s", strerror(errno)); if (i & O_NONBLOCK) errx(-1, "Failed to clear O_NONBLOCK (i=0x%x)\n", i); - - /* Do 1000 accept's with an invalid pointer. */ - for (i = 0; !quit && i < 1000; i++) { + + /* Do `NUM_ATTEMPTS` accepts with an invalid pointer. */ + for (i = 0; !quit && i < NUM_ATTEMPTS; i++) { size = sizeof(sin); if (accept(s, (struct sockaddr *)(uintptr_t)(0x100), &size) != -1) @@ -182,7 +200,7 @@ main(int argc, char *argv[]) errx(-1, "waitpid: %s", strerror(errno)); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) warnx("child process died"); - + /* * Allocate a file descriptor and make sure it's fd2+2. 2 because * we allocate an fd for the socket. Modified: stable/10/tools/regression/sockets/accf_data_attach/Makefile ============================================================================== --- stable/10/tools/regression/sockets/accf_data_attach/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/accf_data_attach/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,8 +4,6 @@ PROG= accf_data_attach MAN= - -accf_data_attach: accf_data_attach.c - gcc -Wall -o accf_data_attach accf_data_attach.c +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/accf_data_attach/accf_data_attach.c ============================================================================== --- stable/10/tools/regression/sockets/accf_data_attach/accf_data_attach.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/accf_data_attach/accf_data_attach.c Sat Apr 25 05:31:52 2015 (r281974) @@ -58,7 +58,7 @@ * make sure it is removed. */ int -main(int argc, char *argv[]) +main(void) { struct accept_filter_arg afa; struct sockaddr_in sin; Modified: stable/10/tools/regression/sockets/fstat/Makefile ============================================================================== --- stable/10/tools/regression/sockets/fstat/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/fstat/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,6 +4,6 @@ PROG= fstat MAN= -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/fstat/fstat.c ============================================================================== --- stable/10/tools/regression/sockets/fstat/fstat.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/fstat/fstat.c Sat Apr 25 05:31:52 2015 (r281974) @@ -57,7 +57,7 @@ dotest(int domain, int type, int protoco } int -main(int argc, char *argv[]) +main(void) { dotest(PF_INET, SOCK_DGRAM, 0); Modified: stable/10/tools/regression/sockets/kqueue/Makefile ============================================================================== --- stable/10/tools/regression/sockets/kqueue/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/kqueue/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,5 +4,6 @@ PROG= kqueue MAN= +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/kqueue/kqueue.c ============================================================================== --- stable/10/tools/regression/sockets/kqueue/kqueue.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/kqueue/kqueue.c Sat Apr 25 05:31:52 2015 (r281974) @@ -250,9 +250,9 @@ test_evfilt_write(int kq, int fd[2], con * sockets, and confirm that we can register for various events on them. */ int -main(int argc, char *argv[]) +main(void) { - int i, kq, sv[2]; + int kq, sv[2]; printf("1..49\n"); Modified: stable/10/tools/regression/sockets/listen_backlog/Makefile ============================================================================== --- stable/10/tools/regression/sockets/listen_backlog/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/listen_backlog/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -1,7 +1,7 @@ # $FreeBSD$ PROG= listen_backlog -WARNS?= 3 MAN= +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/listen_backlog/listen_backlog.c ============================================================================== --- stable/10/tools/regression/sockets/listen_backlog/listen_backlog.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/listen_backlog/listen_backlog.c Sat Apr 25 05:31:52 2015 (r281974) @@ -218,7 +218,8 @@ test_defaults(void) * the first and second listen(). */ static int -socket_listen_update(int domain, int type, int protocol, int backlog, +socket_listen_update(int domain __unused, int type __unused, + int protocol __unused, int backlog, int update_backlog, int listen_backlog_assertion, int update_backlog_assertion, int *sockp, const char *domainstring, const char *typestring, const char *testclass, const char *test) @@ -365,7 +366,7 @@ test_set_qlimit(void) } int -main(int argc, char *argv[]) +main(void) { size_t len; Modified: stable/10/tools/regression/sockets/listenclose/Makefile ============================================================================== --- stable/10/tools/regression/sockets/listenclose/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/listenclose/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,6 +4,6 @@ PROG= listenclose MAN= -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/listenclose/listenclose.c ============================================================================== --- stable/10/tools/regression/sockets/listenclose/listenclose.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/listenclose/listenclose.c Sat Apr 25 05:31:52 2015 (r281974) @@ -52,7 +52,7 @@ */ int -main(int argc, char *argv[]) +main(void) { int listen_sock, connect_sock; struct sockaddr_in sin; Modified: stable/10/tools/regression/sockets/pr_atomic/Makefile ============================================================================== --- stable/10/tools/regression/sockets/pr_atomic/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/pr_atomic/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -2,6 +2,6 @@ PROG= pr_atomic MAN= -WARNS?= 3 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/pr_atomic/pr_atomic.c ============================================================================== --- stable/10/tools/regression/sockets/pr_atomic/pr_atomic.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/pr_atomic/pr_atomic.c Sat Apr 25 05:31:52 2015 (r281974) @@ -42,31 +42,31 @@ #include <errno.h> #include <unistd.h> -#define TEST_SOCKET "/tmp/test_socket" +static char socket_path[] = "tmp.XXXXXX"; static jmp_buf myjmpbuf; -void handle_sigalrm(int signo); - -void handle_sigalrm(int signo) +static void handle_sigalrm(int signo __unused) { longjmp(myjmpbuf, 1); } int -main(int argc, char *argv[]) +main(void) { struct sockaddr_un un; pid_t pid; int s; + if (mkstemp(socket_path) == -1) + err(1, "mkstemp"); s = socket(PF_LOCAL, SOCK_DGRAM, 0); if (s == -1) errx(-1, "socket"); memset(&un, 0, sizeof(un)); un.sun_family = AF_LOCAL; - unlink(TEST_SOCKET); - strcpy(un.sun_path, TEST_SOCKET); + unlink(socket_path); + strcpy(un.sun_path, socket_path); if (bind(s, (struct sockaddr *)&un, sizeof(un)) == -1) errx(-1, "bind"); pid = fork(); Modified: stable/10/tools/regression/sockets/reconnect/Makefile ============================================================================== --- stable/10/tools/regression/sockets/reconnect/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/reconnect/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,6 +4,6 @@ PROG= reconnect MAN= -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/reconnect/reconnect.c ============================================================================== --- stable/10/tools/regression/sockets/reconnect/reconnect.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/reconnect/reconnect.c Sat Apr 25 05:31:52 2015 (r281974) @@ -45,12 +45,12 @@ #include <string.h> #include <unistd.h> -static char *uds_name1 = NULL; -static char *uds_name2 = NULL; +static char uds_name1[] = "reconnect.XXXXXXXX"; +static char uds_name2[] = "reconnect.XXXXXXXX"; #define sstosa(ss) ((struct sockaddr *)(ss)) -void +static void prepare_ifsun(struct sockaddr_un *ifsun, const char *path) { @@ -62,7 +62,7 @@ prepare_ifsun(struct sockaddr_un *ifsun, strcpy(ifsun->sun_path, path); } -int +static int create_uds_server(const char *path) { struct sockaddr_un ifsun; @@ -82,7 +82,7 @@ create_uds_server(const char *path) return sock; } -void +static void connect_uds_server(int sock, const char *path) { struct sockaddr_un ifsun; @@ -95,14 +95,12 @@ connect_uds_server(int sock, const char err(1, "can't connect to a socket"); } -void +static void cleanup(void) { - if (uds_name1 != NULL) - unlink(uds_name1); - if (uds_name2 != NULL) - unlink(uds_name2); + unlink(uds_name1); + unlink(uds_name2); } int @@ -112,20 +110,14 @@ main() atexit(cleanup); - uds_name1 = strdup("/tmp/reconnect.XXXXXX"); - if (uds_name1 == NULL) - err(1, "can't allocate memory"); - uds_name1 = mktemp(uds_name1); - if (uds_name1 == NULL) - err(1, "mktemp(3) failed"); + if (mkstemp(uds_name1) == -1) + err(1, "mkstemp"); + unlink(uds_name1); s_sock1 = create_uds_server(uds_name1); - uds_name2 = strdup("/tmp/reconnect.XXXXXX"); - if (uds_name2 == NULL) - err(1, "can't allocate memory"); - uds_name2 = mktemp(uds_name2); - if (uds_name2 == NULL) - err(1, "mktemp(3) failed"); + if (mkstemp(uds_name2) == -1) + err(1, "mkstemp"); + unlink(uds_name2); s_sock2 = create_uds_server(uds_name2); c_sock = socket(PF_LOCAL, SOCK_DGRAM, 0); Modified: stable/10/tools/regression/sockets/rtsocket/Makefile ============================================================================== --- stable/10/tools/regression/sockets/rtsocket/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/rtsocket/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -2,6 +2,6 @@ PROG= rtsocket MAN= -WARNS?= 3 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/rtsocket/rtsocket.c ============================================================================== --- stable/10/tools/regression/sockets/rtsocket/rtsocket.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/rtsocket/rtsocket.c Sat Apr 25 05:31:52 2015 (r281974) @@ -41,7 +41,7 @@ #include <unistd.h> int -main(int argc, char *argv[]) +main(void) { int sock, socks[2]; Modified: stable/10/tools/regression/sockets/sblock/Makefile ============================================================================== --- stable/10/tools/regression/sockets/sblock/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/sblock/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,6 +4,6 @@ PROG= sblock MAN= -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/sblock/sblock.c ============================================================================== --- stable/10/tools/regression/sockets/sblock/sblock.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/sblock/sblock.c Sat Apr 25 05:31:52 2015 (r281974) @@ -54,7 +54,7 @@ static int interrupted; static void -signal_handler(int signum) +signal_handler(int signum __unused) { interrupted++; @@ -95,7 +95,7 @@ locking_recver(int fd) ssize_t len; char ch; - if (sleep(1) < 0) + if (sleep(1) != 0) err(-1, "FAIL: locking_recver: sleep"); len = recv(fd, &ch, sizeof(ch), 0); if (len < 0 && errno != EINTR) @@ -116,7 +116,7 @@ signaller(pid_t locking_recver_pid, int ssize_t len; char ch; - if (sleep(2) < 0) { + if (sleep(2) != 0) { warn("signaller sleep(2)"); return; } @@ -124,7 +124,7 @@ signaller(pid_t locking_recver_pid, int warn("signaller kill(%d)", locking_recver_pid); return; } - if (sleep(1) < 0) { + if (sleep(1) != 0) { warn("signaller sleep(1)"); return; } @@ -141,14 +141,14 @@ signaller(pid_t locking_recver_pid, int warn("signaller close"); return; } - if (sleep(1) < 0) { + if (sleep(1) != 0) { warn("signaller sleep(1)"); return; } } int -main(int argc, char *argv[]) +main(void) { int error, fds[2], recver_fd, sender_fd; pid_t blocking_recver_pid; Modified: stable/10/tools/regression/sockets/sendfile/sendfile.c ============================================================================== --- stable/10/tools/regression/sockets/sendfile/sendfile.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/sendfile/sendfile.c Sat Apr 25 05:31:52 2015 (r281974) @@ -452,8 +452,8 @@ run_parent(void) static void cleanup(void) { - if (*path != '\0') - unlink(path); + + unlink(path); } int @@ -461,12 +461,12 @@ main(int argc, char *argv[]) { int pagesize; - *path = '\0'; + path[0] = '\0'; pagesize = getpagesize(); if (argc == 1) { - snprintf(path, PATH_MAX, "/tmp/sendfile.XXXXXXXXXXXX"); + snprintf(path, sizeof(path), "sendfile.XXXXXXXXXXXX"); file_fd = mkstemp(path); if (file_fd == -1) FAIL_ERR("mkstemp"); Modified: stable/10/tools/regression/sockets/shutdown/Makefile ============================================================================== --- stable/10/tools/regression/sockets/shutdown/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/shutdown/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,6 +4,6 @@ PROG= shutdown MAN= -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/shutdown/shutdown.c ============================================================================== --- stable/10/tools/regression/sockets/shutdown/shutdown.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/shutdown/shutdown.c Sat Apr 25 05:31:52 2015 (r281974) @@ -45,6 +45,8 @@ main(void) int listen_sock, connect_sock; u_short port; + listen_sock = -1; + /* Shutdown(2) on an invalid file descriptor has to return EBADF. */ if ((shutdown(listen_sock, SHUT_RDWR) != -1) && (errno != EBADF)) errx(-1, "shutdown() for invalid file descriptor does not " Modified: stable/10/tools/regression/sockets/sigpipe/Makefile ============================================================================== --- stable/10/tools/regression/sockets/sigpipe/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/sigpipe/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,6 +4,6 @@ PROG= sigpipe MAN= -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/sigpipe/sigpipe.c ============================================================================== --- stable/10/tools/regression/sockets/sigpipe/sigpipe.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/sigpipe/sigpipe.c Sat Apr 25 05:31:52 2015 (r281974) @@ -69,7 +69,7 @@ got_signal(void) } static void -signal_handler(int signum) +signal_handler(int signum __unused) { signaled = 1; Modified: stable/10/tools/regression/sockets/so_setfib/Makefile ============================================================================== --- stable/10/tools/regression/sockets/so_setfib/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/so_setfib/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -1,14 +1,16 @@ # $FreeBSD$ +.include <bsd.own.mk> + PROG= so_setfib MAN= WARNS?= 6 -.ifdef INET6 -CFLAGS+= -DINET6 -.endif -.ifdef INET +.if ${MK_INET} != "no" CFLAGS+= -DINET .endif +.if ${MK_INET6} != "no" +CFLAGS+= -DINET6 +.endif .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/so_setfib/so_setfib.c ============================================================================== --- stable/10/tools/regression/sockets/so_setfib/so_setfib.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/so_setfib/so_setfib.c Sat Apr 25 05:31:52 2015 (r281974) @@ -45,6 +45,7 @@ * 5. Repeat for next domain family and type from (2) on. */ +#include <sys/param.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/sysctl.h> @@ -143,6 +144,7 @@ t(u_int dom, u_int type) if (s == -1) { printf("not ok %d %s_%s # socket(): %s\n", testno, t_dom[dom].name, t_type[type].name, strerror(errno)); + testno++; return; } @@ -168,6 +170,11 @@ main(int argc __unused, char *argv[] __u u_int i, j; size_t s; + if (geteuid() != 0) { + printf("1..0 # SKIP: must be root"); + return (0); + } + /* Initalize randomness. */ srandomdev(); @@ -175,6 +182,10 @@ main(int argc __unused, char *argv[] __u s = sizeof(rt_numfibs); if (sysctlbyname("net.fibs", &rt_numfibs, &s, NULL, 0) == -1) err(1, "sysctlbyname(net.fibs, ..)"); + + printf("1..%lu\n", + (nitems(t_dom) - 1) * nitems(t_type) * (2 + rt_numfibs + 2 + 3)); + /* Adjust from number to index. */ rt_numfibs -= 1; Modified: stable/10/tools/regression/sockets/socketpair/Makefile ============================================================================== --- stable/10/tools/regression/sockets/socketpair/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/socketpair/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -4,6 +4,6 @@ PROG= socketpair MAN= -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/socketpair/socketpair.c ============================================================================== --- stable/10/tools/regression/sockets/socketpair/socketpair.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/socketpair/socketpair.c Sat Apr 25 05:31:52 2015 (r281974) @@ -47,7 +47,7 @@ * right places. */ int -main(int argc, char *argv[]) +main(void) { int fd1, fd2, fd3; int sv[2]; Modified: stable/10/tools/regression/sockets/unix_bindconnect/Makefile ============================================================================== --- stable/10/tools/regression/sockets/unix_bindconnect/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/unix_bindconnect/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -2,6 +2,6 @@ PROG= unix_bindconnect MAN= -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/unix_bindconnect/unix_bindconnect.c ============================================================================== --- stable/10/tools/regression/sockets/unix_bindconnect/unix_bindconnect.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/unix_bindconnect/unix_bindconnect.c Sat Apr 25 05:31:52 2015 (r281974) @@ -54,8 +54,8 @@ #define UNWIND_MAX 1024 -int unwind_len; -struct unwind { +static int unwind_len; +static struct unwind { char u_path[PATH_MAX]; } unwind_list[UNWIND_MAX]; @@ -105,7 +105,7 @@ bind_test(const char *directory_path) sun.sun_len = sizeof(sun); sun.sun_family = AF_UNIX; if (snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", socket_path) - >= sizeof(sun.sun_path)) { + >= (int)sizeof(sun.sun_path)) { warn("bind_test: snprintf(sun.sun_path)"); close(sock1); return (-1); @@ -216,7 +216,7 @@ connect_test(const char *directory_path) sun.sun_len = sizeof(sun); sun.sun_family = AF_UNIX; if (snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", socket_path) - >= sizeof(sun.sun_path)) { + >= (int)sizeof(sun.sun_path)) { warn("connect_test: snprintf(sun.sun_path)"); close(sock1); return (-1); @@ -298,7 +298,7 @@ connect_test(const char *directory_path) return (0); } int -main(int argc, char *argv[]) +main(void) { char directory_path[PATH_MAX]; int error; Modified: stable/10/tools/regression/sockets/unix_close_race/Makefile ============================================================================== --- stable/10/tools/regression/sockets/unix_close_race/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/unix_close_race/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -2,6 +2,6 @@ PROG= unix_close_race MAN= -WARNS?= 3 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/unix_close_race/unix_close_race.c ============================================================================== --- stable/10/tools/regression/sockets/unix_close_race/unix_close_race.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/unix_close_race/unix_close_race.c Sat Apr 25 05:31:52 2015 (r281974) @@ -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); Modified: stable/10/tools/regression/sockets/unix_passfd/Makefile ============================================================================== --- stable/10/tools/regression/sockets/unix_passfd/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/unix_passfd/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -2,6 +2,6 @@ PROG= unix_passfd MAN= -WARNS?= 2 +WARNS?= 3 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/unix_passfd/unix_passfd.c ============================================================================== --- stable/10/tools/regression/sockets/unix_passfd/unix_passfd.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/unix_passfd/unix_passfd.c Sat Apr 25 05:31:52 2015 (r281974) @@ -29,11 +29,14 @@ #include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> +#include <sys/sysctl.h> +#include <sys/un.h> #include <err.h> #include <fcntl.h> #include <limits.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> @@ -106,11 +109,10 @@ samefile(const char *test, struct stat * } static void -sendfd(const char *test, int sockfd, int sendfd) +sendfd_payload(const char *test, int sockfd, int sendfd, + void *payload, size_t paylen) { struct iovec iovec; - char ch; - char message[CMSG_SPACE(sizeof(int))]; struct cmsghdr *cmsghdr; struct msghdr msghdr; @@ -118,13 +120,12 @@ sendfd(const char *test, int sockfd, int bzero(&msghdr, sizeof(msghdr)); bzero(&message, sizeof(message)); - ch = 0; msghdr.msg_control = message; msghdr.msg_controllen = sizeof(message); - iovec.iov_base = &ch; - iovec.iov_len = sizeof(ch); + iovec.iov_base = payload; + iovec.iov_len = paylen; msghdr.msg_iov = &iovec; msghdr.msg_iovlen = 1; @@ -138,33 +139,35 @@ sendfd(const char *test, int sockfd, int len = sendmsg(sockfd, &msghdr, 0); if (len < 0) err(-1, "%s: sendmsg", test); - if (len != sizeof(ch)) + if ((size_t)len != paylen) errx(-1, "%s: sendmsg: %zd bytes sent", test, len); } static void -recvfd(const char *test, int sockfd, int *recvfd) +sendfd(const char *test, int sockfd, int sendfd) +{ + char ch; + + return (sendfd_payload(test, sockfd, sendfd, &ch, sizeof(ch))); +} + +static void +recvfd_payload(const char *test, int sockfd, int *recvfd, + void *buf, size_t buflen) { struct cmsghdr *cmsghdr; - char message[CMSG_SPACE(sizeof(int))]; + char message[CMSG_SPACE(SOCKCREDSIZE(CMGROUP_MAX)) + sizeof(int)]; struct msghdr msghdr; struct iovec iovec; ssize_t len; - char ch; bzero(&msghdr, sizeof(msghdr)); - ch = 0; msghdr.msg_control = message; msghdr.msg_controllen = sizeof(message); - iovec.iov_base = &ch; - iovec.iov_len = sizeof(ch); - - msghdr.msg_iov = &iovec; - msghdr.msg_iovlen = 1; - - iovec.iov_len = sizeof(ch); + iovec.iov_base = buf; + iovec.iov_len = buflen; msghdr.msg_iov = &iovec; msghdr.msg_iovlen = 1; @@ -172,23 +175,37 @@ recvfd(const char *test, int sockfd, int len = recvmsg(sockfd, &msghdr, 0); if (len < 0) err(-1, "%s: recvmsg", test); - if (len != sizeof(ch)) + if ((size_t)len != buflen) errx(-1, "%s: recvmsg: %zd bytes received", test, len); + cmsghdr = CMSG_FIRSTHDR(&msghdr); if (cmsghdr == NULL) errx(-1, "%s: recvmsg: did not receive control message", test); - if (cmsghdr->cmsg_len != CMSG_LEN(sizeof(int)) || - cmsghdr->cmsg_level != SOL_SOCKET || - cmsghdr->cmsg_type != SCM_RIGHTS) + *recvfd = -1; + for (; cmsghdr != NULL; cmsghdr = CMSG_NXTHDR(&msghdr, cmsghdr)) { + if (cmsghdr->cmsg_level == SOL_SOCKET && + cmsghdr->cmsg_type == SCM_RIGHTS && + cmsghdr->cmsg_len == CMSG_LEN(sizeof(int))) { + *recvfd = *(int *)CMSG_DATA(cmsghdr); + if (*recvfd == -1) + errx(-1, "%s: recvmsg: received fd -1", test); + } + } + if (*recvfd == -1) errx(-1, "%s: recvmsg: did not receive single-fd message", test); - *recvfd = *(int *)CMSG_DATA(cmsghdr); - if (*recvfd == -1) - errx(-1, "%s: recvmsg: received fd -1", test); +} + +static void +recvfd(const char *test, int sockfd, int *recvfd) +{ + char ch; + + return (recvfd_payload(test, sockfd, recvfd, &ch, sizeof(ch))); } int -main(int argc, char *argv[]) +main(void) { struct stat putfd_1_stat, putfd_2_stat, getfd_1_stat, getfd_2_stat; int fd[2], putfd_1, putfd_2, getfd_1, getfd_2; @@ -330,6 +347,43 @@ main(int argc, char *argv[]) closesocketpair(fd); printf("%s passed\n", test); + + /* + * Test for PR 181741. Receiver sets LOCAL_CREDS, and kernel + * prepends a control message to the data. Sender sends large + * payload. Payload + SCM_RIGHTS + LOCAL_CREDS hit socket buffer + * limit, and receiver receives truncated data. + */ + test = "test8-rights+creds+payload"; + printf("beginning %s\n", test); + + { + const int on = 1; + u_long sendspace; + size_t len; + void *buf; + + len = sizeof(sendspace); + if (sysctlbyname("net.local.stream.sendspace", &sendspace, + &len, NULL, 0) < 0) + err(-1, "%s: sysctlbyname(net.local.stream.sendspace)", + test); + + if ((buf = malloc(sendspace)) == NULL) + err(-1, "%s: malloc", test); + + domainsocketpair(test, fd); + if (setsockopt(fd[1], 0, LOCAL_CREDS, &on, sizeof(on)) < 0) + err(-1, "%s: setsockopt(LOCAL_CREDS)", test); + tempfile(test, &putfd_1); + sendfd_payload(test, fd[0], putfd_1, buf, sendspace); + recvfd_payload(test, fd[1], &getfd_1, buf, sendspace); + close(putfd_1); + close(getfd_1); + closesocketpair(fd); + } + + printf("%s passed\n", test); return (0); } Modified: stable/10/tools/regression/sockets/unix_sendtorace/Makefile ============================================================================== --- stable/10/tools/regression/sockets/unix_sendtorace/Makefile Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/unix_sendtorace/Makefile Sat Apr 25 05:31:52 2015 (r281974) @@ -2,6 +2,6 @@ PROG= unix_sendtorace MAN= -WARNS?= 3 +WARNS?= 6 .include <bsd.prog.mk> Modified: stable/10/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c ============================================================================== --- stable/10/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c Sat Apr 25 05:25:41 2015 (r281973) +++ stable/10/tools/regression/sockets/unix_sendtorace/unix_sendtorace.c Sat Apr 25 05:31:52 2015 (r281974) @@ -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)); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504250531.t3P5Vrrn078878>