From owner-freebsd-arch@FreeBSD.ORG Sat Apr 5 10:00:44 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A83A2E24; Sat, 5 Apr 2014 10:00:44 +0000 (UTC) Received: from mail-qa0-x22a.google.com (mail-qa0-x22a.google.com [IPv6:2607:f8b0:400d:c00::22a]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5BA1685C; Sat, 5 Apr 2014 10:00:44 +0000 (UTC) Received: by mail-qa0-f42.google.com with SMTP id k15so4126586qaq.15 for ; Sat, 05 Apr 2014 03:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:cc:content-type; bh=KxtoKD506BfcM7fJeS6nEyuU/KK38iGXKPv3io/jw84=; b=OM9IP+IA4SI2uQ9mHwzlV09WyT0xcz+nI//660HBYTPAtN3KtBEKMzm+i5dcj56LHG gWV8NJnnPpww7tcPh8bUaUtqQxCPNCQtEeg8MIIOdSqughUKs05Ls4mMbDHF18xLp3pN BrcWMYZtIJxyLwKTgEmhm/fHlqzy8boqi9tfbMnbkdCydm9hQ8fEHPlZAeJt6CXniZ4g TCt1Qo8t4B3lE12JHxaum8oXGp+2OM2u489ZO4wameCUW0SpGDEy/HL10pMQhdfm4unJ VdYBmhdVs+nukz5XXMsidBquZ9eu+pFuCePKXnHVqwY7pGyE7zJxf3x3ZwDy4QGeCNtO l/IQ== MIME-Version: 1.0 X-Received: by 10.224.36.129 with SMTP id t1mr928918qad.88.1396692043517; Sat, 05 Apr 2014 03:00:43 -0700 (PDT) Sender: edschouten@gmail.com Received: by 10.140.96.203 with HTTP; Sat, 5 Apr 2014 03:00:43 -0700 (PDT) Date: Sat, 5 Apr 2014 12:00:43 +0200 X-Google-Sender-Auth: psMQTcnKFhi6nm-19Q5X-JQ_jd0 Message-ID: Subject: [Patch] kqueue(2) <-> procdesc(4): EVFILT_PROCDESC From: Ed Schouten To: Robert Watson Content-Type: text/plain; charset=UTF-8 Cc: freebsd-arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Apr 2014 10:00:44 -0000 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