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

Function enterpgrp

freebsd/kern/kern_proc.c:570–626  ·  view source on GitHub ↗

* Create a new process group. * pgid must be equal to the pid of p. * Begin a new session if required. */

Source from the content-addressed store, hash-verified

568 * Begin a new session if required.
569 */
570int
571enterpgrp(struct proc *p, pid_t pgid, struct pgrp *pgrp, struct session *sess)
572{
573
574 sx_assert(&proctree_lock, SX_XLOCKED);
575
576 KASSERT(pgrp != NULL, ("enterpgrp: pgrp == NULL"));
577 KASSERT(p->p_pid == pgid,
578 ("enterpgrp: new pgrp and pid != pgid"));
579 KASSERT(pgfind(pgid) == NULL,
580 ("enterpgrp: pgrp with pgid exists"));
581 KASSERT(!SESS_LEADER(p),
582 ("enterpgrp: session leader attempted setpgrp"));
583
584 if (sess != NULL) {
585 /*
586 * new session
587 */
588 mtx_init(&sess->s_mtx, "session", NULL, MTX_DEF);
589 PROC_LOCK(p);
590 p->p_flag &= ~P_CONTROLT;
591 PROC_UNLOCK(p);
592 PGRP_LOCK(pgrp);
593 sess->s_leader = p;
594 sess->s_sid = p->p_pid;
595 proc_id_set(PROC_ID_SESSION, p->p_pid);
596 refcount_init(&sess->s_count, 1);
597 sess->s_ttyvp = NULL;
598 sess->s_ttydp = NULL;
599 sess->s_ttyp = NULL;
600 bcopy(p->p_session->s_login, sess->s_login,
601 sizeof(sess->s_login));
602 pgrp->pg_session = sess;
603 KASSERT(p == curproc,
604 ("enterpgrp: mksession and p != curproc"));
605 } else {
606 pgrp->pg_session = p->p_session;
607 sess_hold(pgrp->pg_session);
608 PGRP_LOCK(pgrp);
609 }
610 pgrp->pg_id = pgid;
611 proc_id_set(PROC_ID_GROUP, p->p_pid);
612 LIST_INIT(&pgrp->pg_members);
613 pgrp->pg_flags = 0;
614
615 /*
616 * As we have an exclusive lock of proctree_lock,
617 * this should not deadlock.
618 */
619 LIST_INSERT_HEAD(PGRPHASH(pgid), pgrp, pg_hash);
620 SLIST_INIT(&pgrp->pg_sigiolst);
621 PGRP_UNLOCK(pgrp);
622
623 doenterpgrp(p, pgrp);
624
625 return (0);
626}
627

Callers 2

sys_setsidFunction · 0.85
sys_setpgidFunction · 0.85

Calls 6

mtx_initFunction · 0.85
proc_id_setFunction · 0.85
refcount_initFunction · 0.85
sess_holdFunction · 0.85
doenterpgrpFunction · 0.85
pgfindFunction · 0.70

Tested by

no test coverage detected