2 #include "../port/lib.h"
6 #include "../port/error.h"
9 Whinesecs = 10, /* frequency of out-of-resources printing */
16 pgrpnote(ulong noteid, char *a, long n, int flag)
27 for(ep = p+conf.nproc; p < ep; p++) {
30 if(up != p && p->noteid == noteid && p->kp == 0) {
32 if(p->noteid == noteid)
33 postnote(p, 0, buf, flag);
44 p = smalloc(sizeof(Pgrp));
46 p->pgrpid = incref(&pgrpid);
55 r = smalloc(sizeof(Rgrp));
70 Mhead **h, **e, *f, *next;
79 e = &p->mnthash[MNTHASH];
80 for(h = p->mnthash; h < e; h++) {
81 for(f = *h; f; f = next) {
97 pgrpinsert(Mount **order, Mount *m)
106 for(f = *order; f; f = f->order) {
107 if(m->mountid < f->mountid) {
118 * pgrpcpy MUST preserve the mountid allocation order of the parent group
121 pgrpcpy(Pgrp *to, Pgrp *from)
124 Mount *n, *m, **link, *order;
125 Mhead *f, **tom, **l, *mh;
130 for(i = 0; i < MNTHASH; i++) {
132 for(f = from->mnthash[i]; f; f = f->hash) {
134 mh = newmhead(f->from);
138 for(m = f->mount; m; m = m->next) {
139 n = newmount(mh, m->to, m->mflag, m->spec);
141 pgrpinsert(&order, m);
149 * Allocate mount ids in the same sequence as the parent group
152 for(m = order; m; m = m->order)
153 m->copy->mountid = mountid.ref++;
165 new = smalloc(sizeof(Fgrp));
167 new->fd = smalloc(DELTAFD*sizeof(Chan*));
174 /* Make new fd list shorter if possible, preserving quantization */
175 new->nfd = f->maxfd+1;
176 i = new->nfd%DELTAFD;
178 new->nfd += DELTAFD - i;
179 new->fd = malloc(new->nfd*sizeof(Chan*));
183 error("no memory for fgrp");
187 new->maxfd = f->maxfd;
188 for(i = 0; i <= f->maxfd; i++) {
212 * If we get into trouble, forceclosefgrp
216 for(i = 0; i <= f->maxfd; i++)
221 up->closingfgrp = nil;
228 * Called from sleep because up is in the middle
229 * of closefgrp and just got a kill ctl message.
230 * This usually means that up has wedged because
231 * of some kind of deadly embrace with mntclose
232 * trying to talk to itself. To break free, hand the
233 * unclosed channels to the close queue. Once they
234 * are finished, the blocked cclose that we've
235 * interrupted will finish by itself.
244 if(up->procctl != Proc_exitme || up->closingfgrp == nil){
245 print("bad forceclosefgrp call");
250 for(i = 0; i <= f->maxfd; i++)
259 newmount(Mhead *mh, Chan *to, int flag, char *spec)
263 m = smalloc(sizeof(Mount));
267 m->mountid = incref(&mountid);
270 kstrdup(&m->spec, spec);
291 resrcwait(char *reason)
295 static ulong lastwhine;
306 up->psstate = reason;
308 /* don't tie up the console with complaints */
309 if(now - lastwhine > Whinesecs) {
311 print("%s\n", reason);
314 tsleep(&up->sleep, return0, 0, 100+nrand(200));