Plumber.mesa
Copyright Ó 1989, 1992 by Xerox Corporation. All rights reserved.
Michael Plass, September 25, 1989 3:36:30 pm PDT
Peter B. Kessler, January 15, 1990 5:36:06 pm PST
Norman Adams, May 18, 1990 10:43 am PDT
Welch, March 7, 1991 4:42 pm PST - extracted PseudoTerminal
Willie-s, June 12, 1992 2:41 pm PDT
Wire:
TYPE ~
REF WireRep ¬
NIL;
-- Wire is here only for Conduit
WireRep:
TYPE ~
RECORD [
active: BOOLEAN ¬ FALSE,
connectedTo: Rope.ROPE ¬ NIL,
process: PROCESS ¬ NIL,
result: REF ¬ NIL
];
-- Conduit should be opaque, but that makes reloading impossible, or requires that we add a private interface soley for the purpose of hiding Conduit. Fooey.
Conduit: PUBLIC TYPE = REF ConduitRep;
ConduitRep:
PUBLIC TYPE =
MONITORED RECORD [
closing: BOOLEAN ¬ FALSE,
pty: PseudoTerminal.PseudoTerminal ¬ NIL,
stdin: Wire,
stdout: Wire,
stderr: Wire,
message: REF
];
SpawnResult: TYPE = RECORD [res: INT, errno: INT, details: REF];
Error:
ERROR [code:
ATOM, msg: Rope.
ROPE];
Spawn:
PROC [
command: Rope.
ROPE, wd: Rope.
ROPE,
stdin:
REF, stdout:
REF, stderr:
REF,
exec:
BOOL, tty:
BOOL, debug:
BOOL ¬
FALSE, noisy:
BOOL ¬
FALSE,
reportSourceFD:
PROC[fd: UnixTypes.FileDescriptor] ¬
NIL
]
RETURNS [SpawnResult];
The command is the command to hand to a /bin/sh.
The wd is the working directory to cd to before spawning the shell.
The input REF's may be file names (Rope.ROPE, REF TEXT), or IO.STREAM's.
The returned SpawnResult.details is a LIST of the result of the spawn, errno, and the results of the stream copiers.
If exec then exec the command in the shell.
If tty then add -t /dev/tty?? and -p /dev/pty?? options to command.
The procedure reportSourceFD is called on the source Unix file descriptor.
Spawn[...stdin, stdout, stderr...] is equivalent to
SpawnWithConduit[...MakeConduit[stdin, stdout, stderr]...]. The only advantage to the latter is that if you hang on to the conduit, you can call Terminate on it.
SpawnWithConduit: PROC [
conduit: Conduit,
command: Rope.ROPE, wd: Rope.ROPE,
exec: BOOLEAN, tty: BOOLEAN,
reportSourceFD: PROC[fd: UnixTypes.FileDescriptor] ¬ NIL
]
RETURNS [SpawnResult];
MakeConduit:
PROC [stdin, stdout, stderr:
REF, debug:
BOOL¬
FALSE, noisy:
BOOL¬
FALSE]
RETURNS [Conduit];
Terminate: PROC [conduit: Conduit, reason: ATOM];
}.