[systemd-devel] Odd /proc/$pid/fd symlinks in nspawn container

Ben Gamari ben at smart-cactus.org
Fri Jul 17 03:23:49 PDT 2015


Mantas Mikulėnas <grawity at gmail.com> writes:

> Note that devpts also supports multiple instances – the host /dev/pts is
> not the same as the guest /dev/pts'en. So my guess is that your stdio is
> attached to a pty from the *host*.
>
> Not really sure how that breaks job control though.
>
> Also, the fd symlinks are slightly magical; they can be followed and opened
> even if readlink returns garbage. (For example, a socket fd or a pipe fd
> wouldn't even *have* a path to return, yet the /proc symlink can be
> opened.) So that again shouldn't cause problems.
>
Fair enough. In that case perhaps the lack of job control is due to,

    bash: cannot set terminal process group (-1): Inappropriate ioctl for device

Indeed looking at jobs.c, it seems that bash tries to move the fd for
its tty to a high number (255 in this case) and will then try using it
to set the terminal process group. I see this pretty clearly in the
strace output,

    $ sudo systemd-nspawn -D$(realpath centos6.5-amd64) /usr/bin/strace -f -- bash -i
    ...
    19617 dup2(3, 255)                      = 255
    19617 close(3)                          = 0
    19617 ioctl(255, TIOCGPGRP, [32695])    = -1 ENOTTY (Inappropriate ioctl for device)
    19617 ioctl(255, TIOCGPGRP, [32695])    = -1 ENOTTY (Inappropriate ioctl for device)
    19617 fstat(2, {st_mode=S_IFCHR|0600, st_rdev=makedev(136, 7), ...}) = 0
    19617 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb741b8c000
    19617 write(2, "bash: cannot set terminal proces"..., 77) = 77

Note how both of the ioctls failed with ENOTTY, which according to the
tcgetpgrp manpage means,

    The calling process does not have a controlling terminal, or it has one
    but it is not described by fd, or, for tcsetpgrp(), this controlling
    terminal is no longer associated with the session of the calling
    process.

Why might this be the case? Does nspawn prevent the process from getting
a controlling tty?

Cheers,

- Ben


[1] http://stackoverflow.com/questions/11821378/what-does-bashno-job-control-in-this-shell-mean
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150717/d398f783/attachment.sig>


More information about the systemd-devel mailing list