Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Aug 2002 10:20:11 -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:  <200208281720.g7SHKBo7015655@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: Daniel Eischen <eischen@pcnet1.pcnet.com>
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 <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 <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
 #include <time.h>
 #include <err.h>
 
 #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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208281720.g7SHKBo7015655>