MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pget

Function pget

freebsd/kern/kern_proc.c:503–563  ·  view source on GitHub ↗

* Locate process and do additional manipulations, depending on flags. */

Source from the content-addressed store, hash-verified

501 * Locate process and do additional manipulations, depending on flags.
502 */
503int
504pget(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);
560errout:

Callers 15

sysctl_kern_procFunction · 0.70
sysctl_kern_proc_argsFunction · 0.70
sysctl_kern_proc_envFunction · 0.70
sysctl_kern_proc_auxvFunction · 0.70
sysctl_kern_proc_sv_nameFunction · 0.70
sysctl_kern_proc_ovmmapFunction · 0.70
sysctl_kern_proc_vmmapFunction · 0.70
sysctl_kern_proc_kstackFunction · 0.70
sysctl_kern_proc_groupsFunction · 0.70
sysctl_kern_proc_rlimitFunction · 0.70

Calls 5

tdfindFunction · 0.85
pfind_anyFunction · 0.70
pfindFunction · 0.70
p_canseeFunction · 0.70
p_candebugFunction · 0.70

Tested by

no test coverage detected