Date: Tue, 27 Aug 2002 18:00:15 -0700 (PDT) From: Archie Cobbs <archie@packetdesign.com> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/42100: libc_r: accept(2) can't handle descriptor being closed/shutdown Message-ID: <200208280100.g7S10Fmv032732@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/42100; it has been noted by GNATS. From: Archie Cobbs <archie@packetdesign.com> To: freebsd-gnats-submit@FreeBSD.org Cc: Subject: Re: bin/42100: libc_r: accept(2) can't handle descriptor being closed/shutdown Date: Tue, 27 Aug 2002 17:51:37 -0700 Hmm.. guess I forgot to include the test program! Here it is. ============================== CUT HERE ======================== /* Set to "1" to abort on signal, or "0" for thread-based delayed abort */ #ifndef SIGNAL_TEST #define SIGNAL_TEST 1 #endif #ifdef __linux__ #define _XOPEN_SOURCE 600 #define _GNU_SOURCE 1 #define _BSD_SOURCE 1 #define _ISOC99_SOURCE 1 #endif #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <signal.h> #include <errno.h> #include <unistd.h> #include <time.h> #include <err.h> #if SIGNAL_TEST static void signal_handler(int sig); #else #include <pthread.h> static void *thread_entry(void *arg); static pthread_t tid; #endif static int sock; int main(int ac, char **av) { struct sockaddr_in sin; socklen_t slen; /* Create socket */ if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) err(1, "socket"); memset(&sin, 0, sizeof(sin)); #ifndef __linux__ sin.sin_len = sizeof(sin); #endif sin.sin_family = AF_INET; if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) err(1, "socket"); slen = sizeof(sin); if (listen(sock, 10) == -1) err(1, "listen"); #if SIGNAL_TEST /* Register signal handler */ signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); #else /* Spawn thread */ if ((errno = pthread_create(&tid, NULL, thread_entry, NULL)) != 0) err(1, "pthread_create"); #endif /* Listen for connections on socket */ printf("main: waiting for connection...\n"); if (accept(sock, (struct sockaddr *)&sin, &slen) == -1) err(1, "main: accept"); printf("main: got connection?\n"); return (0); } #if SIGNAL_TEST static void signal_handler(int sig) #else static void * thread_entry(void *arg) #endif { #if SIGNAL_TEST printf("%s: rec'd signal %d...\n", __FUNCTION__, sig); #else printf("%s: sleeping 2 seconds...\n", __FUNCTION__); sleep(2); #endif srandom(getpid() ^ time(NULL)); if ((random() & 0x00400000) != 0) { printf("%s: shutdown()'ing socket...\n", __FUNCTION__); if (shutdown(sock, SHUT_RDWR) == -1) err(1, "thread: shutdown"); } else { printf("%s: close()'ing socket...\n", __FUNCTION__); if (close(sock) == -1) err(1, "thread: shutdown"); } #if !SIGNAL_TEST return (NULL); #endif } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208280100.g7S10Fmv032732>