Hi all; first time here but I've been hacking Perl for many years (and UNIX for even longer). I have a super-bizarre problem that I hope some Perl or UNIX guru can advise me on.
I wrote some code back in 2007 that wants to find out the maximum # of bytes I can write to a pipe without it blocking (I want to know the pipe buffer size). So, I have this:
my ($rd, $wd, $sz); pipe($rd, $wd) or die "pipe(print): $!\n"; $sz = fpathconf($wd, _PC_PIPE_BUF) or die "fpathconf(pipe): $!\n";
Now, this has worked fine ever since. I'm running it on Red Hat EL 4 (Perl 5.8.5 32bit) and Red Hat EL 5 (Perl 5.8.8 64bit). Lately, for reasons I can't figure out, the second die() above is firing due to fpathconf failure, with an error code of "Bad file descriptor". This doesn't happen every time, and it's happening across different systems at different times, etc. Nothing in the above code has changed. I'm not aware of anything systematic that has changed on any of these systems but I don't have direct control over them.
I'm really stumped. I don't understand how the fpathconf() can fail with "Bad file descriptor", after the pipe() just succeeded in the previous line (the pipe() never fails that I've seen). I added code to print fileno($wd) and it was just "5" (nothing huge like I'm running out of FDs).
To try to harden the code I modified it so that if the fpathconf() fails on the write FD then I try it on the read FD. If that fails I choose a small value (512--on Linux this value is actually 4096) and continue rather than dying. I left some warning messages in for now so I could see if the problem is still happening. I've seen the fpathconf() on the write FD failing, then the fpathconf() on the read FD succeeds! I don't know (since the problem is intermittent and I have no way to reliably reproduce it) if this really fixes the problem or if I was just lucky. And, I have no idea WHY this would be the case
I'm hoping someone who knows more about the guts of this can give me some thoughts on how to handle it.
In reply to Why does fpathconf give "bad file descriptor"? by madscientist
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |