setting close-on-exec flag for Linux::Inotify2?
Eric Wong
e at 80x24.org
Wed Jul 28 01:04:41 CEST 2021
Hi all, I noticed an inotify FD was being inadvertantly passed
to an exec-ed child process, unlike every other FD in a Perl
process (due to $^F).
Using Perl open()/IO::Handle->new_from_fd for the fcntl perlop
works, but the Perl handle needs to be kept around for as long
as the Linux::Inotify2 object lives to avoid close() on DESTROY.
At DESTROY, either Linux::Inotify2 or the Perl handle will hit
an close(2) EBADF error. That's fine for single-threaded code
(and I'm not touching threads w/ Perl), but maybe there's a
better way to go about this...
Since close-on-exec is a file descriptor flag, I can't even
POSIX::dup() it and change the file description on the dup'ed
FD like I could with the O_NONBLOCK flag.
It'd be nice to change the default and just set it automatically
after inotify_init (or use inotify_init2 for newer kernels),
respecting $^F. It probably won't break anything, especially
since every other FD >2 has FD_CLOEXEC set in Perl.
Thoughts?
More information about the perl
mailing list