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

1993/0407/boot/aux.c (diff list | history)

1993/0407/sys/src/9/boot/aux.c:1,1891993/0901/sys/src/9/boot/aux.c:1,202 (short | long | prev | next)
1992/0317    
#include <u.h> 
#include <libc.h> 
#include <../boot/boot.h> 
 
int 
plumb(char *dir, char *dest, int *efd, char *here) 
{ 
	char buf[128]; 
	char name[128]; 
	int n; 
 
	sprint(name, "%s/clone", dir); 
	efd[0] = open(name, ORDWR); 
	if(efd[0] < 0) 
		return -1; 
	n = read(efd[0], buf, sizeof(buf)-1); 
	if(n < 0){ 
		close(efd[0]); 
		return -1; 
	} 
	buf[n] = 0; 
	sprint(name, "%s/%s/data", dir, buf); 
	if(here){ 
		sprint(buf, "announce %s", here); 
		if(sendmsg(efd[0], buf) < 0){ 
			close(efd[0]); 
			return -1; 
		} 
	} 
	sprint(buf, "connect %s", dest); 
	if(sendmsg(efd[0], buf) < 0){ 
		close(efd[0]); 
		return -1; 
	} 
	efd[1] = open(name, ORDWR); 
	if(efd[1] < 0){ 
		close(efd[0]); 
		return -1; 
	} 
	return efd[1]; 
} 
 
int 
sendmsg(int fd, char *msg) 
{ 
	int n; 
 
	n = strlen(msg); 
	if(write(fd, msg, n) != n) 
		return -1; 
	return 0; 
} 
 
void 
warning(char *s) 
{ 
	char buf[ERRLEN]; 
 
	errstr(buf); 
	fprint(2, "boot: %s: %s\n", s, buf); 
} 
 
void 
fatal(char *s) 
{ 
	char buf[ERRLEN]; 
 
	errstr(buf); 
	fprint(2, "boot: %s: %s\n", s, buf); 
	exits(0); 
} 
 
int 
1992/0610    
readfile(char *name, char *buf, int len) 
1992/0317    
{ 
	int f, n; 
 
	buf[0] = 0; 
1992/0610    
	f = open(name, OREAD); 
1992/0317    
	if(f < 0) 
		return -1; 
	n = read(f, buf, len-1); 
	if(n >= 0) 
		buf[n] = 0; 
	close(f); 
	return 0; 
} 
 
1993/0330    
int 
writefile(char *name, char *buf, int len) 
{ 
	int f, n; 
 
	f = open(name, OWRITE); 
	if(f < 0) 
		return -1; 
	n = write(f, buf, len); 
	close(f); 
	return (n != len) ? -1 : 0; 
} 
 
1992/0317    
void 
setenv(char *name, char *val) 
{ 
	int f; 
	char ename[2*NAMELEN]; 
 
	sprint(ename, "#e/%s", name); 
	f = create(ename, 1, 0666); 
	if(f < 0) 
		return; 
	write(f, val, strlen(val)); 
	close(f); 
} 
 
void 
srvcreate(char *name, int fd) 
{ 
	char *srvname; 
	int f; 
1992/0318    
	char buf[2*NAMELEN]; 
1992/0317    
 
	srvname = strrchr(name, '/'); 
	if(srvname) 
		srvname++; 
	else 
		srvname = name; 
 
	sprint(buf, "#s/%s", srvname); 
	f = create(buf, 1, 0666); 
	if(f < 0) 
		fatal(buf); 
	sprint(buf, "%d", fd); 
	if(write(f, buf, strlen(buf)) != strlen(buf)) 
		fatal("write"); 
	close(f); 
} 
 
1993/0901    
static int 
catchint(void *a, char *note) 
{ 
	USED(a); 
	if(strcmp(note, "alarm") == 0) 
		return 1; 
	return 0; 
} 
 
1992/0317    
int 
outin(char *prompt, char *def, int len) 
{ 
	int n; 
	char buf[256]; 
 
1993/0901    
	atnotify(catchint, 1); 
1992/0617    
	if(cpuflag) 
		alarm(60*1000); 
1993/0901    
		alarm(15*1000); 
1992/0317    
	do{ 
		print("%s[%s]: ", prompt, *def ? def : "no default"); 
		n = read(0, buf, len); 
1993/0901    
		if(cpuflag) 
			alarm(15*1000); 
1992/0317    
	}while(n==0); 
1992/0617    
	if(cpuflag) 
		alarm(0); 
1993/0901    
	atnotify(catchint, 0); 
1992/0317    
	if(n < 0) 
1992/0609    
		fatal("can't read #c/cons or timeout; please reboot"); 
1993/0901    
		return 1; 
1992/0317    
	if(n != 1){ 
		buf[n-1] = 0; 
		strcpy(def, buf); 
	} 
	return n; 
} 
1992/0530    
 
1992/0610    
/* 
 *  get second word of the terminal environment variable.   If it 
1992/0625    
 *  ends in "boot", get rid of that part. 
1992/0610    
 */ 
1992/0530    
void 
getconffile(char *conffile, char *terminal) 
{ 
	char *p, *q; 
1992/0610    
	char *s; 
	int n; 
1992/0530    
 
1992/0610    
	s = conffile; 
1992/0530    
	*conffile = 0; 
	p = terminal; 
	if((p = strchr(p, ' ')) == 0 || p[1] == ' ' || p[1] == 0) 
		return; 
	p++; 
	for(q = p; *q && *q != ' '; q++) 
		; 
	while(p < q) 
		*conffile++ = *p++; 
1992/0610    
	*conffile = 0; 
 
1992/0625    
	/* dump a trailing boot */ 
1992/0610    
	n = strlen(s); 
	if(n > 4 && strcmp(s + n - 4, "boot") == 0) 
		*(s+n-4) = 0; 
1992/0530    
} 


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