Some more background on this.
2016-04-02 14:42 GMT-03:00 Laurent Bercot:
>
> I have no idea what the TIOCSCTTY is for, though.
Apparently, on Linux and the BSDs, if 'fd' is an open file descriptor
to a terminal device, ioctl(fd, TIOCSCTTY, ...) (two or three
arguments) sets it as the controlling terminal [1][2]. I've seen calls
like that in sysvinit, agetty from util-linux and open-controlling-tty
from nosh.
> *What* device would you open as a controlling terminal in the general case?
>From what I understand from the code, sysvinit tries several devices
in order: the contents of the CONSOLE environment variable,
/dev/console, /dev/tty0 and finally /dev/null if everything else
failed. But it looks like it sets the controlling terminal for the
processes it is configured to wait for until they end, and only when
booting the machine (actions 'sysinit' and 'bootwait') or in
single-user runlevel (runlevel 's'). It doesn't for processes with a
'respawn' action in normal runlevels, for example. The relevant part
should be inside the spawn() function in the init.c file [3]. I get
lost easily trying to read that code, though :)
> I have no idea what systemd does and I don't think it would be a good
> indicator of what *should* be done anyway.
:)
For completeness, the unit file directives involved here are
StandardInput, StandardOutput and StandardError:
<
https://www.freedesktop.org/software/systemd/man/systemd.exec.html>
> I suspect that the use of open-controlling-tty is there to mimic systemd's
> behaviour exactly;
Maybe. Honoring the expected behaviour of a 'StandardInput=tty'
directive does seem to require setting the device stdin is connected
to as a controlling terminal, according to that documentation. But
surprisingly the unit file-to-bundle directory converter
(system-control convert-systemd-units) doesn't support
'StandardOutput=tty' and 'StandardError=tty' directives and ignores
them. Supposedly, if supported, 'StandardOutput=tty' appearing alone
in the unit file would make the service output to a terminal while
keeping stdin connected to /dev/null, and not set a controlling
terminal. That's why I said that in nosh's case I wasn't sure if the
whole controlling terminal thing is because of this limitation.
> [...] this conversation would have a place on the supervision ML
I was undecided about where to post it, but ultimately since I was
presenting it as a question about s6-rc, I chose the skaware ML.
Thanks,
G.
[1] <
http://man7.org/linux/man-pages/man4/tty_ioctl.4.html>
[2] <
https://www.freebsd.org/cgi/man.cgi?query=tty&sektion=4&manpath=FreeBSD+10.2-RELEASE>
[3] <
http://svn.savannah.nongnu.org/viewvc/%2Acheckout%2A/sysvinit/trunk/src/init.c?root=sysvinit&content-type=text%2Fplain>
Received on Sun Apr 03 2016 - 01:59:14 UTC