aboutsummaryrefslogtreecommitdiff
path: root/sys/gio/cursor/gtrdiscon.x
blob: 5eba23f423ee000b4384d80e8545715bb810a494 (plain) (blame)
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
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	<gio.h>

# GTR_DISCONNECT -- Disconnect from a kernel subprocess.  To achieve an orderly
# shutdown we process any outstanding XMIT or XFER requests, then transmit an
# end of file (zero length record) to the kernel task when it reads from the
# graphics stream.  The kernel should then shutdown and eventually we will
# receive "bye" from the process.  We then call PRCLOSE to shutdown the
# process for good.  Note: we do not expect anything but an XFER (read) request
# on the graphics stream, but it seems prudent to do something reasonable if
# some other request is received.

procedure gtr_disconnect (pid, in, out, stream)

int	pid			# process id of subprocess
int	in, out			# command i/o streams of the subprocess
int	stream			# graphics stream used by kernel

pointer	sp, sp2, lbuf, buf
int	pseudofile, nchars, junk
bool	streq()
int	getline(), read(), strncmp(), psio_isxmit(), prclose(), pr_findproc()
errchk	getline, prclose, read, write

begin
	call smark (sp)
	call salloc (lbuf, SZ_LINE, TY_CHAR)

	while (getline (in, Memc[lbuf]) != EOF) {
	    if (streq (Memc[lbuf], "bye\n") ||
		strncmp (Memc[lbuf], "ERROR", 5) == 0) {

		junk = prclose (pid)
		break

	    } else if (Memc[lbuf] == '!') {
		# OS escape.
		call proscmd (pr_findproc(pid), Memc[lbuf+1])

	    } else {
		call smark (sp2)

		switch (psio_isxmit (Memc[lbuf], pseudofile, nchars)) {
		case XMIT:
		    call salloc (buf, nchars, TY_CHAR)
		    nchars = read (in, Memc[buf], nchars)
		    if (nchars > 0)
			if (pseudofile == STDOUT || pseudofile == STDERR)
			    call write (pseudofile, Memc[buf], nchars)

		case XFER:
		    call salloc (buf, nchars, TY_CHAR)
		    if (pseudofile == STDIN)
			nchars = read (pseudofile, Memc[buf], nchars)
		    else
			nchars = 0		# this is the EOF
		    call psio_xfer (out, Memc[buf], nchars)
		}

		call sfree (sp2)
	    }
	}

	call sfree (sp)
end