Saint Aardvark has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a CGI program (Apache running on FreeBSD) that will write some output to a file. This part is causing me no end of headaches:

sub write_list { my $outfile = "/home/foo/bar"; open (OUT, ">$outfile") or &print_error ("Can't open $outfile: + $!"); foreach $i (@changes) { print OUT $i; } close (OUT) or print_error ("Can't close $file properly: $!"); }
Opening the file is fine. Writing to the file is fine (I can cat the file and see what I expected; @changes is global, which prob. isn't the best way to do it but doesn't seem to be relevant here). Closing the file gives an error: "Error: Can't close /home/foo/bar properly: Bad file descriptor."

I've tried chmod'ing the file 777. I've tried making the group ownership www (group of the user running Apache). Both have no effect. I can't seem to find any information on this problem with close(). Can anyone fill me in on what I'm doing wrong?

I am now blessing your keyboard...

Replies are listed 'Best First'.
Re: close() gives bad file descriptor error
by Zaxo (Archbishop) on Feb 01, 2002 at 01:31 UTC

    Check permissions on the parent directory. When you write a new file, a directory inode must be updated. Bad permissions on home directories are a pretty common misconfiguration.

    After Compline,
    Zaxo