Subject: Re: Cygwin /dev/null problem or perl 5.8.0 problem? (was: Re: autom4te and perl 5.8.0)
From: Nick Ing-Simmons <[email-masked]>
To: [email-masked]
Cc: "Gerrit @ cygwin" <[email-masked]>, Perl 5 Porters <[email-masked]>
Date: Thu, 20 Jun 2002 14:43:05 +0100

H.Merijn Brand <[email-masked]> writes:
>On Wed 19 Jun 2002 23:28, "Gerrit P. Haase" <[email-masked]> wrote:
>> Hallo Conrad,
>> 
>> Am Mittwoch, 19. Juni 2002 um 23:18 schriebst du:
>> 
>> > "Gerrit P. Haase" <[email-masked]> wrote:
>> 
>> Segfaulting with perl 5.8.0 on Cygwin:
>> 
>>  use IO::File;
>>  my $out = new IO::File;
>>  $out->open("/dev/null", O_CREAT | O_WRONLY | O_TRUNC, 0666);
>> 

It is a perl5.7+ problem of uncertain vintage.

The root cause is fixed by: 

--- doio.c.ship	Thu Jun 20 14:35:53 2002
+++ doio.c	Thu Jun 20 14:14:27 2002
@@ -663,7 +663,10 @@
     if (writing) {
 	if (IoTYPE(io) == IoTYPE_SOCKET
 	    || (IoTYPE(io) == IoTYPE_WRONLY && fd >= 0 && S_ISCHR(PL_statbuf.st_mode)) ) {
-	    mode[0] = 'w';
+	    char *s = mode;
+	    if (*s == 'I' || *s == '#')
+	     s++;
+	    *s = 'w';
 	    if (!(IoOFP(io) = PerlIO_openn(aTHX_ type,mode,fd,0,0,NULL,0,svp))) {
 		PerlIO_close(fp);
 		IoIFP(io) = Nullfp;

Otherwise in this case "mode" is passed as "ww" rather than "#w", PerlIOBase_push
objects and returns a NULL and we get the SEGV.

(I am testing a change which makes perlio.c more defensive with returned NULL 
as well.)

I am slightly confused by the condition though - this is the IoIFP and IoOFP need
their own PerlIO * logic - fine if it is a socket but why do we need that 
for the WRONLY case of a char-device? Did we mean RDWR case?

-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/