develooper Front page | perl.perl5.porters | Postings from September 2001

Re: [ID 20010825.002] STDOUT is not flushed before exec().

Thread Previous | Thread Next
From:
Joe Smith
Date:
September 17, 2001 17:42
Subject:
Re: [ID 20010825.002] STDOUT is not flushed before exec().
Message ID:
20010917174133.A5969@tardis.tymnet.com
On Tue, Sep 18, 2001 at 02:46:45AM +0530, Abhijit Menon-Sen wrote:
> At 2001-08-25 03:30:21, jms@tardis.tymnet.com wrote:
> > 
> > #!/usr/local/bin/perl   --   # Remove trailing newline!
> > BEGIN{SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;
> > truncate$0,-1+-s$0;exec$0;}}//rekcaH_lreP_rehtona_tsuJ
> 
> I couldn't get this code to run anywhere, so I haven't been able to
> investigate your report properly, but...

If $|++ is present, it works everywhere I've tested.
But without $|++, it works on Linux, but not on Solaris.
(The code quoted above is missing the dollarsign in $SIG{}.)

I used "perl -pi -e 's/tsuJ\n/tsuJ/' test-fail.pl" to remove
the trailing linefeed after editing the file.

> > STDOUT should get explictly flushed when fflush(NULL) is broken.
> 
> util.c:Perl_my_fflush_all() should take care of this, and it is called,
> via PERL_FLUSHALL_FOR_CHILD, in all the obvious places. Does that fail
> to work correctly on your system, or is not called at all?
> 
> - ams

I don't know the answer to that question.
		-Joe

	=============

Example showing how test-fail.pl fails on Solaris:

jms@solaris% ls -l test*.pl
-rwxrwxr-x   1 inwap         134 Sep 17 17:17 test-fail.pl*
-rwxrwxr-x   1 inwap         139 Sep 17 17:13 test-good.pl*
jms@solaris% diff test*.pl
Warning: missing newline at end of file test-fail.pl
Warning: missing newline at end of file test-good.pl
2c2
< BEGIN{$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;  
---
> BEGIN{$|++;$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;  
jms@solaris% cp test-good.pl test
jms@solaris% ./test
Just another Perl Hackerjms@solaris% cp test-fail.pl test
jms@solaris% cat test-fail.pl
#!/usr/local/bin/perl5
BEGIN{$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;  
truncate$0,-1+-s$0;exec$0;}}//rekcaH_lreP_rehtona_tsuJjms@solaris% 
jms@solaris% ./test
jms@solaris% perl -v

This is perl, v5.6.1 built for sun4-solaris

Copyright 1987-2001, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

jms@solaris% uname -a
SunOS solaris 5.8 Generic_108528-09 sun4u sparc SUNW,Ultra-5_10

	=========

Example showing how test-fail.pl works on Linux

jms@linux% cp test-good.pl test
jms@linux% ./test
Just another Perl Hackerjms@linux% cp test-fail.pl test
jms@linux% ./test
Just another Perl Hackerjms@linux% 
jms@linux% 
jms@linux% diff test-good.pl test-fail.pl
2c2
< BEGIN{$|++;$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;  
---
> BEGIN{$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;  
jms@linux% cat test-fail.pl
#!/usr/local/bin/perl5
BEGIN{$SIG{__WARN__}=sub{$_=pop;y-_- -;print/".*(.)"/;  
truncate$0,-1+-s$0;exec$0;}}//rekcaH_lreP_rehtona_tsuJjms@linux% 
jms@linux% cp test-fail.pl test
jms@linux% ./test
Just another Perl Hackerjms@linux% 
jms@linux% /usr/local/bin/perl5 -v

This is perl, v5.6.1 built for i686-linux

Copyright 1987-2001, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

jms@linux% uname -a
Linux linux 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown


-- 
Joe Smith   WorldCom, Global Data Network Ops, Product Technical Support
UNIX and Tech Sup: TYMNET Network, Xstream Packet Services (Public X.25)
<Joe.Smith@wcom.com>      2560 N 1st St, MS-5046/746, San Jose, CA 95131
Voice: 408-533-6220 = vnet 854-6220    Fax: 408-533-6702 = vnet 854-6702

Thread Previous | Thread Next


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