From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/gio/cursor/gtrdiscon.x | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 sys/gio/cursor/gtrdiscon.x (limited to 'sys/gio/cursor/gtrdiscon.x') diff --git a/sys/gio/cursor/gtrdiscon.x b/sys/gio/cursor/gtrdiscon.x new file mode 100644 index 00000000..5eba23f4 --- /dev/null +++ b/sys/gio/cursor/gtrdiscon.x @@ -0,0 +1,66 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include + +# 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 -- cgit