Get ttyname() to work properly in containers
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
glibc (Ubuntu) |
Fix Released
|
High
|
Adam Conrad | ||
multitail (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned | ||
screen (Ubuntu) |
Fix Released
|
High
|
Christian Brauner | ||
tmux (Ubuntu) |
Fix Released
|
High
|
Christian Brauner |
Bug Description
For the past year or so, the LXD team has been trying to resolve an issue affecting screen, tmux and a bunch of other software (including the "tty" command).
The problem comes from the fact that when attaching to a container, your terminal's pts device comes from the host and therefore can't be found in /dev/pts/.
glibc makes the assumption that it can readlink /proc/self/fd/0 and that the target path will exist. This simply isn't true as the symlink target returned by the kernel, is confusingly relative to the host's root and not the container's.
Which means that if the target happens to exist, it's actually going to be an entirely different pts device from the one that you're actually attached to.
You therefore need to do something along the lines of:
- Resolve the symlink. If the target doesn't exist, return the symlink as the ttyname.
- If the target does exist, check that its major and minor matches that of the symlink itself, if it doesn't, then return the symlink rather than the target.
That's the ideal approach which makes existing software keep working properly without the need for any added code. After about a year of bikeshedding, the proposed glibc upstream fix has now evolved to instead returning ENODEV in the is_pty function. This allows downstream glibc users to detect this case and then use /proc/self/fd/0 rather than the return value of ttyname() but means every software using ttyname() now needs fixing.
As we very much care about Ubuntu running properly inside LXD containers, our suggested patchset includes both the ENODEV patch as is still being considered by upstream (stuck on legal validation) AND another patch which has ttyname() return the symlink when it receives the ENODEV.
We feel this is the best way to fix the problem entirely right now. Once glibc upstream merges the ENODEV side of this and all affected software get fixed upstream to deal with it, we'll then be able to drop that patch without causing any regressions.
tags: | added: patch |
Changed in glibc (Ubuntu): | |
status: | Triaged → Fix Committed |
Changed in screen (Ubuntu): | |
status: | In Progress → Fix Committed |
Changed in screen (Ubuntu): | |
status: | Fix Committed → Triaged |
Changed in screen (Ubuntu): | |
assignee: | Christian Brauner (cbrauner) → Stéphane Graber (stgraber) |
status: | Triaged → Fix Committed |
Changed in tmux (Ubuntu): | |
status: | Triaged → In Progress |
Changed in tmux (Ubuntu): | |
status: | In Progress → Fix Released |
Changed in screen (Ubuntu): | |
status: | Fix Released → In Progress |
Upstream threads: https:/ /sourceware. org/cgi- bin/search. cgi?q=ttyname+ and+ttyname_ r&cmd=Search% 21&form= extended& m=all&ps= 10&fmt= long&wm= wrd&sp= 1&sy=1& wf=2221& type=&GroupBySi te=no&ul= %2Fml%2Flibc- alpha%2F% 25
We've been getting about a report a week about things failing due to this bug so we really need it sorted this time (most reports are for screen/tmux and tools that use them like do-release- upgrade) .