develooper Front page | perl.perl5.porters | Postings from March 2000

MachTen 4.1.4: Unnamed pipes don't have a valid file type [ID20000315.008]

From:
Dominic Dunlop
Date:
March 22, 2000 03:52
Subject:
MachTen 4.1.4: Unnamed pipes don't have a valid file type [ID20000315.008]
Message ID:
p04310102b4fe490f461d@[192.168.1.4]
[Tenon: this is for your information -- I don't have a current 
support contract.]

[Copied to Perl5 porters list and a couple of people with different 
unreconstructed BSD derivatives: please tell me how this runs on for 
you.]

This problem originally came to light in development versions of perl 
5.6.0: a lack of file type information confuses perl and makes it 
unable to tell the read/write mode of a pipe end.  The code in 
question follows line 447 of perl's doio.c, but I don't propose 
patching perl to get around the problem -- particularly so near the 
release of 5.6.0 -- as this is clearly an OS bug.  To see it, try 
this:

#include <stdio.h>
#include <sys/stat.h>
int
main(int ac, char **av)
{
   struct stat st;
   int ps[2];
   int i;

   if (pipe(ps)) {
     perror("Can't make pipes");
     exit(2);
   }
   for (i = 0; i < 2; i++) {
     if (fstat(ps[i], &st)) {
       fprintf(stderr, "Can't stat pipe end %d: ", i);
       perror(NULL);
       exit(2);
     }
     printf("%#07o: end #%d is %sa pipe\n",
            st.st_mode & 0170000, i,
            S_ISFIFO(st.st_mode) ? "" : "not ");
   }
   exit(0);
}

On MachTen, it says that neither end of the pipe is a pipe, because 
the file type field of the mode word is zero.  You can write a 
similar program which says the same about the ends of a UNIX domain 
socket pair (which is, according to BSD tradition, exactly the same 
thing as a pipe).  A program which diddles with a named pipe, on the 
other hand, gets told that it is indeed dealing with a pipe if it 
asks.

This is wrong.  BSD UNIX has traditionally been fuzzy on this issue, 
but recent UNIXes (including recent BSD derivatives) and the POSIX 
standard are clear about having a file type for pipes, assigning it 
to the information for the pipe ends when the pipe is opened, and 
having S_ISFIFO() return true for such things.


-- 
Dominic Dunlop



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About