Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/boot/aux.c

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


## diffname boot/aux.c 1992/0317
## diff -e /dev/null /n/bootesdump/1992/0317/sys/src/9/boot/aux.c
0a
#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
readenv(char *name, char *buf, int len)
{
	int f, n;
	char ename[2*NAMELEN];

	sprint(ename, "#e/%s", name);
	buf[0] = 0;
	f = open(ename, OREAD);
	if(f < 0)
		return -1;
	n = read(f, buf, len-1);
	if(n >= 0)
		buf[n] = 0;
	close(f);
	return 0;
}

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;

	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);
}

int
outin(char *prompt, char *def, int len)
{
	int n;
	char buf[256];

	do{
		print("%s[%s]: ", prompt, *def ? def : "no default");
		n = read(0, buf, len);
	}while(n==0);
	if(n < 0)
		fatal("can't read #c/cons; please reboot");
	if(n != 1){
		buf[n-1] = 0;
		strcpy(def, buf);
	}
	return n;
}
.
## diffname boot/aux.c 1992/0318
## diff -e /n/bootesdump/1992/0317/sys/src/9/boot/aux.c /n/bootesdump/1992/0318/sys/src/9/boot/aux.c
109a
	char buf[2*NAMELEN];
.
## diffname boot/aux.c 1992/0530
## diff -e /n/bootesdump/1992/0318/sys/src/9/boot/aux.c /n/bootesdump/1992/0530/sys/src/9/boot/aux.c
145a

void
getconffile(char *conffile, char *terminal)
{
	char *p, *q;

	*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++;
}
.
## diffname boot/aux.c 1992/0609
## diff -e /n/bootesdump/1992/0530/sys/src/9/boot/aux.c /n/bootesdump/1992/0609/sys/src/9/boot/aux.c
139c
		fatal("can't read #c/cons or timeout; please reboot");
.
137a
	alarm(0);
.
133a
	alarm(60*1000);
.
## diffname boot/aux.c 1992/0610
## diff -e /n/bootesdump/1992/0609/sys/src/9/boot/aux.c /n/bootesdump/1992/0610/sys/src/9/boot/aux.c
162a
	*conffile = 0;

	/* dump a trailig boot */
	n = strlen(s);
	if(n > 4 && strcmp(s + n - 4, "boot") == 0)
		*(s+n-4) = 0;
.
153a
	s = conffile;
.
152a
	char *s;
	int n;
.
148a
/*
 *  get second word of the terminal environment variable.   If it
 *  ends in "boot", get work of that part.
 */
.
81c
	f = open(name, OREAD);
.
79d
77d
74c
readfile(char *name, char *buf, int len)
.
## diffname boot/aux.c 1992/0617
## diff -e /n/bootesdump/1992/0610/sys/src/9/boot/aux.c /n/bootesdump/1992/0617/sys/src/9/boot/aux.c
137c
	if(cpuflag)
		alarm(0);
.
132c
	if(cpuflag)
		alarm(60*1000);
.
## diffname boot/aux.c 1992/0625
## diff -e /n/bootesdump/1992/0617/sys/src/9/boot/aux.c /n/bootesdump/1992/0625/sys/src/9/boot/aux.c
172c
	/* dump a trailing boot */
.
151c
 *  ends in "boot", get rid of that part.
.
## diffname boot/aux.c 1993/0330
## diff -e /n/bootesdump/1992/0625/sys/src/9/boot/aux.c /n/bootesdump/1993/0330/sys/src/9/boot/aux.c
88a
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;
}

.
## diffname boot/aux.c 1993/0406
## diff -e /n/bootesdump/1993/0330/sys/src/9/boot/aux.c /n/bootesdump/1993/0406/sys/src/9/boot/aux.c
122a
	print("post(%s)...", name);
.
## diffname boot/aux.c 1993/0407
## diff -e /n/bootesdump/1993/0406/sys/src/9/boot/aux.c /n/bootesdump/1993/0407/sys/src/9/boot/aux.c
123d
## diffname boot/aux.c 1993/0901
## diff -e /n/bootesdump/1993/0407/sys/src/9/boot/aux.c /n/fornaxdump/1993/0901/sys/src/brazil/boot/aux.c
154c
		return 1;
.
152a
	atnotify(catchint, 0);
.
149a
		if(cpuflag)
			alarm(15*1000);
.
146c
		alarm(15*1000);
.
144a
	atnotify(catchint, 1);
.
138a
static int
catchint(void *a, char *note)
{
	USED(a);
	if(strcmp(note, "alarm") == 0)
		return 1;
	return 0;
}

.
## diffname boot/aux.c 1997/0327
## diff -e /n/fornaxdump/1993/0901/sys/src/brazil/boot/aux.c /n/emeliedump/1997/0327/sys/src/brazil/boot/aux.c
186,201c
	for(i=0; lp && *lp && i<n; i++){
		while(*lp && strchr(sep, *lp) != 0)
			*lp++=0;
		if(*lp == 0)
			break;
		fields[i]=lp;
		while(*lp && strchr(sep, *lp) == 0)
			lp++;
	}
	return i;
.
182,184c
	int i;
.
175,180c
int
parsefields(char *lp, char **fields, int n, char *sep)
.
## diffname boot/aux.c 2000/0308
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/boot/aux.c /n/emeliedump/2000/0308/sys/src/9/boot/aux.c
174,190d
## diffname boot/aux.c 2000/1021
## diff -e /n/emeliedump/2000/0308/sys/src/9/boot/aux.c /n/emeliedump/2000/1021/sys/src/9/boot/aux.c
66,69c
	fprint(2, "boot fatal: %s: %r\n", s);
.
57,60c
	fprint(2, "boot: %s: %r\n", s);
.
## diffname boot/aux.c 2001/0527
## diff -e /n/emeliedump/2000/1021/sys/src/9/boot/aux.c /n/emeliedump/2001/0527/sys/src/9/boot/aux.c
123c
	snprint(buf, sizeof buf, "#s/%s", srvname);
.
115c
	char buf[64];
.
102c
	snprint(ename, sizeof ename, "#e/%s", name);
.
100c
	char ename[64];
.
63c
	char buf[ERRMAX];

	buf[0] = '\0';
	errstr(buf, sizeof buf);
	fprint(2, "boot: %s: %s\n", s, buf);
.
57c
	char buf[ERRMAX];

	buf[0] = '\0';
	errstr(buf, sizeof buf);
	fprint(2, "boot: %s: %s\n", s, buf);
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.