Subject: Re: Strange behavious of getpeername(2) on pipe
To: Martin J. Laubach <mjl@emsi.priv.at>
From: Jason R Thorpe <thorpej@zembu.com>
List: tech-kern
Date: 03/27/2001 08:02:20
On Tue, Mar 27, 2001 at 03:22:05PM +0200, Martin J. Laubach wrote:

 > 	if(getpeername(fd) != 0 && errno == ENOTCONN)
 > 		{
 > 		... fastcgi, input comes via socket and special protocol ...
 > 		}
 > 	else
 > 		{
 > 		... normal cgi, input comes via pipe ...
 > 		}
 > 
 >   Unfortunately, this works on all tested unixoid systems (Solaris 7,
 > AIX, SINIS, FreeBSD, even OpenBSD!) but not on NetBSD.

The code is making an unwarranted assumption about the implementation
of pipes.  pipe(2) has been implemented using sockets for a very long
time in BSD.  FreeBSD has a separate implementation, which OpenBSD also
uses.  However, BSD/OS still uses sockets for pipes, and I believe Tru64
does as well.

Note that the X/Open definition of pipe(2) leaves a lot of flexibility
for how they are to be implemented -- NetBSD is perfectly within spec
using sockets to implement pipes.

 >   Therefore: ist our behaviour correct, and if so, what work-arounds
 > are possible?
 > 
 > 	mjl

-- 
        -- Jason R. Thorpe <thorpej@zembu.com>