Plan 9 from Bell Labs’s /usr/web/sources/patch/applied/vtupdate/event.c.new

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


#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>
#include "cons.h"

#define	BUFSIZ	4000

extern int	outfd;
extern int	wctlout;

int	hostpid;

void
edie(void)
{
	static int dead = 0;

	if(dead++ > 0) return;
	close(outfd);
	postnote(PNGROUP, getpid(), "exit");
}

static int
start_host(void)
{
	int	fd;

	cs = consctl();
	if(cs == 0){
		perror("consctl");
		exits("consctl");
	}

	if(wflag){
		bind("#|", "/mnt/temp", MREPL);
		wctlout = open("/mnt/temp/data", OWRITE);
	}

	switch((hostpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG))) {
	case 0:
		if(wflag)
			bind("/mnt/temp/data1", "/dev/wctl", MREPL);
		fd = open("/dev/cons", OREAD);
		dup(fd,0);
		if(fd != 0)
			close(fd);
		fd = open("/dev/cons", OWRITE);
		dup(fd,1);
		dup(fd,2);
		if(fd != 1 && fd !=2)
			close(fd);
		execl("/bin/rc","rcX",nil);
		fprint(2,"failed to start up rc\n");
		_exits("rc");
	case -1:
		fprint(2,"rc startup: fork error\n");
		_exits("rc_fork");
	}

	return open("/mnt/cons/cons/data", ORDWR);
}

void
ebegin(int Ehost)
{

	atexit(edie);

	einit(Emouse|Ekeyboard);

	outfd = start_host();
	if( estart(Ehost, outfd, BUFSIZ) != Ehost) {
		exits("event init error");
	}
}

void
send_interrupt(void)
{
	postnote(PNGROUP, hostpid,"interrupt");
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].