summaryrefslogtreecommitdiff
path: root/sys/src/cmd/vt/event.c
blob: 12f1f0e439f93c502822d6e3aa268d8569f50a0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>
#include "cons.h"

#define	BUFSIZ	4000

extern int	outfd;

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

	switch((hostpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG))) {
	case 0:
		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");
}