From 50ed6e07131ca103b633c224c72e4a7b7e7f8e49 Mon Sep 17 00:00:00 2001 From: "Christian S.J. Peron" Date: Fri, 12 Oct 2007 14:58:34 +0000 Subject: [PATCH] Make sure that we refresh the PID on read(2) and write(2) operations. This fixes the process portion of the bpf(4) stats if the peer forks into the background after it's opened the descriptor. This bug results in the following behavior for netstat -B: # netstat -B Pid Netif Flags Recv Drop Match Sblen Hblen Command netstat: kern.proc.pid failed: No such process 78023 em0 p--s-- 2237404 43119 2237404 13986 0 ?????? MFC after: 1 week --- sys/net/bpf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 05682ff4703c..7af9f3c84b74 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -488,6 +488,7 @@ bpfread(struct cdev *dev, struct uio *uio, int ioflag) return (EINVAL); BPFD_LOCK(d); + d->bd_pid = curthread->td_proc->p_pid; if (d->bd_state == BPF_WAITING) callout_stop(&d->bd_callout); timed_out = (d->bd_state == BPF_TIMED_OUT); @@ -616,6 +617,7 @@ bpfwrite(struct cdev *dev, struct uio *uio, int ioflag) struct sockaddr dst; int error, hlen; + d->bd_pid = curthread->td_proc->p_pid; if (d->bd_bif == NULL) return (ENXIO);