From 8b79a473faf2ff25acb220500158920490c71576 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 25 Jun 2001 00:46:34 +0000 Subject: - make the regresison test mode code build in by default. This should allow us to have test targets without special configure options - fixed make proto so that it actually does something (This used to be commit 55109a752578e9389d853cb27ec17c2114ecff77) --- source3/lib/util_sock.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'source3/lib/util_sock.c') diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index 426d0572f1..7f8b83ec7d 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1146,36 +1146,33 @@ int create_pipe_socket(char *dir, int dir_perms, return s; } -#ifdef SMB_REGRESSION_TEST /******************************************************************* this is like socketpair but uses tcp. It is used by the Samba -user testing +regression test code +The function guarantees that nobody else can attach to the socket, +or if they do that this function fails and the socket gets closed +returns 0 on success, -1 on failure +the resulting file descriptors are symmetrical ******************************************************************/ static int socketpair_tcp(int fd[2]) { int listener; struct sockaddr sock; socklen_t socklen = sizeof(sock); - int len = socklen; - int one = 1; int connect_done = 0; - + fd[0] = fd[1] = listener = -1; memset(&sock, 0, sizeof(sock)); if ((listener = socket(PF_INET, SOCK_STREAM, 0)) == -1) goto failed; - setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one)); - if (listen(listener, 1) != 0) goto failed; if (getsockname(listener, &sock, &socklen) != 0) goto failed; if ((fd[1] = socket(PF_INET, SOCK_STREAM, 0)) == -1) goto failed; - setsockopt(fd[1],SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one)); - set_blocking(fd[1], 0); if (connect(fd[1],(struct sockaddr *)&sock,sizeof(sock)) == -1) { @@ -1184,9 +1181,7 @@ static int socketpair_tcp(int fd[2]) connect_done = 1; } - if ((fd[0] = accept(listener, &sock, &len)) == -1) goto failed; - - setsockopt(fd[0],SOL_SOCKET,SO_REUSEADDR,(char *)&one,sizeof(one)); + if ((fd[0] = accept(listener, &sock, &socklen)) == -1) goto failed; close(listener); if (connect_done == 0) { @@ -1208,9 +1203,12 @@ static int socketpair_tcp(int fd[2]) /******************************************************************* run a program on a local tcp socket, this is used to launch smbd -in the test code +when regression testing +the return value is a socket which is attached to a subprocess +running "prog". stdin and stdout are attached. stderr is left +attached to the original stderr ******************************************************************/ -int sock_exec(char *prog) +int sock_exec(const char *prog) { int fd[2]; if (socketpair_tcp(fd) != 0) return -1; @@ -1225,4 +1223,4 @@ int sock_exec(char *prog) close(fd[1]); return fd[0]; } -#endif + -- cgit