diff options
author | Marco S Hyman <marc@cvs.openbsd.org> | 2002-02-15 23:36:53 +0000 |
---|---|---|
committer | Marco S Hyman <marc@cvs.openbsd.org> | 2002-02-15 23:36:53 +0000 |
commit | 6b465ecef0ed1bad9d9703ec5b63b027d88a67e7 (patch) | |
tree | c2eaa09ca60dc0429912fc1c7f83c83a0dec3593 /regress | |
parent | ee02b627e102db7ad309894c02e9d522fcea1930 (diff) |
fork and start up a listener to discard bytes instead of
relying on the discard service being enabled. Listener listens on
localhost, only
Diffstat (limited to 'regress')
-rw-r--r-- | regress/lib/libc_r/close/close.c | 66 | ||||
-rw-r--r-- | regress/lib/libpthread/close/close.c | 66 |
2 files changed, 122 insertions, 10 deletions
diff --git a/regress/lib/libc_r/close/close.c b/regress/lib/libc_r/close/close.c index 2e21ecf1e47..e92c5c3f9c2 100644 --- a/regress/lib/libc_r/close/close.c +++ b/regress/lib/libc_r/close/close.c @@ -1,4 +1,4 @@ -/* $OpenBSD: close.c,v 1.2 2001/09/20 16:43:15 todd Exp $ */ +/* $OpenBSD: close.c,v 1.3 2002/02/15 23:36:52 marc Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996 by Chris Provenzano and contributors, * proven@mit.edu All rights reserved. @@ -34,8 +34,7 @@ /* * Test the semantics of close() while a select() is happening. - * Not a great test. You need the 'discard' service running in inetd for - * this to work. + * Not a great test. */ #include <pthread.h> @@ -48,8 +47,53 @@ #include <netinet/in.h> #include "test.h" +#define BUFSIZE 4096 + int fd; +/* + * meat of inetd discard service -- ignore data + */ +void +discard(int s) +{ + char buffer[BUFSIZE]; + + while ((errno = 0, read(s, buffer, sizeof(buffer)) > 0) || + errno == EINTR) + ; +} + +/* + * Listen on localhost:TEST_PORT for a connection + */ +#define TEST_PORT 9876 + +void +server(void) +{ + int sock; + int client; + int client_addr_len; + struct sockaddr_in serv_addr; + struct sockaddr client_addr; + + CHECKe(sock = socket(AF_INET, SOCK_STREAM, 0)); + bzero((char *) &serv_addr, sizeof serv_addr); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + serv_addr.sin_port = htons(TEST_PORT); + CHECKe(bind(sock, (struct sockaddr *) &serv_addr, sizeof serv_addr)); + CHECKe(listen(sock,3)); + + client_addr_len = sizeof client_addr; + CHECKe(client = accept(sock, &client_addr, &client_addr_len )); + CHECKe(close(sock)); + discard(client); + CHECKe(close(client)); + exit(0); +} + void* new_thread(void* arg) { fd_set r; @@ -75,13 +119,25 @@ main() struct sockaddr_in addr; int ret; + /* fork and have the child open a listener */ + signal(SIGCHLD, SIG_IGN); + switch (fork()) { + case 0: + server(); + exit(0); + case -1: + exit(errno); + default: + sleep(2); + } + /* Open up a TCP connection to the local discard port */ addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - addr.sin_port = htons(9); /* port 9/tcp is discard service */ + addr.sin_port = htons(TEST_PORT); CHECKe(fd = socket(AF_INET, SOCK_STREAM, 0)); - printf("main: connecting to discard port with fd %d\n", fd); + printf("main: connecting to test port with fd %d\n", fd); ret = connect(fd, (struct sockaddr *)&addr, sizeof addr); if (ret == -1) fprintf(stderr, "connect() failed: ensure that the discard port is enabled for inetd(8)\n"); diff --git a/regress/lib/libpthread/close/close.c b/regress/lib/libpthread/close/close.c index 2e21ecf1e47..e92c5c3f9c2 100644 --- a/regress/lib/libpthread/close/close.c +++ b/regress/lib/libpthread/close/close.c @@ -1,4 +1,4 @@ -/* $OpenBSD: close.c,v 1.2 2001/09/20 16:43:15 todd Exp $ */ +/* $OpenBSD: close.c,v 1.3 2002/02/15 23:36:52 marc Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996 by Chris Provenzano and contributors, * proven@mit.edu All rights reserved. @@ -34,8 +34,7 @@ /* * Test the semantics of close() while a select() is happening. - * Not a great test. You need the 'discard' service running in inetd for - * this to work. + * Not a great test. */ #include <pthread.h> @@ -48,8 +47,53 @@ #include <netinet/in.h> #include "test.h" +#define BUFSIZE 4096 + int fd; +/* + * meat of inetd discard service -- ignore data + */ +void +discard(int s) +{ + char buffer[BUFSIZE]; + + while ((errno = 0, read(s, buffer, sizeof(buffer)) > 0) || + errno == EINTR) + ; +} + +/* + * Listen on localhost:TEST_PORT for a connection + */ +#define TEST_PORT 9876 + +void +server(void) +{ + int sock; + int client; + int client_addr_len; + struct sockaddr_in serv_addr; + struct sockaddr client_addr; + + CHECKe(sock = socket(AF_INET, SOCK_STREAM, 0)); + bzero((char *) &serv_addr, sizeof serv_addr); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + serv_addr.sin_port = htons(TEST_PORT); + CHECKe(bind(sock, (struct sockaddr *) &serv_addr, sizeof serv_addr)); + CHECKe(listen(sock,3)); + + client_addr_len = sizeof client_addr; + CHECKe(client = accept(sock, &client_addr, &client_addr_len )); + CHECKe(close(sock)); + discard(client); + CHECKe(close(client)); + exit(0); +} + void* new_thread(void* arg) { fd_set r; @@ -75,13 +119,25 @@ main() struct sockaddr_in addr; int ret; + /* fork and have the child open a listener */ + signal(SIGCHLD, SIG_IGN); + switch (fork()) { + case 0: + server(); + exit(0); + case -1: + exit(errno); + default: + sleep(2); + } + /* Open up a TCP connection to the local discard port */ addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - addr.sin_port = htons(9); /* port 9/tcp is discard service */ + addr.sin_port = htons(TEST_PORT); CHECKe(fd = socket(AF_INET, SOCK_STREAM, 0)); - printf("main: connecting to discard port with fd %d\n", fd); + printf("main: connecting to test port with fd %d\n", fd); ret = connect(fd, (struct sockaddr *)&addr, sizeof addr); if (ret == -1) fprintf(stderr, "connect() failed: ensure that the discard port is enabled for inetd(8)\n"); |