From owner-freebsd-bugs Wed Aug 28 10:20:32 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 81E9B37B401 for ; Wed, 28 Aug 2002 10:20:11 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3416643E3B for ; Wed, 28 Aug 2002 10:20:11 -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 g7SHKBJU015656 for ; Wed, 28 Aug 2002 10:20:11 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7SHKBo7015655; Wed, 28 Aug 2002 10:20:11 -0700 (PDT) Date: Wed, 28 Aug 2002 10:20:11 -0700 (PDT) Message-Id: <200208281720.g7SHKBo7015655@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: Daniel Eischen Cc: Subject: Re: bin/42100: libc_r: accept(2) can't handle descriptor being closed/shutdown Date: Wed, 28 Aug 2002 09:54:44 -0700 Daniel Eischen wrote: > I hacked up your program a bit and it looks like the kernel Hang on.. I want to make sure I fully understand what you're saying. If it's the kernel's fault, then libc_r should have nothing to do with it, right? So I wrote another test program (below) and compiled it *without* -pthread.. There are four cases: shutdown() vs. close() and FreeBSD vs. Linux. Here is what accept() returns in these four cases: shutdown() | close() ----------------+-------------- FreeBSD EAGAIN | EBADF Linux EINVAL | EBADF So there are two conclusions: 1. FreeBSD returns EAGAIN for a file descriptor that has been shutdown(). This is at best inconsistent with Linux, but is probably plain wrong because EAGAIN has a special meaning for O_NONBLOCK file descriptors. 2. The kernel is behaving properly in the close() case, which contradicts your claim that a kernel problem is responsible for the bug in the original test program in the close() case. -Archie __________________________________________________________________________ Archie Cobbs * Packet Design * http://www.packetdesign.com ============================= CUT HERE =============================== /* Compile as: cc -o xx -Wall xx.c */ #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 #include #define USE_SHUTDOWN 1 int main(int ac, char **av) { struct sockaddr_in sin; socklen_t slen; int sock; /* 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"); /* Set socket to non-blocking */ if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) err(1, "fcntl"); /* Listen for connections on socket */ if (listen(sock, 10) == -1) err(1, "listen"); slen = sizeof(sin); printf("created socket\n"); #if USE_SHUTDOWN /* Shutdown socket */ printf("calling shutdown()\n"); if (shutdown(sock, SHUT_RDWR) == -1) err(1, "shutdown"); #else /* Close socket */ printf("calling close()\n"); if (close(sock) == -1) err(1, "close"); #endif /* Try to accept on socket */ printf("calling accept()\n"); if (accept(sock, (struct sockaddr *)&sin, &slen) == -1) err(1, "accept"); printf("got connection?\n"); return (0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message