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

1993/0501/boot/boot.c (diff list | history)

1993/0402/sys/src/9/boot/boot.c:1,141993/0501/sys/src/9/boot/boot.c:1,12 (short | long | prev | next)
1992/0317    
#include <u.h> 
#include <libc.h> 
1993/0330    
#include <auth.h> 
1993/0501    
#include <fcall.h> 
1992/0318    
#include "../boot/boot.h" 
1992/0317    
 
#define DEFSYS "bootes" 
typedef struct Net	Net; 
typedef struct Flavor	Flavor; 
 
int	printcol; 
                 
char	cputype[NAMELEN]; 
char	terminal[NAMELEN]; 
char	sys[2*NAMELEN]; 
1993/0402/sys/src/9/boot/boot.c:15,291993/0501/sys/src/9/boot/boot.c:13,27
1992/0317    
char	username[NAMELEN]; 
1992/0522    
char	bootfile[3*NAMELEN]; 
1992/0530    
char	conffile[NAMELEN]; 
1992/0317    
                 
int mflag; 
int fflag; 
int kflag; 
1992/0322    
int aflag; 
1992/0323    
int pflag; 
1993/0330    
int afd = -1; 
1992/0317    
                 
1993/0501    
int	printcol; 
int	mflag; 
int	fflag; 
int	kflag; 
int	aflag; 
int	pflag; 
int	afd = -1; 
1992/0530    
static void	swapproc(void); 
1993/0501    
static void	recover(Method*); 
1992/0530    
static Method	*rootserver(char*); 
1992/0317    
 
void 
1993/0402/sys/src/9/boot/boot.c:87,921993/0501/sys/src/9/boot/boot.c:85,99
1992/0317    
	 */ 
1992/0318    
	(*pword)(islocal, mp); 
1992/0317    
 
1993/0501    
	switch(rfork(RFPROC|RFNAMEG|RFFDG)) { 
	case -1: 
		print("failed to start recover: %r\n"); 
		break; 
	case 0: 
		recover(mp); 
		break; 
	} 
 
1992/0317    
	/* 
	 *  connect to the root file system 
	 */ 
1993/0402/sys/src/9/boot/boot.c:93,981993/0501/sys/src/9/boot/boot.c:100,106
1992/0317    
	fd = (*mp->connect)(); 
	if(fd < 0) 
		fatal("can't connect to file server"); 
1993/0501    
	nop(fd); 
1992/0909    
	if(!islocal && !ishybrid){ 
1992/0318    
		if(cfs) 
			fd = (*cfs)(fd); 
1993/0402/sys/src/9/boot/boot.c:132,1381993/0501/sys/src/9/boot/boot.c:140,145
1992/0317    
	settime(islocal); 
1993/0330    
	close(afd); 
1992/0317    
	swapproc(); 
1993/0330    
	remove("#e/password"); 
1992/0317    
 
	sprint(cmd, "/%s/init", cputype); 
1992/0322    
	sprint(flags, "-%s%s%s", cpuflag ? "c" : "t", mflag ? "m" : "", aflag ? "a" : ""); 
1993/0402/sys/src/9/boot/boot.c:183,1881993/0501/sys/src/9/boot/boot.c:190,233
1992/0520    
	return 0;		/* not reached */ 
1992/0317    
} 
 
1993/0501    
int 
nop(int fd) 
{ 
	int n; 
	Fcall hdr; 
	char buf[128]; 
 
	print("boot: nop..."); 
	hdr.type = Tnop; 
	hdr.tag = NOTAG; 
	n = convS2M(&hdr, buf); 
	if(write(fd, buf, n) != n){ 
		fatal("write nop"); 
		return 0; 
	} 
reread: 
	n = read(fd, buf, sizeof buf); 
	if(n <= 0){ 
		fatal("read nop"); 
		return 0; 
	} 
	if(n == 2) 
		goto reread; 
	if(convM2S(buf, &hdr, n) == 0) { 
		fatal("format nop"); 
		return 0; 
	} 
	if(hdr.type != Rnop){ 
		fatal("not Rnop"); 
		return 0; 
	} 
	if(hdr.tag != NOTAG){ 
		fatal("tag not NOTAG"); 
		return 0; 
	} 
	return 1; 
} 
 
1992/0530    
static void 
1992/0317    
swapproc(void) 
{ 
1993/0402/sys/src/9/boot/boot.c:195,1981993/0501/sys/src/9/boot/boot.c:240,318
1992/0317    
	} 
	if(write(fd, "start", 5) <= 0) 
		warning("starting swap kproc"); 
1993/0501    
	close(fd); 
} 
 
void 
reattach(int rec, Method *amp, char *buf) 
{ 
	char *mp; 
	int fd, n, sv[2]; 
	char tmp[64], *p; 
 
	mp = strchr(buf, ' '); 
	if(mp == 0) 
		goto fail; 
	*mp++ = '\0'; 
 
	p = strrchr(buf, '/'); 
	if(p == 0) 
		goto fail; 
	*p = '\0'; 
 
	sprint(tmp, "%s/remote", buf); 
	fd = open(tmp, OREAD); 
	if(fd < 0) 
		goto fail; 
	n = read(fd, tmp, sizeof(tmp)); 
	if(n < 0) 
		goto fail; 
	close(fd); 
	tmp[n-1] = '\0'; 
 
	print("boot: Service %s down, wait...\n", tmp); 
 
	p = strrchr(buf, '/'); 
	if(p == 0) 
		goto fail; 
	*p = '\0'; 
 
	while(plumb(buf, tmp, sv, 0) < 0) 
		sleep(30); 
 
	nop(sv[1]); 
	doauthenticate(sv[1], amp); 
 
	print("boot: Service %s Ok\n", tmp); 
 
	n = sprint(tmp, "%d %s", sv[1], mp); 
	if(write(rec, tmp, n) < 0) { 
		errstr(tmp); 
		print("write recover: %s\n", tmp); 
	} 
	exits(0); 
fail: 
	print("recover fail: %s\n", buf); 
	exits(0); 
} 
 
void 
recover(Method *mp) 
{ 
	int fd, n; 
	char buf[256]; 
 
	fd = open("#/./recover", ORDWR); 
	if(fd < 0) 
		exits(0); 
 
	for(;;) { 
		n = read(fd, buf, sizeof(buf)); 
		if(n < 0) 
			exits(0); 
		buf[n] = '\0'; 
 
		if(fork() == 0) 
			reattach(fd, mp, buf); 
	} 
1992/0317    
} 


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