SPUG: proper checking of file status after read? (mod_perl Apache2)

Fred Morris m3047 at inwa.net
Wed Sep 17 22:46:29 CDT 2003


Well, I got my calendar thingie working with Apache 2 (prefork model) and
mod_perl... more or less.

This would be the Apache 2, Perl 5.8 and mod_perl which ship with SuSE 8.2
for x86, plus their patches for them. (Apache ids as 2.0.46, but since SuSE
tends to retrofit patches and not change the version number, who can be
sure?). I also had to download the latest version of CGI.pm from Lincoln
Stein's website.


I suppose I might as well describe what it took:

CHANGES TO DIRECTIVES:

PerlHandler Apache::Registry becomes PerlResponseHandler ModPerl::Registry
PerlSendHeader On becomes PerlOptions +ParseHeaders

Note that the latter is probably unnecessary when using CGI.pm.

CHANGES TO @INC:

The most irritating thing is that it doesn't chdir to where the script is
executing! That may change in the future according to some doc I read
somewhere, but that's the way it is for now. This means that if you have
modules and you don't want to install them in your perl5 tree, you need to
find PerlRequire (or create one if need be) and add a use lib for the path.
SuSE 8.2 provides it as /etc/apache2/mod_perl-startup.pl.


That was really all it took. However, it doesn't seem completely stable. I
get sporadic failures where it seems like the CGI parameters didn't make it
to the script, or files don't read. The only one which actually gets logged
is Inappropriate ioctl for device. At first I thought it was always
occurring at the same place in the file (the end, maybe?) but now I see
that's not the case. Most of the time when it occurs it reports line 4 (and
there are 4 lines in the file), but one time it reported line 12! And of
course, sometimes it works.



This brings up a question about the code which is being executed, and if it
is correct.


    open( INFILE, '/path/spec') ... no errors, notice no mode == read

    while ($line = <INFILE>) {

      all ok...
    }

    if ($!) ... <--- this is what sporadically fails!


The point is to determine that the file was read ok. If not like this, then
how? Is $! unsafe/indeterminate when a file has been successfully read?

I don't see this behavior on my stable server, which is running older stuff.


If anybody's got any insights to share....

--

Fred Morris
m3047 at inwa.net





More information about the spug-list mailing list