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

2002/0109/port/devenv.c (diff list | history)

2001/1204/sys/src/9/port/devenv.c:5,162002/0109/sys/src/9/port/devenv.c:5,20 (short | long | prev | next)
Add #ec.
rsc Fri Mar 4 12:44:25 2005
1990/0227    
#include	"fns.h" 
1992/0111    
#include	"../port/error.h" 
1990/0227    
 
                 
1992/0623    
enum 
1990/0227    
{ 
1992/0623    
	Maxenvsize = 16300, 
1990/0227    
}; 
 
2002/0109    
static Egrp	*envgrp(Chan *c); 
static int	envwriteable(Chan *c); 
 
static Egrp	confegrp;	/* global environment group containing the kernel configuration */ 
 
1997/0327    
static int 
2001/0527    
envgen(Chan *c, char*, Dirtab*, int, int s, Dir *dp) 
1990/0227    
{ 
2001/1204/sys/src/9/port/devenv.c:22,282002/0109/sys/src/9/port/devenv.c:26,32
1999/1230    
		return 1; 
	} 
 
1993/0501    
	eg = up->egrp; 
2002/0109    
	eg = envgrp(c); 
1992/0623    
	qlock(eg); 
 
	for(e = eg->entries; e && s; e = e->link) 
2001/1204/sys/src/9/port/devenv.c:53,592002/0109/sys/src/9/port/devenv.c:57,75
1997/0327    
static Chan* 
1990/0227    
envattach(char *spec) 
{ 
	return devattach('e', spec); 
2002/0109    
	Chan *c; 
	Egrp *egrp = nil; 
 
	if(spec && *spec) { 
		if(strcmp(spec, "c") == 0) 
			egrp = &confegrp; 
		if(egrp == nil) 
			error(Ebadarg); 
	} 
 
	c = devattach('e', spec); 
	c->aux = egrp; 
	return c; 
1990/0227    
} 
 
2001/0527    
static Walkqid* 
2001/1204/sys/src/9/port/devenv.c:66,722002/0109/sys/src/9/port/devenv.c:82,88
2001/0527    
envstat(Chan *c, uchar *db, int n) 
1990/0227    
{ 
2001/0527    
	if(c->qid.type & QTDIR) 
1999/0122    
		c->qid.vers = up->egrp->vers; 
2002/0109    
		c->qid.vers = envgrp(c)->vers; 
2001/0527    
	return devstat(c, db, n, 0, 0, envgen); 
1990/0227    
} 
 
2001/1204/sys/src/9/port/devenv.c:76,872002/0109/sys/src/9/port/devenv.c:92,105
1991/0705    
	Egrp *eg; 
1992/0623    
	Evalue *e; 
1998/0512    
 
1993/0501    
	eg = up->egrp; 
2002/0109    
	eg = envgrp(c); 
2001/0527    
	if(c->qid.type & QTDIR) { 
1991/1018    
		if(omode != OREAD) 
1990/11211    
			error(Eperm); 
1992/0623    
	} 
	else { 
2002/0109    
		if(omode != OREAD && !envwriteable(c)) 
			error(Eperm); 
1992/0623    
		qlock(eg); 
1999/0122    
		e = envlookup(eg, nil, c->qid.path); 
1992/0623    
		if(e == 0) { 
2001/1204/sys/src/9/port/devenv.c:112,1182002/0109/sys/src/9/port/devenv.c:130,136
1990/11211    
		error(Eperm); 
1992/0623    
 
1991/1018    
	omode = openmode(omode); 
1993/0501    
	eg = up->egrp; 
2002/0109    
	eg = envgrp(c); 
1992/0623    
 
	qlock(eg); 
	if(waserror()) { 
2001/1204/sys/src/9/port/devenv.c:151,1572002/0109/sys/src/9/port/devenv.c:169,175
2001/0527    
	if(c->qid.type & QTDIR) 
1990/11211    
		error(Eperm); 
1992/0623    
 
1993/0501    
	eg = up->egrp; 
2002/0109    
	eg = envgrp(c); 
1992/0623    
	qlock(eg); 
	l = &eg->entries; 
	for(e = *l; e; e = e->link) { 
2001/1204/sys/src/9/port/devenv.c:196,2022002/0109/sys/src/9/port/devenv.c:214,220
2001/0527    
	if(c->qid.type & QTDIR) 
1990/0227    
		return devdirread(c, a, n, 0, 0, envgen); 
1992/0623    
 
1993/0501    
	eg = up->egrp; 
2002/0109    
	eg = envgrp(c); 
1992/0623    
	qlock(eg); 
1999/0122    
	e = envlookup(eg, nil, c->qid.path); 
1992/0623    
	if(e == 0) { 
2001/1204/sys/src/9/port/devenv.c:230,2362002/0109/sys/src/9/port/devenv.c:248,254
1992/0623    
	if(vend > Maxenvsize) 
1991/1018    
		error(Etoobig); 
1992/0623    
 
1993/0501    
	eg = up->egrp; 
2002/0109    
	eg = envgrp(c); 
1992/0623    
	qlock(eg); 
1999/0122    
	e = envlookup(eg, nil, c->qid.path); 
1992/0623    
	if(e == 0) { 
2001/1204/sys/src/9/port/devenv.c:260,2652002/0109/sys/src/9/port/devenv.c:278,284
1997/0408    
 
1997/0327    
	devreset, 
	devinit, 
2002/0109    
	devshutdown, 
1997/0327    
	envattach, 
	envwalk, 
	envstat, 
2001/1204/sys/src/9/port/devenv.c:314,3302002/0109/sys/src/9/port/devenv.c:333,405
1992/0625    
	} 
1991/1022    
} 
 
2002/0109    
static Egrp* 
envgrp(Chan *c) 
{ 
	if(c->aux == nil) 
		return up->egrp; 
	return c->aux; 
} 
 
static int 
envwriteable(Chan *c) 
{ 
	return iseve() || c->aux == nil; 
} 
 
1991/0927    
/* 
 *  to let the kernel set environment variables 
 */ 
void 
ksetenv(char *ename, char *eval) 
2002/0109    
ksetenv(char *ename, char *eval, int conf) 
1991/0927    
{ 
	Chan *c; 
2001/0527    
	char buf[2*KNAMELEN]; 
1991/0927    
                 
	sprint(buf, "#e/%s", ename); 
2002/0109    
	 
	snprint(buf, sizeof(buf), "#e%s/%s", conf?"c":"", ename); 
1991/0927    
	c = namec(buf, Acreate, OWRITE, 0600); 
1997/0327    
	devtab[c->type]->write(c, eval, strlen(eval), 0); 
	cclose(c); 
2002/0109    
} 
 
/* 
 * Return a copy of configuration environment as a sequence of strings. 
 * The strings alternate between name and value.  A zero length name string 
 * indicates the end of the list 
 */ 
char * 
getconfenv(void) 
{ 
	Egrp *eg = &confegrp; 
	Evalue *e; 
	char *p, *q; 
	int n; 
 
	qlock(eg); 
	if(waserror()) { 
		qunlock(eg); 
		nexterror(); 
	} 
	 
	/* determine size */ 
	n = 0; 
	for(e=eg->entries; e; e=e->link) 
		n += strlen(e->name) + e->len + 2; 
	p = malloc(n + 1); 
	if(p == nil) 
		error(Enomem); 
	q = p; 
	for(e=eg->entries; e; e=e->link) { 
		strcpy(q, e->name); 
		q += strlen(q) + 1; 
		memmove(q, e->value, e->len); 
		q[e->len] = 0; 
		/* move up to the first null */ 
		q += strlen(q) + 1; 
	} 
	*q = 0; 
	 
	poperror(); 
	qunlock(eg); 
	return p; 
1991/1102    
} 


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