File::Copy giving "Bad File Descriptor" from sysread

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I'm modifying a CMS modperl app (WebGUI) and am getting "Bad File
Descriptor" from a call to "copy" from the File::Copy module.

My setup- perl v5.8.2, OpenBSD OpenBSD 3.5, Apache/1.3.29 with
mod_perl/1.27, mysql 4.0.18

The problem seems to be with copying ANY file from within the app- but
if I run "perl -Mfile::Copy -de 1" I can copy the same files using
"copy" just fine.

To debug, I created a simple small text file:
echo foo > /tmp/a
chmod a+r /tmp/a

And to be sure I knew which part of File::Copy failed, I edited
       defined($r = sysread($from_h, $buf, $size))
            or goto fail_inner0;
print "Cannot sysread<br>\n";

Then I added the following to my WebGUI subroutine-
copy('/tmp/a','/tmp/b') or print "Cannot copy a to b: $! <br>\n";

which prints:
Cannot sysread
Cannot copy a to b: Bad file descriptor

It does create an empty "/tmp/b"- it can open /tmp/a for reading
without error, set it to binmode without error, can open /tmp/b for
writing without error, but then the sysread fails!

Replacing "copy('/tmp/a/','/tmp/b')" with
"system('cp','/tmp/a/','/tmp/b')" works... but it's not as portable,
and this is going to be a public patch.

and as a sanity check:
perl -MFile::Copy -e "copy ('/tmp/a','/tmp/b') or die 'Cannot copy a
to b: ',$! "
cat /tmp/b

that prints "foo"- so the copy works "simply" but fails inside the
modperl app.

Any answers? Even help on debugging this further? I'm stuck.


Site Timeline