Annotation of lucent/sys/src/9/port/pgrp.c, revision 1.1.1.1

1.1       root        1: #include       "u.h"
                      2: #include       "../port/lib.h"
                      3: #include       "mem.h"
                      4: #include       "dat.h"
                      5: #include       "fns.h"
                      6: #include       "../port/error.h"
                      7: 
                      8: static Ref pgrpid;
                      9: static Ref mountid;
                     10: 
                     11: void
                     12: pgrpnote(ulong noteid, char *a, long n, int flag)
                     13: {
                     14:        Proc *p, *ep;
                     15:        char buf[ERRLEN];
                     16: 
                     17:        if(n >= ERRLEN-1)
                     18:                error(Etoobig);
                     19: 
                     20:        memmove(buf, a, n);
                     21:        buf[n] = 0;
                     22:        p = proctab(0);
                     23:        ep = p+conf.nproc;
                     24:        for(; p < ep; p++) {
                     25:                if(p->state == Dead)
                     26:                        continue;
                     27:                if(p != u->p && p->noteid == noteid && p->kp == 0) {
                     28:                        qlock(&p->debug);
                     29:                        if(p->pid == 0 || p->noteid != noteid){
                     30:                                qunlock(&p->debug);
                     31:                                continue;
                     32:                        }
                     33:                        if(!waserror()) {
                     34:                                postnote(p, 0, buf, flag);
                     35:                                poperror();
                     36:                        }
                     37:                        qunlock(&p->debug);
                     38:                }
                     39:        }
                     40: }
                     41: 
                     42: Pgrp*
                     43: newpgrp(void)
                     44: {
                     45:        Pgrp *p;
                     46: 
                     47:        p = smalloc(sizeof(Pgrp));
                     48:        p->ref = 1;
                     49:        p->pgrpid = incref(&pgrpid);
                     50:        return p;
                     51: }
                     52: 
                     53: void
                     54: closepgrp(Pgrp *p)
                     55: {
                     56:        Mhead **h, **e, *f, *next;
                     57:        
                     58:        if(decref(p) == 0){
                     59:                qlock(&p->debug);
                     60:                p->pgrpid = -1;
                     61: 
                     62:                e = &p->mnthash[MNTHASH];
                     63:                for(h = p->mnthash; h < e; h++) {
                     64:                        for(f = *h; f; f = next) {
                     65:                                close(f->from);
                     66:                                mountfree(f->mount);
                     67:                                next = f->hash;
                     68:                                free(f);
                     69:                        }
                     70:                }
                     71:                qunlock(&p->debug);
                     72:                free(p);
                     73:        }
                     74: }
                     75: 
                     76: void
                     77: pgrpcpy(Pgrp *to, Pgrp *from)
                     78: {
                     79:        Mhead **h, **e, *f, **tom, **l, *mh;
                     80:        Mount *n, *m, **link;
                     81: 
                     82:        rlock(&from->ns);
                     83: 
                     84:        e = &from->mnthash[MNTHASH];
                     85:        tom = to->mnthash;
                     86:        for(h = from->mnthash; h < e; h++) {
                     87:                l = tom++;
                     88:                for(f = *h; f; f = f->hash) {
                     89:                        mh = smalloc(sizeof(Mhead));
                     90:                        mh->from = f->from;
                     91:                        incref(mh->from);
                     92:                        *l = mh;
                     93:                        l = &mh->hash;
                     94:                        link = &mh->mount;
                     95:                        for(m = f->mount; m; m = m->next) {
                     96:                                n = newmount(mh, m->to);
                     97:                                *link = n;
                     98:                                link = &n->next;        
                     99:                        }
                    100:                }
                    101:        }
                    102:        runlock(&from->ns);
                    103: }
                    104: 
                    105: Fgrp*
                    106: dupfgrp(Fgrp *f)
                    107: {
                    108:        Fgrp *new;
                    109:        Chan *c;
                    110:        int i;
                    111: 
                    112:        new = smalloc(sizeof(Fgrp));
                    113:        new->ref = 1;
                    114: 
                    115:        lock(f);
                    116:        new->maxfd = f->maxfd;
                    117:        for(i = 0; i <= f->maxfd; i++) {
                    118:                if(c = f->fd[i]){
                    119:                        incref(c);
                    120:                        new->fd[i] = c;
                    121:                }
                    122:        }
                    123:        unlock(f);
                    124: 
                    125:        return new;
                    126: }
                    127: 
                    128: void
                    129: closefgrp(Fgrp *f)
                    130: {
                    131:        int i;
                    132:        Chan *c;
                    133: 
                    134:        if(decref(f) == 0) {
                    135:                for(i = 0; i <= f->maxfd; i++)
                    136:                        if(c = f->fd[i])
                    137:                                close(c);
                    138: 
                    139:                free(f);
                    140:        }
                    141: }
                    142: 
                    143: 
                    144: Mount*
                    145: newmount(Mhead *mh, Chan *to)
                    146: {
                    147:        Mount *m;
                    148: 
                    149:        m = smalloc(sizeof(Mount));
                    150:        m->to = to;
                    151:        m->head = mh;
                    152:        incref(to);
                    153:        m->mountid = incref(&mountid);
                    154:        return m;
                    155: }
                    156: 
                    157: void
                    158: mountfree(Mount *m)
                    159: {
                    160:        Mount *f;
                    161: 
                    162:        while(m) {
                    163:                f = m->next;
                    164:                close(m->to);
                    165:                free(m);
                    166:                m = f;
                    167:        }
                    168: }
                    169: 
                    170: void
                    171: resrcwait(char *reason)
                    172: {
                    173:        char *p;
                    174: 
                    175:        p = u->p->psstate;
                    176:        if(reason) {
                    177:                u->p->psstate = reason;
                    178:                print("%s\n", reason);
                    179:        }
                    180:        if(u == 0)
                    181:                panic("resrcwait");
                    182: 
                    183:        tsleep(&u->p->sleep, return0, 0, 300);
                    184:        u->p->psstate = p;
                    185: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.