From markd@Grizzly.COM  Thu Jul 18 08:41:54 1996
Received: from scruz.net (nic.scruz.net [165.227.1.2])
          by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id IAA27524
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 18 Jul 1996 08:41:53 -0700 (PDT)
Received: from Grizzly.COM by scruz.net (8.7.3/1.34)
	id IAA12770; Thu, 18 Jul 1996 08:41:50 -0700 (PDT)
Received: (from markd@localhost) by Grizzly.COM (8.7.5/8.7.3) id UAA06069; Thu, 18 Jul 1996 20:42:46 -0700 (PDT)
Message-Id: <199607190342.UAA06069@Grizzly.COM>
Date: Thu, 18 Jul 1996 20:42:46 -0700 (PDT)
From: Mark Diekhans <markd@Grizzly.COM>
Reply-To: markd@Grizzly.COM
To: FreeBSD-gnats-submit@freebsd.org
Subject: can't send to a pipe
X-Send-Pr-Version: 3.2

>Number:         1397
>Category:       kern
>Synopsis:       can't send to a pipe
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bde
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 18 08:50:01 PDT 1996
>Closed-Date:    Sat Jun 21 09:59:46 PDT 1997
>Last-Modified:  Sat Jun 21 10:05:03 PDT 1997
>Originator:     Mark Diekhans
>Release:        FreeBSD 2.2-960612-SNAP i386
>Organization:
== Mark Diekhans <markd@grizzly.com> ==
>Environment:

>Description:

  Pipes are implemented as sockets and this is what fstat reports. However
send returns a "Socket operation on non-socket" error.  Either socket
operations should work or fstat should report the file as a FIFO, not a socket.

This worked on 2.1.


>How-To-Repeat:

#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>

int
main ()
{
    int fds [2];
    struct stat statBuf;
    char *data;

    if (pipe (fds) < 0) {
        perror ("pipe");
        exit (1);
    }
    if (fstat (fds [1], &statBuf)) {
        perror ("fstat");
        exit (1);
    }

    printf ("pipe mode is: %o\n", statBuf.st_mode);

    data = "some data to write";
    if (send (fds [1], data, strlen (data), 0) < 0) {
        perror ("but doing a send fails");
        exit (1);
    }
    exit (0);
}


>Fix:
	
Unknown.
>Release-Note:
>Audit-Trail:

From: J Wunsch <j@uriah.heep.sax.de>
To: markd@Grizzly.COM
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/1397: can't send to a pipe
Date: Thu, 18 Jul 1996 18:48:35 +0200 (MET DST)

 As Mark Diekhans wrote:
 
 >   Pipes are implemented as sockets and this is what fstat
 > reports. However send returns a "Socket operation on non-socket"
 > error.  Either socket operations should work or fstat should report
 > the file as a FIFO, not a socket.
 
 Pipes are no longer implemented as sockets.  Using socket operations
 on them was illegal all the time, even if the kernel has not been
 reporting the error.
 
 Pipes are no longer reported by fstat (i think this is an error, or
 at least an omission):
 
 j        less        6320   wd /tmp          2 drwxrwxrwt     512  r
 j        less        6320    1 /           741 crw--w----   ttyp5 rw
 j        less        6320    2 /           741 crw--w----   ttyp5 rw
 j        less        6320    3 /           348 crw-rw-rw-     tty  r
 j        uulog       6319   wd /tmp          2 drwxrwxrwt     512  r
 j        uulog       6319    0 /           741 crw--w----   ttyp5 rw
 j        uulog       6319    2 /           741 crw--w----   ttyp5 rw
 j        uulog       6319    3 /var       4758 -rw-r--r--  335307  r
 
 That's a "uulog | less", you can see that uulog's fd 1 and less' fd 0
 are not displayed at all.
 
 FIFO's are being flagged correctly:
 
 j        uulog       6339    1 /tmp         21 prwxr-xr-x       0  w
 ...
 j        cat         6338    3 /tmp         21 prwxr-xr-x       0  r
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)

From: Mark Diekhans <markd@Grizzly.COM>
To: joerg_wunsch@uriah.heep.sax.de, Bill Paul <wpaul@skynet.ctr.columbia.edu>
Cc: FreeBSD-gnats-submit@freebsd.org, bugs@freefall.freebsd.org
Subject: Re: kern/1397: can't send to a pipe
Date: Thu, 18 Jul 1996 19:10:19 -0700 (PDT)

 Hi J"org and Bill,
 
 >From: J Wunsch <j@uriah.heep.sax.de>
 
 >Pipes are no longer implemented as sockets.  Using socket operations
 >on them was illegal all the time, even if the kernel has not been
 >reporting the error.
 
 Cool, I always though sockets were a little overkill for pipes...
 
 >From: Bill Paul <wpaul@skynet.ctr.columbia.edu>
 
 >He didn't mean fstat(1), he meant fstat(2). Look at the sample source
 >he supplied: he's calling fstat(2) on one of the pipe descriptors
 >returned by pipe(2) and he says he's getting S_IFSOCK as a result.
 >However since John's new pipe code does not in fact (ab)use sockets,
 >attempts to use socket system calls on the descriptors fail. This
 >is a contradiction: if socket operations won't work, fstat(2) should
 >not identify the descriptors as S_IFSOCK.
 
 Exactly!
 
 
 >In this case, he could replace pipe(2) with socketpair(2) in the
 
 The code (a Tcl extension) I am dealing with has an open file descriptor and
 tries to figure out what to do with it, so this isn't a solution. It uses
 send on sockets since its more reliable.
 
 >application, but that doesn't change the fact that fstat(2) is reporting 
 >a bogus result. I suppose a new type has to be added (S_IPIPE?), but
 >a question (in my mind at least) of compatibility with other *BSD systems.
 
 Reporting FIFO would probably be better than SOCK, at least that wouldn't
 lead people to do the wrong thing because they think its a socket.
 
 Given all of this, the definition of S_ISFIFO probably is wrong as well:
 
 #define	S_ISFIFO(m)	(((m) & 0170000) == 0010000 || \
 			 ((m) & 0170000) == 0140000)	/* fifo or socket */
 
 
 
 Mark

From: Bruce Evans <bde@zeta.org.au>
To: markd@Grizzly.COM, wpaul@skynet.ctr.columbia.edu
Cc: FreeBSD-gnats-submit@freebsd.org, bugs@freefall.freebsd.org
Subject: Re: kern/1397: can't send to a pipe
Date: Fri, 19 Jul 1996 13:03:26 +1000

 >Reporting FIFO would probably be better than SOCK, at least that wouldn't
 >lead people to do the wrong thing because they think its a socket.
 
 >Given all of this, the definition of S_ISFIFO probably is wrong as well:
 
 >#define	S_ISFIFO(m)	(((m) & 0170000) == 0010000 || \
 >			 ((m) & 0170000) == 0140000)	/* fifo or socket */
 
 This is a kludge for nameless pipes being implemented as sockets.  There
 was no way to distinguish between a nameless pipe and a socket, at least
 using the stat classifition macros or mode bits.  Portable code will
 have to deal with this for years.  It's still in 2.1.5 and it's probably
 in many other BSD4.4-derived systems.
 
 The above #define should be changed soon.  I'm a bit worried about new
 ports and libraries being used with old kernels.
 
 Bruce
State-Changed-From-To: open->analyzed 
State-Changed-By: wosch 
State-Changed-When: Wed Sep 25 17:01:48 PDT 1996 
State-Changed-Why:  

Mr. /usr/include 


Responsible-Changed-From-To: freebsd-bugs->bde 
Responsible-Changed-By: wosch 
Responsible-Changed-When: Wed Sep 25 17:01:48 PDT 1996 
Responsible-Changed-Why:  
State-Changed-From-To: analyzed->closed 
State-Changed-By: bde 
State-Changed-When: Sat Jun 21 09:59:46 PDT 1997 
State-Changed-Why:  

Essentially a duplicate of PR1242 which I just finished fixing 
in 2.2.x and -current. 

fstat(1) was fixed earlier (revision 1.5 1996/08/24 of fstat.c 
seems to be good enough although its log message says that it is 
a quick attempt). 
>Unformatted:
