aboutsummaryrefslogtreecommitdiff
path: root/sys/gio/cursor/gtrdiscon.x
diff options
context:
space:
mode:
Diffstat (limited to 'sys/gio/cursor/gtrdiscon.x')
-rw-r--r--sys/gio/cursor/gtrdiscon.x66
1 files changed, 66 insertions, 0 deletions
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 <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