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)
31 if(up != p && p->noteid == noteid && p->kp == 0) {
33 if(p->pid == 0 || p->noteid != noteid){
38 postnote(p, 0, buf, flag);
51 p = smalloc(sizeof(Pgrp));
53 p->pgrpid = incref(&pgrpid);
62 r = smalloc(sizeof(Rgrp));
77 Mhead **h, **e, *f, *next;
86 e = &p->mnthash[MNTHASH];
87 for(h = p->mnthash; h < e; h++) {
88 for(f = *h; f; f = next) {
104 pgrpinsert(Mount **order, Mount *m)
113 for(f = *order; f; f = f->order) {
114 if(m->mountid < f->mountid) {
125 * pgrpcpy MUST preserve the mountid allocation order of the parent group
128 pgrpcpy(Pgrp *to, Pgrp *from)
131 Mount *n, *m, **link, *order;
132 Mhead *f, **tom, **l, *mh;
137 for(i = 0; i < MNTHASH; i++) {
139 for(f = from->mnthash[i]; f; f = f->hash) {
141 mh = newmhead(f->from);
145 for(m = f->mount; m; m = m->next) {
146 n = newmount(mh, m->to, m->mflag, m->spec);
148 pgrpinsert(&order, m);
156 * Allocate mount ids in the same sequence as the parent group
159 for(m = order; m; m = m->order)
160 m->copy->mountid = mountid.ref++;
172 new = smalloc(sizeof(Fgrp));
174 new->fd = smalloc(DELTAFD*sizeof(Chan*));
181 /* Make new fd list shorter if possible, preserving quantization */
182 new->nfd = f->maxfd+1;
183 i = new->nfd%DELTAFD;
185 new->nfd += DELTAFD - i;
186 new->fd = malloc(new->nfd*sizeof(Chan*));
190 error("no memory for fgrp");
194 new->maxfd = f->maxfd;
195 for(i = 0; i <= f->maxfd; i++) {
219 * If we get into trouble, forceclosefgrp
223 for(i = 0; i <= f->maxfd; i++)
228 up->closingfgrp = nil;
235 * Called from sleep because up is in the middle
236 * of closefgrp and just got a kill ctl message.
237 * This usually means that up has wedged because
238 * of some kind of deadly embrace with mntclose
239 * trying to talk to itself. To break free, hand the
240 * unclosed channels to the close queue. Once they
241 * are finished, the blocked cclose that we've
242 * interrupted will finish by itself.
251 if(up->procctl != Proc_exitme || up->closingfgrp == nil){
252 print("bad forceclosefgrp call");
257 for(i = 0; i <= f->maxfd; i++)
266 newmount(Mhead *mh, Chan *to, int flag, char *spec)
270 m = smalloc(sizeof(Mount));
274 m->mountid = incref(&mountid);
277 kstrdup(&m->spec, spec);
298 resrcwait(char *reason)
302 static ulong lastwhine;
309 up->psstate = reason;
311 /* don't tie up the console with complaints */
312 if(now - lastwhine > Whinesecs) {
314 print("%s\n", reason);
318 tsleep(&up->sleep, return0, 0, 300);