Date: Sat, 5 Apr 2014 12:00:43 +0200 From: Ed Schouten <ed@80386.nl> To: Robert Watson <rwatson@freebsd.org> Cc: freebsd-arch@freebsd.org Subject: [Patch] kqueue(2) <-> procdesc(4): EVFILT_PROCDESC Message-ID: <CAJOYFBBBtjRh66YLwgTwRFCXv4SRMD5zgq_bq1UZZvSMKJ9Crw@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
Hi Robert, The other day I was playing around with procdesc(4). Quite a nice piece of work. I did notice, though, that there is no way you can use kqueue(2) to monitor process descriptors. That's quite a shame, because it would be awesome if we could just use EVFILT_PROC on process descriptors directly. This is why I thought it would be nice to introduce a variant called EVFILT_PROCDESC. I initially tried altering kqueue(2) in such a way that EVFILT_PROCDESC would use a mixture of filt_fileattach() to attach to the descriptor and filt_proc() to watch for events, but this approach didn't really work out all that well, for the reason that a kevent either has a file descriptor or a process associated; not both. In the end I decided to not make things more complex than needed and just implement it like a regular file descriptor probe. This means that we can get NOTE_EXIT to work, but NOTE_FORK, NOTE_EXEC and NOTE_TRACK would require some more work. What are your thoughts on the following patch? http://80386.nl/pub/kqueue-evfilt-procdesc.txt Some notes on this patch: - I decided to just reuse the obsolete EVFILT_NETDEV. EVFILT_PROCDESC will be used on completely different file descriptor types, so I can't think of a way this would cause ABI issues. - pd->pd_proc is protected by proctree_lock. It's a bit hard to pick this up inside of the kqfilter, so simply make procdesc_exit() copy out pd->pd_proc->p_xstat. We also want this copy, because we don't want to run into a race condition where wait4() already reaps the process before the kqfilter is called. This is works for EVFILT_PROC anyway. The nice thing about this patch is that even though pdwait4(2) is still unimplemented, it does at least allow people to now extract the exit code without accessing any global namespaces. Thanks, -- Ed Schouten <ed@80386.nl>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJOYFBBBtjRh66YLwgTwRFCXv4SRMD5zgq_bq1UZZvSMKJ9Crw>