plan 9 kernel history: overview | file list | diff list

1992/0711/port/pgrp.c (diff list | history)

port/pgrp.c on 1990/0227
1990/0227    
#include	"u.h" 
1992/0321    
#include	"../port/lib.h" 
1990/0227    
#include	"mem.h" 
#include	"dat.h" 
#include	"fns.h" 
1992/0111    
#include	"../port/error.h" 
1990/0227    
 
1992/0619    
static Ref pgrpid; 
static Ref mountid; 
1990/0227    
 
void 
1992/0428    
pgrpnote(ulong noteid, char *a, long n, int flag) 
1990/1110    
{ 
1992/0428    
	Proc *p, *ep; 
1990/1110    
	char buf[ERRLEN]; 
 
	if(n >= ERRLEN-1) 
1990/11211    
		error(Etoobig); 
1992/0428    
 
1991/0318    
	memmove(buf, a, n); 
1990/1110    
	buf[n] = 0; 
	p = proctab(0); 
1992/0428    
	ep = p+conf.nproc; 
	for(; p < ep; p++) { 
		if(p->state == Dead) 
			continue; 
		if(p->noteid == noteid && p->kp == 0) { 
1991/1216    
			qlock(&p->debug); 
1992/0428    
			if(p->pid==0 || p->noteid != noteid){ 
1991/1216    
				qunlock(&p->debug); 
1990/1110    
				continue; 
			} 
1991/0125    
			if(!waserror()){ 
				postnote(p, 0, buf, flag); 
				poperror(); 
1990/1110    
			} 
1991/1216    
			qunlock(&p->debug); 
1990/1110    
		} 
	} 
} 
 
Pgrp* 
1990/0227    
newpgrp(void) 
{ 
	Pgrp *p; 
 
1992/0619    
	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; 
1991/0705    
} 
 
Fgrp* 
dupfgrp(Fgrp *f) 
{ 
	Fgrp *new; 
	Chan *c; 
	int i; 
 
1992/0623    
	new = smalloc(sizeof(Fgrp)); 
	new->ref = 1; 
1991/0705    
 
1992/0607    
	lock(f); 
1991/0705    
	new->maxfd = f->maxfd; 
	for(i = 0; i <= f->maxfd; i++) 
		if(c = f->fd[i]){ 
			incref(c); 
			new->fd[i] = c; 
		} 
1992/0607    
	unlock(f); 
1991/0705    
 
	return new; 
} 
 
void 
resrcwait(char *reason) 
{ 
1991/1110    
	char *p; 
 
	p = u->p->psstate; 
	if(reason) { 
		u->p->psstate = reason; 
1991/0710    
		print("%s\n", reason); 
1991/1110    
	} 
1990/0227    
	if(u == 0) 
1991/0710    
		panic("resrcwait"); 
1992/0602    
 
	tsleep(&u->p->sleep, return0, 0, 1000); 
1991/1110    
	u->p->psstate = p; 
1990/0227    
} 
 
void 
closepgrp(Pgrp *p) 
{ 
1991/1011    
	Mhead **h, **e, *f, *next; 
	 
1990/0227    
	if(decref(p) == 0){ 
1991/0212    
		qlock(&p->debug); 
1990/1110    
		p->pgrpid = -1; 
1991/1011    
 
		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; 
1992/0619    
				free(f); 
1990/0227    
			} 
1991/1011    
		} 
1991/0212    
		qunlock(&p->debug); 
1992/0619    
		free(p); 
1990/0227    
	} 
} 
 
1991/0705    
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); 
 
1992/0619    
		free(f); 
1991/0705    
	} 
} 
 
 
1990/0227    
Mount* 
1991/1011    
newmount(Mhead *mh, Chan *to) 
1990/0227    
{ 
1992/0711    
	Mount *m; 
1990/0227    
 
1992/0619    
	m = smalloc(sizeof(Mount)); 
	m->to = to; 
	m->head = mh; 
	incref(to); 
	m->mountid = incref(&mountid); 
	return m; 
1991/0514    
} 
 
void 
pgrpcpy(Pgrp *to, Pgrp *from) 
{ 
1991/1113    
	Mhead **h, **e, *f, **tom, **l, *mh; 
1991/1011    
	Mount *n, *m, **link; 
1991/0514    
 
1991/1011    
	rlock(&from->ns); 
 
1991/1127    
	*to->crypt = *from->crypt; 
1991/1011    
	e = &from->mnthash[MNTHASH]; 
1991/1113    
	tom = to->mnthash; 
1991/1011    
	for(h = from->mnthash; h < e; h++) { 
1991/1113    
		l = tom++; 
1991/1011    
		for(f = *h; f; f = f->hash) { 
1992/0619    
			mh = smalloc(sizeof(Mhead)); 
1991/1011    
			mh->from = f->from; 
			incref(mh->from); 
			*l = mh; 
1991/1113    
			l = &mh->hash; 
1991/1011    
			link = &mh->mount; 
			for(m = f->mount; m; m = m->next) { 
				n = newmount(mh, m->to); 
				*link = n; 
				link = &n->next;	 
			} 
1991/0514    
		} 
1991/1011    
	} 
	runlock(&from->ns); 
} 
1991/0514    
 
1991/1011    
void 
mountfree(Mount *m) 
{ 
	Mount *f; 
 
1992/0705    
	while(m) { 
		f = m->next; 
		close(m->to); 
		free(m); 
		m = f; 
	} 
1990/0227    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)