* Return a locked process given a process descriptor, or ESRCH if it has * died. */
| 121 | * died. |
| 122 | */ |
| 123 | int |
| 124 | procdesc_find(struct thread *td, int fd, cap_rights_t *rightsp, |
| 125 | struct proc **p) |
| 126 | { |
| 127 | struct procdesc *pd; |
| 128 | struct file *fp; |
| 129 | int error; |
| 130 | |
| 131 | error = fget(td, fd, rightsp, &fp); |
| 132 | if (error) |
| 133 | return (error); |
| 134 | if (fp->f_type != DTYPE_PROCDESC) { |
| 135 | error = EBADF; |
| 136 | goto out; |
| 137 | } |
| 138 | pd = fp->f_data; |
| 139 | sx_slock(&proctree_lock); |
| 140 | if (pd->pd_proc != NULL) { |
| 141 | *p = pd->pd_proc; |
| 142 | PROC_LOCK(*p); |
| 143 | } else |
| 144 | error = ESRCH; |
| 145 | sx_sunlock(&proctree_lock); |
| 146 | out: |
| 147 | fdrop(fp, td); |
| 148 | return (error); |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Function to be used by procstat(1) sysctls when returning procdesc |