Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/pgrp.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname port/pgrp.c 1990/0227
## diff -e /dev/null /n/bootesdump/1990/0227/sys/src/9/mips/pgrp.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"errno.h"

struct{
	Lock;
	Pgrp	*free;
	ulong	pgrpid;
}pgrpalloc;

struct{
	Lock;
	Mount	*free;
	ulong	mountid;
}mountalloc;

void
pgrpinit(void)
{
	int i;
	Pgrp *p;
	Mount *m;

	pgrpalloc.free = ialloc(conf.npgrp*sizeof(Pgrp), 0);

	p = pgrpalloc.free;
	for(i=0; i<conf.npgrp-1; i++,p++){
		p->next = p+1;
		p->mtab = ialloc(conf.nmtab*sizeof(Mtab), 0);
		p->etab = ialloc(conf.npgenv*sizeof(Envp*), 0);
	}
	p->next = 0;

	mountalloc.free = ialloc(conf.nmount*sizeof(Mount), 0);

	m = mountalloc.free;
	for(i=0; i<conf.nmount-1; i++,m++)
		m->next = m+1;
	m->next = 0;
}

Pgrp*
newpgrp(void)
{
	Pgrp *p;

loop:
	lock(&pgrpalloc);
	if(p = pgrpalloc.free){		/* assign = */
		pgrpalloc.free = p->next;
		p->ref = 1;
		p->pgrpid = ++pgrpalloc.pgrpid;
		p->nmtab = 0;
		p->nenv = 0;
		unlock(&pgrpalloc);
		return p;
	}
	unlock(&pgrpalloc);
	print("no pgrps\n");
	if(u == 0)
		panic("newpgrp");
	u->p->state = Wakeme;
	alarm(1000, wakeme, u->p);
	sched();
	goto loop;
}

void
closepgrp(Pgrp *p)
{
	int i;
	Mtab *m;
	Envp *ep;

	if(decref(p) == 0){
		m = p->mtab;
		for(i=0; i<p->nmtab; i++,m++)
			if(m->c){
				close(m->c);
				closemount(m->mnt);
			}
		ep = p->etab;
		for(i=0; i<p->nenv; i++,ep++)
			if(ep->env)
				envpgclose(ep->env);
		lock(&pgrpalloc);
		p->next = pgrpalloc.free;
		pgrpalloc.free = p;
		unlock(&pgrpalloc);
	}
}

Mount*
newmount(void)
{
	Mount *m;

loop:
	lock(&mountalloc);
	if(m = mountalloc.free){		/* assign = */
		mountalloc.free = m->next;
		m->ref = 1;
		m->mountid = ++mountalloc.mountid;
		unlock(&mountalloc);
		return m;
	}
	unlock(&mountalloc);
	print("no mounts\n");
	if(u == 0)
		panic("newmount");
	u->p->state = Wakeme;
	alarm(1000, wakeme, u->p);
	sched();
	goto loop;
}

void
closemount(Mount *m)
{
	lock(m);
	if(m->ref == 1){
		close(m->c);
		if(m->next)
			closemount(m->next);
		unlock(m);
		lock(&mountalloc);
		m->mountid = 0;
		m->next = mountalloc.free;
		mountalloc.free = m;
		unlock(&mountalloc);
		return;
	}
	m->ref--;
	unlock(m);
}

void
pgrpcpy(Pgrp *to, Pgrp *from)
{
	int i;
	Mtab *m;
	Envp *ep;
	Env *e;

	lock(from);
	memcpy(to->user, from->user, NAMELEN);
	memcpy(to->mtab, from->mtab, from->nmtab*sizeof(Mtab));
	to->nmtab = from->nmtab;
	m = to->mtab;
	for(i=0; i<from->nmtab; i++,m++)
		if(m->c){
			incref(m->c);
			lock(m->mnt);
			m->mnt->ref++;
			unlock(m->mnt);
		}

	to->nenv = from->nenv;
	ep = to->etab;
	for(i=0; i<from->nenv; i++,ep++){
		ep->chref = 0;
		e = ep->env = from->etab[i].env;
		if(e){
			lock(e);
			if(waserror()){
				unlock(e);
				unlock(from);
				ep->env = 0;
				nexterror();
			}
			/*
			 * If pgrp being forked has an open channel
			 * on this env, it may write it after the fork
			 * so make a copy now.
			 * Don't worry about other pgrps, because they
			 * will copy if they are about to write.
			 */
			if(from->etab[i].chref){
				ep->env = copyenv(e, 0);
				unlock(ep->env);
			}else
				e->pgref++;
			poperror();
			unlock(e);
		}
	}
	unlock(from);
}
.
## diffname port/pgrp.c 1990/0321
## diff -e /n/bootesdump/1990/0227/sys/src/9/mips/pgrp.c /n/bootesdump/1990/0321/sys/src/9/mips/pgrp.c
125c
		if(m->c)
			close(m->c);
.
## diffname port/pgrp.c 1990/0810
## diff -e /n/bootesdump/1990/0321/sys/src/9/mips/pgrp.c /n/bootesdump/1990/0810/sys/src/9/mips/pgrp.c
113a
	print("%s %s\n", u->p->pgrp->user, u->p->text);
.
## diffname port/pgrp.c 1990/0825
## diff -e /n/bootesdump/1990/0810/sys/src/9/mips/pgrp.c /n/bootesdump/1990/0825/sys/src/9/mips/pgrp.c
114d
35c
	p[-1].next = 0;
.
30c
	for(i=0; i<conf.npgrp; i++,p++){
.
## diffname port/pgrp.c 1990/0928
## diff -e /n/bootesdump/1990/0825/sys/src/9/mips/pgrp.c /n/bootesdump/1990/0928/sys/src/9/mips/pgrp.c
105a
		m->next = 0;
.
## diffname port/pgrp.c 1990/1110
## diff -e /n/bootesdump/1990/0928/sys/src/9/mips/pgrp.c /n/bootesdump/1990/1110/sys/src/9/mips/pgrp.c
91a
		unlock(&p->debug);
.
78a
		lock(&p->debug);
		p->pgrpid = -1;
.
45a
pgrptab(int i)
{
	return &pgrpalloc.arena[i];
}

void
pgrpnote(Pgrp *pg, char *a, long n, int flag)
{
	int i;
	Proc *p;
	char buf[ERRLEN];

	if(n >= ERRLEN-1)
		error(0, Etoobig);
	if(n>=4 && strncmp(a, "sys:", 4)==0)
		error(0, Ebadarg);
	memcpy(buf, a, n);
	buf[n] = 0;
	p = proctab(0);
	for(i=0; i<conf.nproc; i++, p++){
		if(p->pgrp == pg){
			lock(&p->debug);
			if(p->pid==0 || p->pgrp!=pg){
				unlock(&p->debug);
				continue;
			}
			if(waserror()){
				unlock(&p->debug);
				continue;
			}
			postnote(p, 0, buf, flag);
			unlock(&p->debug);
		}
	}
}

Pgrp*
.
30a
		p->index = i;
.
27c
	pgrpalloc.arena = ialloc(conf.npgrp*sizeof(Pgrp), 0);
	pgrpalloc.free = pgrpalloc.arena;
.
9a
	Pgrp	*arena;
.
## diffname port/pgrp.c 1990/11211
## diff -e /n/bootesdump/1990/1110/sys/src/9/mips/pgrp.c /n/bootesdump/1990/11211/sys/src/9/mips/pgrp.c
64c
		error(Ebadarg);
.
62c
		error(Etoobig);
.
## diffname port/pgrp.c 1991/0125
## diff -e /n/bootesdump/1990/1210/sys/src/9/mips/pgrp.c /n/bootesdump/1991/0125/sys/src/9/port/pgrp.c
79d
75,77c
			if(!waserror()){
				postnote(p, 0, buf, flag);
				poperror();
.
## diffname port/pgrp.c 1991/0212
## diff -e /n/bootesdump/1991/0125/sys/src/9/port/pgrp.c /n/bootesdump/1991/0212/sys/src/9/port/pgrp.c
133c
		qunlock(&p->debug);
.
118c
		qlock(&p->debug);
.
## diffname port/pgrp.c 1991/0318
## diff -e /n/bootesdump/1991/0212/sys/src/9/port/pgrp.c /n/bootesdump/1991/0318/sys/src/9/port/pgrp.c
193,194c
	memmove(to->user, from->user, NAMELEN);
	memmove(to->mtab, from->mtab, from->nmtab*sizeof(Mtab));
.
65c
	memmove(buf, a, n);
.
## diffname port/pgrp.c 1991/0514
## diff -e /n/bootesdump/1991/0318/sys/src/9/port/pgrp.c /n/bootesdump/1991/0514/sys/src/9/port/pgrp.c
233a
	unlock(from);
}

void
pgrpcpy(Pgrp *to, Pgrp *from)
{
	int i;
	Mtab *m;

	lock(from);
	memmove(to->user, from->user, NAMELEN);
	memmove(to->mtab, from->mtab, from->nmtab*sizeof(Mtab));
	to->nmtab = from->nmtab;
	m = to->mtab;
	for(i=0; i<from->nmtab; i++,m++)
		if(m->c){
			incref(m->c);
			lock(m->mnt);
			m->mnt->ref++;
			unlock(m->mnt);
		}

.
193,204d
190a
	int i;
.
187,188d
185c
envcpy(Pgrp *to, Pgrp *from)
.
## diffname port/pgrp.c 1991/0705
## diff -e /n/bootesdump/1991/0514/sys/src/9/port/pgrp.c /n/bootesdump/1991/0705/sys/src/9/port/pgrp.c
185c
envcpy(Egrp *to, Egrp *from)
.
137a
void
closeegrp(Egrp *e)
{
	Envp *ep;
	int i;

	if(decref(e) == 0) {
		ep = e->etab;
		for(i=0; i<e->nenv; i++,ep++)
			if(ep->env)
				envpgclose(ep->env);
		lock(&egrpalloc);
		e->next = egrpalloc.free;
		egrpalloc.free = e;
		unlock(&egrpalloc);
	}
}

void
closefgrp(Fgrp *f)
{
	int i;
	Chan *c;

	if(decref(f) == 0) {
		for(i = 0; i <= f->maxfd; i++)
			if(c = f->fd[i])
				close(c);

		lock(&fgrpalloc);
		f->next = fgrpalloc.free;
		fgrpalloc.free = f;
		unlock(&fgrpalloc);
	}
}


.
126,129d
115d
107d
103c
		panic("resched");
.
100,101c
}

Egrp*
newegrp(void)
{
	Egrp *e;

	for(;;) {
		lock(&egrpalloc);
		if(e = egrpalloc.free) {
			egrpalloc.free = e->next;
			e->ref = 1;
			e->nenv = 0;
			unlock(&egrpalloc);
			return e;
		}
		unlock(&egrpalloc);
		resrcwait("no envgrps");
	}
}

Fgrp*
newfgrp(void)
{
	Fgrp *f;

	for(;;) {
		lock(&fgrpalloc);
		if(f = fgrpalloc.free) {
			fgrpalloc.free = f->next;
			f->ref = 1;
			f->maxfd = 0;
			memset(f->fd, 0, sizeof(f->fd));
			unlock(&fgrpalloc);
			return f;
		}
		unlock(&fgrpalloc);
		resrcwait("no filegrps");
	}
}

Fgrp*
dupfgrp(Fgrp *f)
{
	Fgrp *new;
	Chan *c;
	int i;

	new = newfgrp();

	new->maxfd = f->maxfd;
	for(i = 0; i <= f->maxfd; i++)
		if(c = f->fd[i]){
			incref(c);
			new->fd[i] = c;
		}

	return new;
}

void
resrcwait(char *reason)
{
	print("%s\n", reason);
.
98c
		resrcwait("no pgrps");
.
89,96c
	for(;;) {
		lock(&pgrpalloc);
		if(p = pgrpalloc.free){
			pgrpalloc.free = p->next;
			p->ref = 1;
			p->pgrpid = ++pgrpalloc.pgrpid;
			p->nmtab = 0;
			unlock(&pgrpalloc);
			return p;
		}
.
42,43c
	fgrpalloc.free = ialloc(conf.nproc*sizeof(Fgrp), 0);
	fe = &fgrpalloc.free[conf.nproc-1];
	for(f = fgrpalloc.free; f < fe; f++)
		f->next = f+1;
	f->next = 0;

	mountalloc.free = ialloc(conf.nmount*sizeof(Mount), 0);
	em = &mountalloc.free[conf.nmount-1];
	for(m = mountalloc.free; m < em; m++)
.
40c
	egrpalloc.free = ialloc(conf.npgrp*sizeof(Egrp), 0);
	ee = &egrpalloc.free[conf.npgrp];
	for(e = egrpalloc.free; e < ee; e++) {
		e->next = e+1;
		e->etab = ialloc(conf.npgenv*sizeof(Envp*), 0);
	}
	e[-1].next = 0;
.
36d
26c
	Egrp *e, *ee;
	Fgrp *f, *fe;
	Mount *m, *em;
.
22c
grpinit(void)
.
14a
struct
{
	Lock;
	Egrp	*free;
}egrpalloc;

struct
{
	Lock;
	Fgrp	*free;
}fgrpalloc;

.
8c
struct
{
.
## diffname port/pgrp.c 1991/0710
## diff -e /n/bootesdump/1991/0705/sys/src/9/port/pgrp.c /n/bootesdump/1991/0710/sys/src/9/port/pgrp.c
194c
		panic("resrcwait");
.
192c
	if(reason)
		print("%s\n", reason);
.
## diffname port/pgrp.c 1991/0806
## diff -e /n/bootesdump/1991/0710/sys/src/9/port/pgrp.c /n/bootesdump/1991/0806/sys/src/9/port/pgrp.c
122a
			memset(p->rendhash, 0, sizeof(p->rendhash));
.
## diffname port/pgrp.c 1991/1011
## diff -e /n/bootesdump/1991/0806/sys/src/9/port/pgrp.c /n/bootesdump/1991/1011/sys/src/9/port/pgrp.c
367c
Mhead *
newmnthead(void)
{
	Mhead *mh, *f, *e;

	for(;;) {
		lock(&mountalloc);
		if(mh = mountalloc.mhfree) {		/* Assign '=' */
			mountalloc.mhfree = mh->hash;
			unlock(&mountalloc);
			mh->hash = 0;
			mh->mount = 0;
			return mh;
		}
		unlock(&mountalloc);

		mh = (Mhead*)VA(kmap(newpage(0, 0, 0)));
		e = &mh[(BY2PG/sizeof(Mhead))-1];
		for(f = mh; f < e; f++)
			f->hash = f+1;

		lock(&mountalloc);
		e->hash = mountalloc.mhfree;
		mountalloc.mhfree = mh;
		unlock(&mountalloc);
	}
}

void
mntheadfree(Mhead *mh)
{
	lock(&mountalloc);
	mh->hash = mountalloc.mhfree;
	mountalloc.mhfree = mh;
	unlock(&mountalloc);
}

void
mountfree(Mount *m)
{
	Mount *f;

	for(f = m; f->next; f = f->next)
		close(f->to);
	close(f->to);
	lock(&mountalloc);
	f->next = mountalloc.free;
	mountalloc.free = m;
	unlock(&mountalloc);
.
365a
	}
	runlock(&from->ns);
}
.
356,364c

	rlock(&from->ns);

	e = &from->mnthash[MNTHASH];
	for(h = from->mnthash; h < e; h++) {
		for(f = *h; f; f = f->hash) {
			mh = newmnthead();
			mh->from = f->from;
			incref(mh->from);
			l = &MOUNTH(to, mh->from);
			mh->hash = *l;
			*l = mh;
			link = &mh->mount;
			for(m = f->mount; m; m = m->next) {
				n = newmount(mh, m->to);
				*link = n;
				link = &n->next;	
			}
.
354d
351,352c
	Mhead **h, **e, *f, **l, *mh;
	Mount *n, *m, **link;
.
304,305d
302d
298,299c
		e->next = mountalloc.free;
.
287,296c
		m = (Mount*)VA(kmap(newpage(0, 0, 0)));
		e = &m[(BY2PG/sizeof(Mount))-1];
		for(f = m; f < e; f++)
			f->next = f+1;

.
275,285d
267,273c
	for(;;) {
		lock(&mountalloc);
		if(m = mountalloc.free){		/* assign = */
			mountalloc.free = m->next;
			m->mountid = ++mountalloc.mountid;
			unlock(&mountalloc);
			m->next = 0;
			m->head = mh;
			m->to = to;
			incref(to);
			return m;
		}
.
265c
	Mount *m, *f, *e;
.
263c
newmount(Mhead *mh, Chan *to)
.
216a
		}

.
211,215c

		e = &p->mnthash[MNTHASH];
		for(h = p->mnthash; h < e; h++) {
			for(f = *h; f; f = next) {
				close(f->from);
				mountfree(f->mount);
				next = f->hash;
				mntheadfree(f);
.
205,207c
	Mhead **h, **e, *f, *next;
	
.
123a
			memset(p->mnthash, 0, sizeof(p->mnthash));
.
122d
67,72d
50d
47c
	for(i=0; i<conf.npgrp; i++,p++) {
.
41a
	Mhead *hm, *hem;
.
30a
	Mhead	*mhfree;
.
## diffname port/pgrp.c 1991/1018
## diff -e /n/bootesdump/1991/1011/sys/src/9/port/pgrp.c /n/bootesdump/1991/1018/sys/src/9/port/pgrp.c
299,329c
	qlock(&from->ev);
	nenv = from->nenv;
	to->nenv = nenv;
	te = to->etab;
	fe = from->etab;
	for(i=0; i < nenv; i++, te++, fe++)
		envpgcopy(te, fe);
	qunlock(&from->ev);
.
295,297c
	Env *te, *fe;
	int i, nenv;
.
236,237c
		eg->next = egrpalloc.free;
		egrpalloc.free = eg;
.
230,234c
	if(decref(eg) == 0) {
		e = eg->etab;
		for(i=0; i<eg->nenv; i++, e++)
			envpgclose(e);
.
227c
	Env *e;
.
225c
closeegrp(Egrp *eg)
.
59c
		e->etab = ialloc(conf.npgenv*sizeof(Env), 0);
.
## diffname port/pgrp.c 1991/1105
## diff -e /n/bootesdump/1991/1018/sys/src/9/port/pgrp.c /n/bootesdump/1991/1105/sys/src/9/port/pgrp.c
313,314d
## diffname port/pgrp.c 1991/1110
## diff -e /n/bootesdump/1991/1105/sys/src/9/port/pgrp.c /n/bootesdump/1991/1110/sys/src/9/port/pgrp.c
194a
	u->p->psstate = p;
.
189a
	}
.
188c
	char *p;

	p = u->p->psstate;
	if(reason) {
		u->p->psstate = reason;
.
## diffname port/pgrp.c 1991/1112
## diff -e /n/bootesdump/1991/1110/sys/src/9/port/pgrp.c /n/bootesdump/1991/1112/sys/src/9/port/pgrp.c
90,91c
	for(i=0; i<conf.nproc; i++, p++) {
		if(p->pgrp == pg && p->kp == 0) {
.
## diffname port/pgrp.c 1991/1113
## diff -e /n/bootesdump/1991/1112/sys/src/9/port/pgrp.c /n/bootesdump/1991/1113/sys/src/9/port/pgrp.c
329a
			l = &mh->hash;
.
327,328d
322a
		l = tom++;
.
321a
	tom = to->mnthash;
.
316c
	Mhead **h, **e, *f, **tom, **l, *mh;
.
## diffname port/pgrp.c 1991/1127
## diff -e /n/bootesdump/1991/1113/sys/src/9/port/pgrp.c /n/bootesdump/1991/1127/sys/src/9/port/pgrp.c
320a
	*to->crypt = *from->crypt;
.
116a
			memset(p->crypt, 0, sizeof *p->crypt);
.
51a
		p->crypt = cr++;
.
44a
	/*
	 * need to /dev/proc read protect crypt memory
	 */
	cr = ialloc(conf.npgrp*sizeof(Crypt), 0);
.
43a
	Crypt *cr;
.
## diffname port/pgrp.c 1991/1216
## diff -e /n/bootesdump/1991/1127/sys/src/9/port/pgrp.c /n/bootesdump/1991/1216/sys/src/9/port/pgrp.c
107c
			qunlock(&p->debug);
.
100c
				qunlock(&p->debug);
.
98c
			qlock(&p->debug);
.
## diffname port/pgrp.c 1991/1231
## diff -e /n/bootesdump/1991/1216/sys/src/9/port/pgrp.c /n/bootesdump/1991/1231/sys/src/9/port/pgrp.c
91,92d
## diffname port/pgrp.c 1992/0111
## diff -e /n/bootesdump/1991/1231/sys/src/9/port/pgrp.c /n/bootesdump/1992/0111/sys/src/9/port/pgrp.c
6c
#include	"../port/error.h"
.
## diffname port/pgrp.c 1992/0128
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/pgrp.c /n/bootesdump/1992/0128/sys/src/9/port/pgrp.c
46,49c
	i = conf.npgrp*sizeof(Crypt);
	cr = ialloc(i, 0);
	pgrpalloc.cryptbase = (ulong)cr;
	pgrpalloc.crypttop = (ulong)cr + i;
.
8,14c
Pgrps pgrpalloc;
.
## diffname port/pgrp.c 1992/0321
## diff -e /n/bootesdump/1992/0128/sys/src/9/port/pgrp.c /n/bootesdump/1992/0321/sys/src/9/port/pgrp.c
2c
#include	"../port/lib.h"
.
## diffname port/pgrp.c 1992/0428
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/pgrp.c /n/bootesdump/1992/0428/sys/src/9/port/pgrp.c
91c
			if(p->pid==0 || p->noteid != noteid){
.
88,89c
	ep = p+conf.nproc;
	for(; p < ep; p++) {
		if(p->state == Dead)
			continue;
		if(p->noteid == noteid && p->kp == 0) {
.
84a

.
79,80c
	Proc *p, *ep;
.
77c
pgrpnote(ulong noteid, char *a, long n, int flag)
.
## diffname port/pgrp.c 1992/0520
## diff -e /n/bootesdump/1992/0428/sys/src/9/port/pgrp.c /n/bootesdump/1992/0520/sys/src/9/port/pgrp.c
370a
	return 0;		/* not reached */
.
296a
	return 0;	/* not reached */
.
165a
	return 0;		/* not reached */
.
145a
	return 0;		/* not reached */
.
126a
	return 0;		/* not reached */
.
## diffname port/pgrp.c 1992/0602
## diff -e /n/bootesdump/1992/0520/sys/src/9/port/pgrp.c /n/bootesdump/1992/0602/sys/src/9/port/pgrp.c
202,204c

	tsleep(&u->p->sleep, return0, 0, 1000);
.
## diffname port/pgrp.c 1992/0607
## diff -e /n/bootesdump/1992/0602/sys/src/9/port/pgrp.c /n/bootesdump/1992/0607/sys/src/9/port/pgrp.c
185a
	unlock(f);
.
179a
	lock(f);
.
## diffname port/pgrp.c 1992/0619
## diff -e /n/bootesdump/1992/0607/sys/src/9/port/pgrp.c /n/bootesdump/1992/0619/sys/src/9/port/pgrp.c
396,399c

	free(f);
.
394a

.
380,388d
350,378d
334c
			mh = smalloc(sizeof(Mhead));
.
277,301c
	m = smalloc(sizeof(Mount));
	m->to = to;
	m->head = mh;
	incref(to);
	m->mountid = incref(&mountid);
	return m;
.
264,267c
		free(f);
.
246,249c

		free(eg);
.
232c
		free(p);
.
227,230d
224c
				free(f);
.
155,168c
	f = smalloc(sizeof(Fgrp));
	f->ref = 1;
	return f;
.
135,147c
	e = smalloc(sizeof(Egrp)+sizeof(Env)*conf.npgenv);

	/* This is a sleazy hack to make malloc work .. devenv need rewriting. */
	e->etab = (Env*)((uchar*)e+sizeof(Egrp));
	e->ref = 1;
	return e;
.
112,127c
	p = smalloc(sizeof(Pgrp)+sizeof(Crypt));
	p->ref = 1;
	/* This needs to have its own arena for protection */
	p->crypt = (Crypt*)((uchar*)p+sizeof(Pgrp));
	p->pgrpid = incref(&pgrpid);
	return p;
.
30,76d
10,28d
8c
static Ref pgrpid;
static Ref mountid;
.
## diffname port/pgrp.c 1992/0623
## diff -e /n/bootesdump/1992/0619/sys/src/9/port/pgrp.c /n/bootesdump/1992/0623/sys/src/9/port/pgrp.c
189,196c
	l = &to->entries;
	qlock(from);
	for(e = from->entries; e; e = e->link) {
		ne = smalloc(sizeof(Evalue));
		ne->name = smalloc(strlen(e->name)+1);
		strcpy(ne->name, e->name);
		if(e->value) {
			ne->value = smalloc(e->len);
			memmove(ne->value, e->value, e->len);
			ne->len = e->len;
		}
		ne->path = ++to->path;
		*l = ne;
		l = &ne->link;
	}
	qunlock(from);
.
186,187c
	Evalue **l, *ne, *e;
.
146,149c
		for(e = eg->entries; e; e = next) {
			next = e->link;
			free(e->name);
			if(e->value)
				free(e->value);
			free(e);
		}
.
142,143c
	Evalue *e, *next;
.
85c
	new = smalloc(sizeof(Fgrp));
	new->ref = 1;
.
69,78d
55,67d
## diffname port/pgrp.c 1992/0625
## diff -e /n/bootesdump/1992/0623/sys/src/9/port/pgrp.c /n/bootesdump/1992/0625/sys/src/9/port/pgrp.c
161,183d
118,134d
## diffname port/pgrp.c 1992/0705
## diff -e /n/bootesdump/1992/0625/sys/src/9/port/pgrp.c /n/bootesdump/1992/0705/sys/src/9/port/pgrp.c
181,186c
	while(m) {
		f = m->next;
		close(m->to);
		free(m);
		m = f;
	}
.
## diffname port/pgrp.c 1992/0711
## diff -e /n/bootesdump/1992/0705/sys/src/9/port/pgrp.c /n/bootesdump/1992/0711/sys/src/9/port/pgrp.c
136c
	Mount *m;
.
## diffname port/pgrp.c 1992/0824
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/pgrp.c /n/bootesdump/1992/0824/sys/src/9/port/pgrp.c
186a
}

void
resrcwait(char *reason)
{
	char *p;

	p = u->p->psstate;
	if(reason) {
		u->p->psstate = reason;
		print("%s\n", reason);
	}
	if(u == 0)
		panic("resrcwait");

	tsleep(&u->p->sleep, return0, 0, 1000);
	u->p->psstate = p;
.
176a
closefgrp(Fgrp *f)
{
	int i;
	Chan *c;

	if(decref(f) == 0) {
		for(i = 0; i <= f->maxfd; i++)
			if(c = f->fd[i])
				close(c);

		free(f);
	}
}


Mount*
newmount(Mhead *mh, Chan *to)
{
	Mount *m;

	m = smalloc(sizeof(Mount));
	m->to = to;
	m->head = mh;
	incref(to);
	m->mountid = incref(&mountid);
	return m;
}

void
.
175a
Fgrp*
dupfgrp(Fgrp *f)
{
	Fgrp *new;
	Chan *c;
	int i;

	new = smalloc(sizeof(Fgrp));
	new->ref = 1;

	lock(f);
	new->maxfd = f->maxfd;
	for(i = 0; i <= f->maxfd; i++) {
		if(c = f->fd[i]){
			incref(c);
			new->fd[i] = c;
		}
	}
	unlock(f);

	return new;
}

.
118,146d
112a
		freecrypt(p->crypt);
.
78,94d
55,76d
49,50c
	p->crypt = newcrypt();
.
47c
	p = smalloc(sizeof(Pgrp));
.
33c
			if(!waserror()) {
.
29c
			if(p->pid == 0 || p->noteid != noteid){
.
11a
freecrypt(Crypt *c)
{
	lock(&cryptalloc);
	c->next = cryptalloc.free;
	cryptalloc.free = c;
	unlock(&cryptalloc);
}

void
.
10a
struct
{
	Lock;
	Crypt	*free;
} cryptalloc;

/*
 * crypt entries are allocated from a pool rather than allocated using malloc so
 * the memory can be protected from reading by devproc. The base and top of the
 * crypt arena is stored in palloc for devproc.
 */
Crypt*
newcrypt(void)
{
	Crypt *c;

	lock(&cryptalloc);
	if(cryptalloc.free) {
		c = cryptalloc.free;
		cryptalloc.free = c->next;
		unlock(&cryptalloc);
		return c;
	}

	cryptalloc.free = malloc(sizeof(Crypt)*conf.nproc);
	if(cryptalloc.free == 0)
		panic("newcrypt");

	for(c = cryptalloc.free+1; c < cryptalloc.free+conf.nproc-1; c++)
		c->next = c+1;

	palloc.cmembase = (ulong)cryptalloc.free;
	palloc.cmembase = palloc.cmembase+(sizeof(Crypt)*conf.nproc);
	unlock(&cryptalloc);
	return newcrypt();
}

.
## diffname port/pgrp.c 1992/1008
## diff -e /n/bootesdump/1992/0824/sys/src/9/port/pgrp.c /n/bootesdump/1992/1008/sys/src/9/port/pgrp.c
43c
	palloc.cmemtop = palloc.cmembase+(sizeof(Crypt)*conf.nproc);
.
39c
	for(c = cryptalloc.free; c < cryptalloc.free+conf.nproc-1; c++)
.
35c
	cryptalloc.free = xalloc(sizeof(Crypt)*conf.nproc);
.
## diffname port/pgrp.c 1992/1209
## diff -e /n/bootesdump/1992/1008/sys/src/9/port/pgrp.c /n/bootesdump/1992/1209/sys/src/9/port/pgrp.c
232c
	tsleep(&u->p->sleep, return0, 0, 300);
.
## diffname port/pgrp.c 1993/0330
## diff -e /n/bootesdump/1992/1209/sys/src/9/port/pgrp.c /n/bootesdump/1993/0330/sys/src/9/port/pgrp.c
132d
119d
95d
49,57d
11,47d
## diffname port/pgrp.c 1993/0501
## diff -e /n/bootesdump/1993/0330/sys/src/9/port/pgrp.c /n/fornaxdump/1993/0501/sys/src/brazil/port/pgrp.c
183,184c
	tsleep(&up->sleep, return0, 0, 300);
	up->psstate = p;
.
180,181d
177c
		up->psstate = reason;
.
175c
	if(up == 0)
		panic("resrcwait");

	p = up->psstate;
.
164a
		m->mountid = 0;
.
153a
	m->flag = flag;
	if(spec != 0)
		strcpy(m->spec, spec);

.
145c
newmount(Mhead *mh, Chan *to, int flag, char *spec)
.
96c
				n = newmount(mh, m->to, m->flag, m->spec);
.
## diffname port/pgrp.c 1993/1115
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/pgrp.c /n/fornaxdump/1993/1115/sys/src/brazil/port/pgrp.c
143d
## diffname port/pgrp.c 1994/0613
## diff -e /n/fornaxdump/1993/1115/sys/src/brazil/port/pgrp.c /n/fornaxdump/1994/0613/sys/src/brazil/port/pgrp.c
101a
	/*
	 * Allocate mount ids in the same sequence as the parent group
	 */
	lock(&mountid);
	for(m = order; m; m = m->order)
		m->copy->mountid = mountid.ref++;
	unlock(&mountid);
.
96c
				n = smalloc(sizeof(Mount));
				n->to = m->to;
				incref(n->to);
				n->head = mh;
				n->flag = m->flag;
				if(m->spec != 0)
					strcpy(n->spec, m->spec);
				m->copy = n;
				pgrpinsert(&order, m);
.
88c
		for(f = from->mnthash[i]; f; f = f->hash) {
.
86c
	for(i = 0; i < MNTHASH; i++) {
.
83,84c
	order = 0;
.
79,80c
	int i;
	Mount *n, *m, **link, *order;
	Mhead *f, **tom, **l, *mh;
.
76a
pgrpinsert(Mount **order, Mount *m)
{
	Mount *f;

	m->order = 0;
	if(*order == 0) {
		*order = m;
		return;
	}
	for(f = *order; f; f = f->order) {
		if(m->mountid < f->mountid) {
			m->order = f;
			*order = m;
			return;
		}
		order = &f->order;
	}
	*order = m;
}

/*
 * pgrpcpy MUST preserve the mountid allocation order of the parent group
 */
void
.
## diffname port/pgrp.c 1994/0812
## diff -e /n/fornaxdump/1994/0613/sys/src/brazil/port/pgrp.c /n/fornaxdump/1994/0812/sys/src/brazil/port/pgrp.c
52a
Rgrp*
newrgrp(void)
{
	Rgrp *r;

	r = smalloc(sizeof(Rgrp));
	r->ref = 1;
	return r;
}

void
closergrp(Rgrp *r)
{
	if(decref(r) == 0)
		free(r);
}

.
## diffname port/pgrp.c 1995/0218
## diff -e /n/fornaxdump/1994/0812/sys/src/brazil/port/pgrp.c /n/fornaxdump/1995/0218/sys/src/brazil/port/pgrp.c
27c
		if(up != p && p->noteid == noteid && p->kp == 0) {
.
## diffname port/pgrp.c 1996/1218
## diff -e /n/fornaxdump/1995/0218/sys/src/brazil/port/pgrp.c /n/fornaxdump/1996/1218/sys/src/brazil/port/pgrp.c
111c
	*l = m->order;
.
109c
		l = &f->order;
.
106c
			*l = f;
.
102a

	l = order;
.
99c
	if(*order == nil) {
.
96c
	Mount *f, **l;
.
## diffname port/pgrp.c 1997/0117
## diff -e /n/fornaxdump/1996/1218/sys/src/brazil/port/pgrp.c /n/fornaxdump/1997/0117/sys/src/brazil/port/pgrp.c
113c
	*order = m;
.
111c
		order = &f->order;
.
108c
			*order = m;
.
103,104d
99c
	if(*order == 0) {
.
96c
	Mount *f;
.
## diffname port/pgrp.c 1997/0327
## diff -e /n/fornaxdump/1997/0117/sys/src/brazil/port/pgrp.c /n/emeliedump/1997/0327/sys/src/brazil/port/pgrp.c
223c
		cclose(m->to);
.
193c
				cclose(c);
.
82c
				cclose(f->from);
.
## diffname port/pgrp.c 1997/0414
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/port/pgrp.c /n/emeliedump/1997/0414/sys/src/brazil/port/pgrp.c
195,196c
	if(decref(f) != 0)
		return;

	for(i = 0; i <= f->maxfd; i++)
		if(c = f->fd[i])
			cclose(c);

	free(f);
.
190,193c
	if(f == 0)
		return;
.
90a
	qunlock(&p->debug);
	free(p);
.
88,89d
79,86c
	qlock(&p->debug);
	p->pgrpid = -1;

	e = &p->mnthash[MNTHASH];
	for(h = p->mnthash; h < e; h++) {
		for(f = *h; f; f = next) {
			cclose(f->from);
			mountfree(f->mount);
			next = f->hash;
			free(f);
.
75,77c
	if(decref(p) != 0)
		return;
.
## diffname port/pgrp.c 1997/0603
## diff -e /n/emeliedump/1997/0414/sys/src/brazil/port/pgrp.c /n/emeliedump/1997/0603/sys/src/brazil/port/pgrp.c
200a
	free(f->fd);
.
169a
	/* Make new fd list shorter if possible, preserving quantization */
	new->nfd = f->maxfd+1;
	i = new->nfd%DELTAFD;
	if(i != 0)
		new->nfd += DELTAFD - i;
	new->fd = smalloc(new->nfd*sizeof(Chan*));
.
## diffname port/pgrp.c 1997/0606
## diff -e /n/emeliedump/1997/0603/sys/src/brazil/port/pgrp.c /n/emeliedump/1997/0606/sys/src/brazil/port/pgrp.c
178d
175c
	new->fd = malloc(new->nfd*sizeof(Chan*));
	if(new->fd == 0){
		unlock(f);
		error("no memory for fgrp");
	}
.
169a
	if(f == nil){
		new->fd = smalloc(DELTAFD*sizeof(Chan*));
		new->nfd = DELTAFD;
		new->ref = 1;
		return new;
	}

	lock(f);
.
## diffname port/pgrp.c 1997/1203
## diff -e /n/emeliedump/1997/0606/sys/src/brazil/port/pgrp.c /n/emeliedump/1997/1203/sys/src/brazil/port/pgrp.c
234c
		strncpy(m->spec, spec, NAMELEN);
.
159c
	wunlock(&from->ns);
.
143,144c
				if(m->spec[0] != 0)
					strncpy(n->spec, m->spec, NAMELEN);
.
125c
	wlock(&from->ns);
.
## diffname port/pgrp.c 1998/0512
## diff -e /n/emeliedump/1997/1203/sys/src/brazil/port/pgrp.c /n/emeliedump/1998/0512/sys/src/brazil/port/pgrp.c
148c
				link = &n->next;
.
74c

.
## diffname port/pgrp.c 1998/0811
## diff -e /n/emeliedump/1998/0512/sys/src/brazil/port/pgrp.c /n/emeliedump/1998/0811/sys/src/brazil/port/pgrp.c
89a
	wunlock(&p->ns);
.
78a
	wlock(&p->ns);
.
## diffname port/pgrp.c 1998/0829
## diff -e /n/emeliedump/1998/0811/sys/src/brazil/port/pgrp.c /n/emeliedump/1998/0829/sys/src/brazil/port/pgrp.c
151a
			runlock(&f->lock);
.
134a
			mh->ref = 1;
.
132a
			rlock(&f->lock);
.
88c
			wunlock(&f->lock);
			putmhead(f);
.
86a
			f->mount = nil;
.
84a
			wlock(&f->lock);
.
## diffname port/pgrp.c 2001/0527
## diff -e /n/emeliedump/1998/0829/sys/src/brazil/port/pgrp.c /n/emeliedump/2001/0527/sys/src/9/port/pgrp.c
255a
		free(m->spec);
.
242c
		kstrdup(&m->spec, spec);
.
240c
	m->mflag = flag;
.
145,151c
				n = newmount(mh, m->to, m->mflag, m->spec);
.
137a
incref(&mheadcounter);
.
135a
extern Ref mheadcounter;
.
17c
	if(n >= ERRMAX-1)
.
15c
	char buf[ERRMAX];
.
## diffname port/pgrp.c 2002/0411
## diff -e /n/emeliedump/2001/0527/sys/src/9/port/pgrp.c /n/emeliedump/2002/0411/sys/src/9/port/pgrp.c
139d
136d
## diffname port/pgrp.c 2002/0731
## diff -e /n/emeliedump/2002/0411/sys/src/9/port/pgrp.c /n/emeliedump/2002/0731/sys/src/9/port/pgrp.c
137,140c
			mh = newmhead(f->from);
.
## diffname port/pgrp.c 2003/0511
## diff -e /n/emeliedump/2002/0731/sys/src/9/port/pgrp.c /n/emeliedump/2003/0511/sys/src/9/port/pgrp.c
184a
		free(new);
.
183c
	if(new->fd == nil){
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].