* Locate process and do additional manipulations, depending on flags. */
| 501 | * Locate process and do additional manipulations, depending on flags. |
| 502 | */ |
| 503 | int |
| 504 | pget(pid_t pid, int flags, struct proc **pp) |
| 505 | { |
| 506 | struct proc *p; |
| 507 | struct thread *td1; |
| 508 | int error; |
| 509 | |
| 510 | p = curproc; |
| 511 | if (p->p_pid == pid) { |
| 512 | PROC_LOCK(p); |
| 513 | } else { |
| 514 | p = NULL; |
| 515 | if (pid <= PID_MAX) { |
| 516 | if ((flags & PGET_NOTWEXIT) == 0) |
| 517 | p = pfind_any(pid); |
| 518 | else |
| 519 | p = pfind(pid); |
| 520 | } else if ((flags & PGET_NOTID) == 0) { |
| 521 | td1 = tdfind(pid, -1); |
| 522 | if (td1 != NULL) |
| 523 | p = td1->td_proc; |
| 524 | } |
| 525 | if (p == NULL) |
| 526 | return (ESRCH); |
| 527 | if ((flags & PGET_CANSEE) != 0) { |
| 528 | error = p_cansee(curthread, p); |
| 529 | if (error != 0) |
| 530 | goto errout; |
| 531 | } |
| 532 | } |
| 533 | if ((flags & PGET_CANDEBUG) != 0) { |
| 534 | error = p_candebug(curthread, p); |
| 535 | if (error != 0) |
| 536 | goto errout; |
| 537 | } |
| 538 | if ((flags & PGET_ISCURRENT) != 0 && curproc != p) { |
| 539 | error = EPERM; |
| 540 | goto errout; |
| 541 | } |
| 542 | if ((flags & PGET_NOTWEXIT) != 0 && (p->p_flag & P_WEXIT) != 0) { |
| 543 | error = ESRCH; |
| 544 | goto errout; |
| 545 | } |
| 546 | if ((flags & PGET_NOTINEXEC) != 0 && (p->p_flag & P_INEXEC) != 0) { |
| 547 | /* |
| 548 | * XXXRW: Not clear ESRCH is the right error during proc |
| 549 | * execve(). |
| 550 | */ |
| 551 | error = ESRCH; |
| 552 | goto errout; |
| 553 | } |
| 554 | if ((flags & PGET_HOLD) != 0) { |
| 555 | _PHOLD(p); |
| 556 | PROC_UNLOCK(p); |
| 557 | } |
| 558 | *pp = p; |
| 559 | return (0); |
| 560 | errout: |
no test coverage detected