Lines Matching refs:pgrp
164 static void orphanpg(struct pgrp *pg);
169 static void pgrp_add(struct pgrp * pgrp, proc_t parent, proc_t child);
171 static void pgrp_replace(proc_t p, struct pgrp *pgrp);
172 static void pgdelete_dropref(struct pgrp *pgrp);
175 extern void pg_rele_dropref(struct pgrp * pgrp);
178 struct pgrp * pg;
851 struct pgrp *
854 struct pgrp * pgrp;
857 pgrp = pgfind_internal(pgid);
858 if ((pgrp == NULL) || ((pgrp->pg_listflags & PGRP_FLAG_TERMINATE) != 0))
859 pgrp = PGRP_NULL;
861 pgrp->pg_refcount++;
863 return(pgrp);
868 struct pgrp *
871 struct pgrp *pgrp;
873 for (pgrp = PGRPHASH(pgid)->lh_first; pgrp != 0; pgrp = pgrp->pg_hash.le_next)
874 if (pgrp->pg_id == pgid)
875 return (pgrp);
880 pg_rele(struct pgrp * pgrp)
882 if(pgrp == PGRP_NULL)
884 pg_rele_dropref(pgrp);
888 pg_rele_dropref(struct pgrp * pgrp)
891 if ((pgrp->pg_refcount == 1) && ((pgrp->pg_listflags & PGRP_FLAG_TERMINATE) == PGRP_FLAG_TERMINATE)) {
893 pgdelete_dropref(pgrp);
897 pgrp->pg_refcount--;
932 struct pgrp * pg;
964 struct pgrp *pgrp;
965 struct pgrp *mypgrp;
968 pgrp = pgfind(pgid);
973 if (pgrp != NULL && mksess) /* firewalls */
974 panic("enterpgrp: setsid into non-empty pgrp");
978 if (pgrp == PGRP_NULL) {
986 panic("enterpgrp: new pgrp and pid != pgid");
988 MALLOC_ZONE(pgrp, struct pgrp *, sizeof(struct pgrp), M_PGRP,
990 if (pgrp == NULL)
999 FREE_ZONE(pgrp, sizeof(struct pgrp), M_PGRP);
1028 pgrp->pg_session = sess;
1035 pgrp->pg_session = procsp;
1037 if ((pgrp->pg_session->s_listflags & (S_LIST_TERM | S_LIST_DEAD)) != 0)
1039 pgrp->pg_session->s_count++;
1042 pgrp->pg_id = pgid;
1043 lck_mtx_init(&pgrp->pg_mlock, proc_lck_grp, proc_lck_attr);
1044 LIST_INIT(&pgrp->pg_members);
1045 pgrp->pg_membercnt = 0;
1046 pgrp->pg_jobc = 0;
1048 pgrp->pg_refcount = 1;
1049 pgrp->pg_listflags = 0;
1050 LIST_INSERT_HEAD(PGRPHASH(pgid), pgrp, pg_hash);
1052 } else if (pgrp == mypgrp) {
1053 pg_rele(pgrp);
1068 fixjobc(p, pgrp, 1);
1073 pgrp_replace(p, pgrp);
1074 pg_rele(pgrp);
1094 pgdelete_dropref(struct pgrp *pgrp)
1102 pgrp_lock(pgrp);
1103 if (pgrp->pg_membercnt != 0) {
1106 pgrp_unlock(pgrp);
1109 pgrp->pg_refcount--;
1110 if ((emptypgrp == 0) || (pgrp->pg_membercnt != 0)) {
1115 pgrp->pg_listflags |= PGRP_FLAG_TERMINATE;
1117 if (pgrp->pg_refcount > 0) {
1122 pgrp->pg_listflags |= PGRP_FLAG_DEAD;
1123 LIST_REMOVE(pgrp, pg_hash);
1129 ttyp = pgrp->pg_session->s_ttyp;
1130 if ((ttyp != NULL) && (pgrp->pg_session->s_ttyp->t_pgrp == pgrp)) {
1131 pgrp->pg_session->s_ttyp->t_pgrp = NULL;
1132 pgrp->pg_session->s_ttypgrpid = NO_PID;
1138 sessp = pgrp->pg_session;
1161 lck_mtx_destroy(&pgrp->pg_mlock, proc_lck_grp);
1162 FREE_ZONE(pgrp, sizeof(*pgrp), M_PGRP);
1167 * Adjust pgrp jobc counters when specified process changes process group.
1180 struct pgrp * pg, *hispg;
1213 fixjobc(proc_t p, struct pgrp *pgrp, int entering)
1215 struct pgrp *hispgrp = PGRP_NULL;
1217 struct session *mysession = pgrp->pg_session;
1233 if ((hispgrp != pgrp) &&
1235 pgrp_lock(pgrp);
1237 pgrp->pg_jobc++;
1238 pgrp_unlock(pgrp);
1239 }else if (--pgrp->pg_jobc == 0) {
1240 pgrp_unlock(pgrp);
1241 orphanpg(pgrp);
1243 pgrp_unlock(pgrp);
1256 fjarg.pg = pgrp;
1268 orphanpg(struct pgrp * pgrp)
1274 if (pgrp == PGRP_NULL)
1277 pgrp_lock(pgrp);
1278 for (p = pgrp->pg_members.lh_first; p != 0; p = p->p_pglist.le_next) {
1280 for (p = pgrp->pg_members.lh_first; p != 0;
1286 pgrp_unlock(pgrp);
1296 pgrp_lock(pgrp);
1297 for (p = pgrp->pg_members.lh_first; p != 0;
1300 for (p = pgrp->pg_members.lh_first; p != 0;
1310 pgrp_unlock(pgrp);
2029 pgrp_iterate(pgrp, flags, callout, arg, filterfn, filterarg)
2030 struct pgrp *pgrp;
2049 if (pgrp == 0)
2051 count = pgrp->pg_membercnt + 10;
2058 pgrp_lock(pgrp);
2060 while ((pgrp->pg_listflags & PGRP_FLAG_ITERABEGIN) == PGRP_FLAG_ITERABEGIN) {
2061 pgrp->pg_listflags |= PGRP_FLAG_ITERWAIT;
2062 msleep(&pgrp->pg_listflags, &pgrp->pg_mlock, 0, "pgrp_iterate", 0);
2064 pgrp->pg_listflags |= PGRP_FLAG_ITERABEGIN;
2067 pgid = pgrp->pg_id;
2070 for (p = pgrp->pg_members.lh_first; p != 0;
2081 pgrp_unlock(pgrp);
2083 pg_rele(pgrp);
2118 pgrp_lock(pgrp);
2119 pgrp->pg_listflags &= ~PGRP_FLAG_ITERABEGIN;
2120 if ((pgrp->pg_listflags & PGRP_FLAG_ITERWAIT) == PGRP_FLAG_ITERWAIT) {
2121 pgrp->pg_listflags &= ~PGRP_FLAG_ITERWAIT;
2122 wakeup(&pgrp->pg_listflags);
2124 pgrp_unlock(pgrp);
2126 pg_rele(pgrp);
2133 pgrp_add(struct pgrp * pgrp, struct proc * parent, struct proc * child)
2136 child->p_pgrp = pgrp;
2137 child->p_pgrpid = pgrp->pg_id;
2140 * When pgrp is being freed , a process can still
2143 * Safe to hold lock due to refcount on pgrp
2145 if ((pgrp->pg_listflags & (PGRP_FLAG_TERMINATE | PGRP_FLAG_DEAD)) == PGRP_FLAG_TERMINATE) {
2146 pgrp->pg_listflags &= ~PGRP_FLAG_TERMINATE;
2149 if ((pgrp->pg_listflags & PGRP_FLAG_DEAD) == PGRP_FLAG_DEAD)
2150 panic("pgrp_add : pgrp is dead adding process");
2153 pgrp_lock(pgrp);
2154 pgrp->pg_membercnt++;
2158 LIST_INSERT_HEAD(&pgrp->pg_members, child, p_pglist);
2160 pgrp_unlock(pgrp);
2163 if (((pgrp->pg_listflags & (PGRP_FLAG_TERMINATE | PGRP_FLAG_DEAD)) == PGRP_FLAG_TERMINATE) && (pgrp->pg_membercnt != 0)) {
2164 pgrp->pg_listflags &= ~PGRP_FLAG_TERMINATE;
2172 struct pgrp * pg;
2207 pgrp_replace(struct proc * p, struct pgrp * newpg)
2209 struct pgrp * oldpg;
2254 * When pgrp is being freed , a process can still
2257 * Safe to hold lock due to refcount on pgrp
2264 panic("pgrp_add : pgrp is dead adding process");
2287 pgrp_lock(struct pgrp * pgrp)
2289 lck_mtx_lock(&pgrp->pg_mlock);
2293 pgrp_unlock(struct pgrp * pgrp)
2295 lck_mtx_unlock(&pgrp->pg_mlock);
2311 struct pgrp *
2314 struct pgrp * pgrp;
2325 pgrp = p->p_pgrp;
2327 assert(pgrp != NULL);
2329 if ((pgrp->pg_listflags & (PGRP_FLAG_TERMINATE | PGRP_FLAG_DEAD)) != 0)
2330 panic("proc_pgrp: ref being povided for dead pgrp");
2332 if (pgrp != PGRP_NULL)
2333 pgrp->pg_refcount++;
2336 return(pgrp);
2339 struct pgrp *
2342 struct pgrp * pg = PGRP_NULL;
2349 panic("tty_pgrp: ref being povided for dead pgrp");