Print this page
XXXX adding PID information to netstat output

@@ -177,10 +177,17 @@
                 } else {
                         if (cmd == F_DUPFD_CLOEXEC) {
                                 f_setfd(retval, FD_CLOEXEC);
                         }
                 }
+
+                if (error == 0 && fp->f_vnode != NULL) {
+                        (void) VOP_IOCTL(fp->f_vnode, F_ASSOCI_PID,
+                            (intptr_t)p->p_pidp->pid_id, FKIOCTL, kcred,
+                            NULL, NULL);
+                }
+
                 goto done;
 
         case F_DUP2FD_CLOEXEC:
                 if (fdes == iarg) {
                         error = EINVAL;

@@ -213,20 +220,35 @@
                          */
                         mutex_enter(&fp->f_tlock);
                         fp->f_count++;
                         mutex_exit(&fp->f_tlock);
                         releasef(fdes);
+
+                        /* assume we have forked successfully */
+                        if (fp->f_vnode != NULL) {
+                                (void) VOP_IOCTL(fp->f_vnode, F_ASSOCI_PID,
+                                    (intptr_t)p->p_pidp->pid_id, FKIOCTL,
+                                    kcred, NULL, NULL);
+                        }
+
                         if ((error = closeandsetf(iarg, fp)) == 0) {
                                 if (cmd == F_DUP2FD_CLOEXEC) {
                                         f_setfd(iarg, FD_CLOEXEC);
                                 }
                                 retval = iarg;
                         } else {
                                 mutex_enter(&fp->f_tlock);
                                 if (fp->f_count > 1) {
                                         fp->f_count--;
                                         mutex_exit(&fp->f_tlock);
+                                        if (fp->f_vnode != NULL) {
+                                                (void) VOP_IOCTL(fp->f_vnode,
+                                                    F_DASSOC_PID,
+                                                    (intptr_t)p->p_pidp->pid_id,
+                                                    FKIOCTL, kcred, NULL, NULL);
+                                        }
+
                                 } else {
                                         mutex_exit(&fp->f_tlock);
                                         (void) closef(fp);
                                 }
                         }