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));
76 e = &p->mnthash[MNTHASH];
77 for(h = p->mnthash; h < e; h++) {
78 while((f = *h) != nil){
92 pgrpinsert(Mount **order, Mount *m)
101 for(f = *order; f != nil; f = f->order) {
102 if(m->mountid < f->mountid) {
113 * pgrpcpy MUST preserve the mountid allocation order of the parent group
116 pgrpcpy(Pgrp *to, Pgrp *from)
118 Mount *n, *m, **link, *order;
119 Mhead *f, **tom, **l, *mh;
126 for(i = 0; i < MNTHASH; i++) {
128 for(f = from->mnthash[i]; f != nil; f = f->hash) {
130 mh = newmhead(f->from);
134 for(m = f->mount; m != nil; m = m->next) {
135 n = smalloc(sizeof(Mount));
136 n->mountid = m->mountid;
141 kstrdup(&n->spec, m->spec);
142 pgrpinsert(&order, n);
150 * Allocate mount ids in the same sequence as the parent group
152 for(m = order; m != nil; m = m->order)
153 m->mountid = incref(&mountid);
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++) {
189 if((c = f->fd[i]) != nil){
205 if(f == nil || decref(f))
209 * If we get into trouble, forceclosefgrp
213 for(i = 0; i <= f->maxfd; i++)
214 if((c = f->fd[i]) != nil){
218 up->closingfgrp = nil;
225 * Called from interrupted() because up is in the middle
226 * of closefgrp and just got a kill ctl message.
227 * This usually means that up has wedged because
228 * of some kind of deadly embrace with mntclose
229 * trying to talk to itself. To break free, hand the
230 * unclosed channels to the close queue. Once they
231 * are finished, the blocked cclose that we've
232 * interrupted will finish by itself.
241 if(up->procctl != Proc_exitme || up->closingfgrp == nil){
242 print("bad forceclosefgrp call");
247 for(i = 0; i <= f->maxfd; i++)
248 if((c = f->fd[i]) != nil){
256 newmount(Chan *to, int flag, char *spec)
260 m = smalloc(sizeof(Mount));
263 m->mountid = incref(&mountid);
266 kstrdup(&m->spec, spec);
276 while((f = m) != nil) {
285 resrcwait(char *reason)
287 static ulong lastwhine;
300 up->psstate = reason;
302 /* don't tie up the console with complaints */
303 if(now - lastwhine > Whinesecs) {
305 print("%s\n", reason);
308 tsleep(&up->sleep, return0, 0, 100+nrand(200));