]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
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)
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

index 6a6ee0942ce2600fef003ee9039a953a4731f4da..14fa041b71b6325c5a2695c27dbd8dd4fe57ce29 100644 (file)
@@ -971,15 +971,6 @@ static int lxc_create_ttys(struct lxc_handler *handler)
                }
        }
 
-       if (conf->ttys.tty_names) {
-               ret = setenv("container_ttys", conf->ttys.tty_names, 1);
-               if (ret < 0) {
-                       SYSERROR("Failed to set \"container_ttys=%s\"", conf->ttys.tty_names);
-                       goto on_error;
-               }
-               TRACE("Set \"container_ttys=%s\"", conf->ttys.tty_names);
-       }
-
        return 0;
 
 on_error:
index ee4bf4003bdc5d34946ea416eae4dbda4fa82146..3160459b46f26635cc6e10451f4aea24388f7477 100644 (file)
@@ -1372,7 +1372,7 @@ static int do_start(void *data)
        }
 
        if (handler->conf->ttys.tty_names) {
-               ret = putenv(handler->conf->ttys.tty_names);
+               ret = setenv("container_ttys", handler->conf->ttys.tty_names, 1);
                if (ret < 0) {
                        SYSERROR("Failed to set environment variable for container ptys");
                        goto out_warn_father;