]> git.ipfire.org Git - thirdparty/lxc.git/commit
lxc/conf,start: fix setting container_ttys environment variable 4544/head
authorRoman Azarenko <roman.azarenko+gh@genexis.eu>
Tue, 22 Apr 2025 07:16:13 +0000 (09:16 +0200)
committerRoman Azarenko <roman.azarenko+gh@genexis.eu>
Tue, 22 Apr 2025 09:39:29 +0000 (11:39 +0200)
commit0636ec66b950dd42342fc937cbba97365e92f01e
tree101e2cef8f2454ea17f8e61d826f0d6c0505f7a8
parenteb971465232db835614d560634cc3966a87abf4e
lxc/conf,start: fix setting container_ttys environment variable

Commit eae44ce19931 ("conf: fix append_ttyname()") changed the format
of `conf->ttys.tty_names`, where the `container_ttys=` prefix was
removed.

This seems to have been taken into account in `lxc_create_ttys()` in
`src/lxc/conf.c`, however that's not enough. `do_start()` in
`src/lxc/start.c` clears the environment, and then does `putenv(...)`
directly on the value of `tty_names`. As it no longer has the
`container_ttys=` prefix, this call doesn't have the intended effect.

This behaviour is also confirmed via `ltrace` when doing `lxc-start`:

[pid 53587] liblxc.so.1->setenv("container_ttys", "pts/1 pts/2 pts/3 pts/4", 1) = 0
[pid 53587] liblxc.so.1->clearenv(0, 1, 0, 0)                                   = 0
[pid 53587] liblxc.so.1->putenv("container=lxc")                                = 0
[pid 53587] liblxc.so.1->putenv("pts/1 pts/2 pts/3 pts/4")                      = 0

Given that `do_start()` clears the environment anyway, there is no
reason for another `setenv()` call in `lxc_create_ttys()`, and a fix
is required for `putenv()` in `do_start()`.

Change the `putenv()` call to `setenv()` in `do_start()` to account
for the change of format in `conf->ttys.tty_names`. Remove extraneous
`setenv()` from `lxc_create_ttys()`.

Fixes #4198

Fixes: eae44ce19931 ("conf: fix append_ttyname()")
Signed-off-by: Roman Azarenko <roman.azarenko+gh@genexis.eu>
src/lxc/conf.c
src/lxc/start.c