You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Harry Plate <ha...@plate.net> on 2006/10/30 20:25:09 UTC

print() on closed filehandle

Apache 2.0.52
Perl 5.8.5

I have 2 systems running identical perl software. One system is RedHat
Enterprise Linux 4, and the other is RedHat WS Linux 4.

The only issue that I am currently dealing with is the (in)ability to open
an existing log file in the folder /var/log from a .pl script:

open (LOGFILE, ">>junk.log") ;

Ea print on LOGFILE results in the error:

...print() on closed filehandle LOGFILE at /var/www/cgi-bin/test.pl ....

The "WS" system has no problems writing to LOGFILE , whereas the enterprise
system fails.

The /var/log folder permissions are wide open, as well as the permissions of
the log file itself;

Nor can I write to /tmp/junk.log, or ./junk.log ...

Yet I can use perl to write to a file when I log into the the system as a
normal user:
%perl -W
open (LOG, ">>/var/log/junk.log");
print LOG "this is a test\n" ;
^D

---and this works just as expected.


It would appear that, under Apache, perl's io system has been constrained,
disabled, broken, or ??

I've compared the httpd.conf, and perl.conf files, and they are identical;

Googling has not been very helpful; found some discussion about
"perlio-enabled", but that appears to be related to some "APR" sub module.
(havent got a clue what that is!)

Can anyone offer a clue? Is there a configuration setting that addresses
this?

-harry



Re: print() on closed filehandle

Posted by Clinton Gormley <cl...@traveljury.com>.
what error is the open giving? 
> open (LOGFILE, ">>junk.log") ;

open (LOGFILE, ">>junk.log") 
    or die "Couldn't open junk.log for appending : $!";

Also, it may be that somewhere LOGFILE is defined as a constant, and so
the bare filehandle LOGFILE is being interpreted as LOGFILE()

Rather use lexical file handles.

Clint


Re: print() on closed filehandle

Posted by Frank Wiles <fr...@wiles.org>.
On Mon, 30 Oct 2006 13:15:32 -0700
Harry Plate <ha...@automaticduck.com> wrote:

> Peter,
> 
> > 
> > You can also temporarily disable SELinux by doing:
> > 
> > echo '0' > /selinux/enforce
> > 
> 
> Bingo! That was it!
> 
> So, I don't see any SELinux configuration (within Webmin, at least).
> I need to learn more about it ... How does one disable it at boot
> time? That would be a good temporary solution.

   IIRC you were running RHEL 4, so to turn it off on boot edit
   the file: 

   /etc/sysconfig/selinux 

   and set: 

   SELINUX=disabled 

   and it won't be started on boot.  Just an FYI, but you can also turn
   it off at runtime by running the following command: 
 
   setenforce 0 

   Hope that helps! 

 ---------------------------------
   Frank Wiles <fr...@wiles.org>
   http://www.wiles.org
 ---------------------------------


Re: print() on closed filehandle

Posted by Harry Plate <ha...@automaticduck.com>.
Peter,

> 
> You can also temporarily disable SELinux by doing:
> 
> echo '0' > /selinux/enforce
> 

Bingo! That was it!

So, I don't see any SELinux configuration (within Webmin, at least). I need
to learn more about it ... How does one disable it at boot time? That would
be a good temporary solution.

-h



Re: print() on closed filehandle

Posted by Peter Rosenthal <vo...@gmail.com>.
SELinux is certainly included in RHEL 4 (though it is an option at install
time whether it is enabled or not). Check your message log for avc failures.
e.g.:

kernel: audit(1162240773.996:667): avc:  denied  { write } for  pid=23025
comm="httpd" name="dprof" dev=dm-0 ino=24282699
scontext=root:system_r:httpd_t tcontext=root:object_r:httpd_config_t
tclass=dir

You can also temporarily disable SELinux by doing:

echo '0' > /selinux/enforce

On 30/10/06, Perrin Harkins <pe...@elem.com> wrote:
>
> On Mon, 2006-10-30 at 12:47 -0700, Harry Plate wrote:
> > *** Cannot open log file, Permission denied at
> /var/www/cgi-bin/test.pl...
> [...]
> > Note the folder and file permissions are wide open; so I would next
> expect
> > that the unix fs is *not* the one that is complaining...
>
> I think it probably is your fs.  Try becoming the user that you run your
> web server as and see if you can write to that directory.  I suspect
> there is an enclosing directory higher up that doesn't have the right
> permissions.
>
> > So is there some kind of mod_perl/Apache setting that is unique to the
> RH
> > Enterprise Linux 4 (vs RH WS 4) ?
>
> There's nothing in mod_perl or Apache, but Red Hat includes SELinux in
> Fedora Core.  Not sure if that's in RHEL 4 or not.
>
> - Perrin
>
>

Re: print() on closed filehandle

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2006-10-30 at 12:47 -0700, Harry Plate wrote:
> *** Cannot open log file, Permission denied at /var/www/cgi-bin/test.pl...
[...]
> Note the folder and file permissions are wide open; so I would next expect
> that the unix fs is *not* the one that is complaining...

I think it probably is your fs.  Try becoming the user that you run your
web server as and see if you can write to that directory.  I suspect
there is an enclosing directory higher up that doesn't have the right
permissions.

> So is there some kind of mod_perl/Apache setting that is unique to the RH
> Enterprise Linux 4 (vs RH WS 4) ?

There's nothing in mod_perl or Apache, but Red Hat includes SELinux in
Fedora Core.  Not sure if that's in RHEL 4 or not.

- Perrin


Re: print() on closed filehandle

Posted by Harry Plate <ha...@plate.net>.
> You ought to test if the file is really open first, and you will hopefully
> get a more helpful error message:
> 
> open(LOGFILE, ">>junk.log") or die "Cannot open logfile, $!";
> 

Good suggestion; so I add the "die" and I get the error:

*** Cannot open log file, Permission denied at /var/www/cgi-bin/test.pl...

Which certainly confirms my theory:

> It would appear that, under Apache, perl's io system has been constrained,
> disabled, broken, or ??

Note the folder and file permissions are wide open; so I would next expect
that the unix fs is *not* the one that is complaining...

So is there some kind of mod_perl/Apache setting that is unique to the RH
Enterprise Linux 4 (vs RH WS 4) ?

Again, I compared the httpd.conf and perl.conf are identical on the 2
servers.

-harry



Re: print() on closed filehandle

Posted by "Dondi M. Stroma" <ds...@verizon.net>.
You ought to test if the file is really open first, and you will hopefully 
get a more helpful error message:

open(LOGFILE, ">>junk.log") or die "Cannot open logfile, $!";