cmd – interface to host operating system commands|
bind –a '#C' / |
Cmd provides a way to run commands in the underlying operating
system's command interpreter of drawterm or when Inferno is running
hosted. It serves a three–level directory that is conventionally
bound behind the root directory. The top of the hierarchy is a
directory cmd, that contains a clone file and zero or
more numbered directories. Each directory represents a distinct
connection to the host's command interpreter. The directory contains
five files: ctl, data, stderr, status and wait, used as described
below. Opening the clone file reserves a connection: it is equivalent
to opening the ctl file of an unused
connection directory, creating a new one if necessary. |
The file ctl controls a connection. When read, it returns the decimal number n of its connection directory. Thus, opening and reading clone allocates a connection directory and reveals the number of the allocated directory, allowing the other files to be named (eg, /cmd/n/data).
Ctl accepts the following textual commands, allowing quoting as
interpreted by parsecmd(2):
The stderr file provides a similar read–only connection to the error output from the command. If the stderr file is not opened, the error output will be discarded.
Once started, a host command runs until it terminates or until it is killed, by using the kill or killonclose requests above, or by closing all ctl, data and wait files for a connection.
The read–only status file provides a single line giving the status
of the connection (not the command), of the form:
n The cmd directory number.
opensThe decimal number of open file descriptors for ctl, data and wait.
state The status of the interface in directory n:
arg0 The host command name (without arguments).
The read–only wait file must be opened before starting a command via ctl. When read, it blocks until the command terminates. The read then returns with a single status line, to be parsed using tokenize (see getfields(2)). There are five fields: host process ID (or 0 if unknown); time the command spent in user code in milliseconds (or 0); time spent in system code in milliseconds (or 0); real time in milliseconds (or 0); and a string giving the exit status of the command. The exit status is host–dependent, except that an empty string means success, and a non–empty string contains a diagnostic.
A write to ctl returns with an error and sets the error string
if a command cannot be started or killed successfully.|