Print this page
XXXX adding PID information to netstat output

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/syscall/fcntl.c
          +++ new/usr/src/uts/common/syscall/fcntl.c
↓ open down ↓ 171 lines elided ↑ open up ↑
 172  172                           */
 173  173                          mutex_enter(&fp->f_tlock);
 174  174                          fp->f_count--;
 175  175                          mutex_exit(&fp->f_tlock);
 176  176                          error = EMFILE;
 177  177                  } else {
 178  178                          if (cmd == F_DUPFD_CLOEXEC) {
 179  179                                  f_setfd(retval, FD_CLOEXEC);
 180  180                          }
 181  181                  }
      182 +
      183 +                if (error == 0 && fp->f_vnode != NULL) {
      184 +                        (void) VOP_IOCTL(fp->f_vnode, F_ASSOCI_PID,
      185 +                            (intptr_t)p->p_pidp->pid_id, FKIOCTL, kcred,
      186 +                            NULL, NULL);
      187 +                }
      188 +
 182  189                  goto done;
 183  190  
 184  191          case F_DUP2FD_CLOEXEC:
 185  192                  if (fdes == iarg) {
 186  193                          error = EINVAL;
 187  194                          goto done;
 188  195                  }
 189  196  
 190  197                  /*FALLTHROUGH*/
 191  198  
↓ open down ↓ 16 lines elided ↑ open up ↑
 208  215                           * (which we have to do anyway), then releasef(fdes),
 209  216                           * then closeandsetf().  Incrementing f_count ensures
 210  217                           * that fp won't disappear after we call releasef().
 211  218                           * When closeandsetf() fails, we try avoid calling
 212  219                           * closef() because of all the side effects.
 213  220                           */
 214  221                          mutex_enter(&fp->f_tlock);
 215  222                          fp->f_count++;
 216  223                          mutex_exit(&fp->f_tlock);
 217  224                          releasef(fdes);
      225 +
      226 +                        /*
      227 +                         * Assume we succeed to duplicate the file descriptor
      228 +                         * and associate the pid to the vnode.
      229 +                         */
      230 +                        if (fp->f_vnode != NULL) {
      231 +                                (void) VOP_IOCTL(fp->f_vnode, F_ASSOCI_PID,
      232 +                                    (intptr_t)p->p_pidp->pid_id, FKIOCTL,
      233 +                                    kcred, NULL, NULL);
      234 +                        }
      235 +
 218  236                          if ((error = closeandsetf(iarg, fp)) == 0) {
 219  237                                  if (cmd == F_DUP2FD_CLOEXEC) {
 220  238                                          f_setfd(iarg, FD_CLOEXEC);
 221  239                                  }
 222  240                                  retval = iarg;
 223  241                          } else {
 224  242                                  mutex_enter(&fp->f_tlock);
 225  243                                  if (fp->f_count > 1) {
 226  244                                          fp->f_count--;
 227  245                                          mutex_exit(&fp->f_tlock);
      246 +                                        /*
      247 +                                         * Failed to duplicate fdes,
      248 +                                         * disassociate the pid from the vnode.
      249 +                                         */
      250 +                                        if (fp->f_vnode != NULL) {
      251 +                                                (void) VOP_IOCTL(fp->f_vnode,
      252 +                                                    F_DASSOC_PID,
      253 +                                                    (intptr_t)p->p_pidp->pid_id,
      254 +                                                    FKIOCTL, kcred, NULL, NULL);
      255 +                                        }
      256 +
 228  257                                  } else {
 229  258                                          mutex_exit(&fp->f_tlock);
 230  259                                          (void) closef(fp);
 231  260                                  }
 232  261                          }
 233  262                          goto out;
 234  263                  }
 235  264                  goto done;
 236  265  
 237  266          case F_SETFL:
↓ open down ↓ 703 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX