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

Discussion in 'Perl Misc' started by Yary H, Oct 3, 2004.

  1. Yary H

    Yary H Guest

    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
    /usr/libdata/perl5/File/Copy.pm:
    defined($r = sysread($from_h, $buf, $size))
    or goto fail_inner0;
    ....
    fail_inner0:
    print "Cannot sysread<br>\n";
    fail_inner:
    ....

    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.

    Thanks
    -y
     
    Yary H, Oct 3, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geoff Cox

    why "bad file descriptor"?

    Geoff Cox, Dec 4, 2005, in forum: Perl
    Replies:
    1
    Views:
    8,657
    Geoff Cox
    Dec 5, 2005
  2. Kevin
    Replies:
    4
    Views:
    1,074
    David Bolen
    Jul 7, 2003
  3. Replies:
    9
    Views:
    739
    Abhijit Soman
    Jan 6, 2005
  4. Vishnu
    Replies:
    0
    Views:
    517
    Vishnu
    Jan 6, 2005
  5. sixteenmillion

    The giving that keeps on giving

    sixteenmillion, Nov 19, 2007, in forum: C Programming
    Replies:
    0
    Views:
    444
    sixteenmillion
    Nov 19, 2007
Loading...

Share This Page