Skip to content

Commit facb5c4

Browse files
docs: add documentation for tty: service option
1 parent 440f330 commit facb5c4

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

doc/config/service-opts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Other run/task/service options are:
4646
* `cgroup.NAME[,opts]` or `cgroup:opts` -- see the [Cgroups](cgroups.md) section
4747
* `env:[-]/path/to/env` -- see the [Service Environment](service-env.md) section
4848
* `log:...` -- see [Redirecting Output](logging.md#redirecting-output)
49+
* `tty:<dev>` -- see [Controlling TTY](tty.md#controlling-tty)
4950
* `nowarn` -- see [Conditional Loading](services.md#conditional-loading)
5051
* `notify:...` -- see [Service Synchronization](service-sync.md)
5152
* `if:...` -- see [Conditional Execution](services.md#conditional-execution)

doc/config/tty.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,31 @@ board bringup and system debugging it can come in handy.
8383

8484
One can also use the `service` stanza to start a stand-alone shell:
8585

86-
service [12345] /bin/sh -l
86+
service [12345] /bin/sh -l
87+
88+
Controlling TTY for Services
89+
----------------------------
90+
91+
The `tty:<dev>` option gives a `run`, `task`, or `service` a controlling
92+
terminal on the given device. The device is opened, set as the
93+
controlling terminal for the session (after `setsid()`), and connected to
94+
the process's stdin, stdout, and stderr. A default `TERM` environment
95+
variable is set based on the device type: `vt102` for serial lines and
96+
`linux` for virtual terminals.
97+
98+
`<dev>` may be a device node like `/dev/ttyS0`, or the special keyword
99+
`@console` (see above). Note that `@console` expands only to the
100+
first console, not all.
101+
102+
When `tty:` is combined with `log:`, stdout and stderr are redirected
103+
to the log sink instead of the TTY, but stdin remains connected to the
104+
TTY device.
105+
106+
> The `tty:<dev>` option is for `run`, `task`, and `service` stanzas only.
107+
> The `tty` directive itself (for getty/login) has its own syntax, see
108+
> above.
109+
110+
**Example:**
111+
112+
service [2345] tty:/dev/ttyS0 /usr/sbin/foo -- Foo on serial console
113+
task [S] tty:@console my-setup-script -- Board bringup on console

man/finit.conf.5

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,37 @@ is
744744
and the default
745745
.Cm tag
746746
identity is the basename of the service or run/task command.
747+
.It Cm tty:\&<dev>
748+
Give the
749+
.Cm run , task ,
750+
or
751+
.Cm service
752+
a controlling terminal on
753+
.Cm <dev> .
754+
The device is opened, set as the controlling terminal for the session
755+
(after
756+
.Fn setsid ) ,
757+
and connected to stdin, stdout, and stderr.
758+
A default
759+
.Ev TERM
760+
variable is set based on the device type:
761+
.Cm vt102
762+
for serial lines and
763+
.Cm linux
764+
for virtual terminals.
765+
.Cm <dev>
766+
may be a device node like
767+
.Pa /dev/ttyS0 ,
768+
or the special keyword
769+
.Cm @console
770+
(see TTYs and Consoles above).
771+
When combined with
772+
.Cm log: ,
773+
stdout and stderr are redirected to the log sink instead, but stdin
774+
remains connected to the TTY device.
775+
.Bd -unfilled -offset indent
776+
service [2345] tty:/dev/ttyS0 /usr/sbin/foo -- Foo on serial console
777+
.Ed
747778
.El
748779
.Sh RESCUE MODE
749780
Finit supports a rescue mode which is activated by the

0 commit comments

Comments
 (0)