Subject: | Handling closed file handles in KQueue.pm |
Hi Dave,
when running the File::ChangeNotify module's tests on OpenBSD, testing a
directory with circular symlinks fails since an undefined file
descriptor is passed to EV_SET() in _watch_file() in KQueue.pm.
_watch_file() tries to open a file, checks the file handle, and then
calls EV_SET() with the file handle's file descriptor:
open my $fh, '<', $file or warn "Can't open '$file': $!";
return unless $fh;
$self->_kqueue->EV_SET(
fileno($fh),
[...]
I suggest to also check whether the file handle's file descriptor is
defined. For example:
open my $fh, '<', $file or warn "Can't open '$file': $!";
return unless $fh && defined fileno($fh);
Description of fileno() in perlfunc(1):
"fileno FILEHANDLE
Returns the file descriptor for a filehandle, or undefined if
the filehandle is not open. [...]"
Regards,
Andreas
Subject: | patch-lib_File_ChangeNotify_Watcher_KQueue_pm.txt |
$OpenBSD$
--- lib/File/ChangeNotify/Watcher/KQueue.pm.orig Sun Oct 17 22:00:14 2010
+++ lib/File/ChangeNotify/Watcher/KQueue.pm Fri Dec 31 16:39:44 2010
@@ -184,7 +184,7 @@ sub _watch_file {
# Don't panic if we can't open a file
open my $fh, '<', $file or warn "Can't open '$file': $!";
- return unless $fh;
+ return unless $fh && defined fileno($fh);
# Store this filehandle (this will automatically nuke any existing events
# assigned to the file)