From owner-freebsd-bugs Tue Aug 27 18: 0:31 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1494837B40E for ; Tue, 27 Aug 2002 18:00:16 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id A7E1243E3B for ; Tue, 27 Aug 2002 18:00:15 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7S10FJU032733 for ; Tue, 27 Aug 2002 18:00:15 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7S10Fmv032732; Tue, 27 Aug 2002 18:00:15 -0700 (PDT) Date: Tue, 27 Aug 2002 18:00:15 -0700 (PDT) Message-Id: <200208280100.g7S10Fmv032732@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Archie Cobbs Subject: Re: bin/42100: libc_r: accept(2) can't handle descriptor being closed/shutdown Reply-To: Archie Cobbs Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/42100; it has been noted by GNATS. From: Archie Cobbs 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 #include #include #include #include #include #include #include #include #include #include #include #if SIGNAL_TEST static void signal_handler(int sig); #else #include 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