Skip to content

pkg/utils: Preserve environment variables set by a KDE session and Konsole #1698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

debarshiray
Copy link
Member

@debarshiray debarshiray commented Aug 6, 2025

See the individual commits for details.

#1449
#1696

debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Aug 6, 2025
A KDE session sets some environment variables to influence the behaviour
of various programs and to access various settings [1].  eg., if the
KDE_SESSION_VERSION environment variable is absent then applications
won't respect KDE's theme or display scaling settings.

These environment variables are not meant to be set by the shell's
start-up scripts, but directly by KDE, and hence needs to be preserved
across the host operating system and Toolbx container.

[1] https://userbase.kde.org/KDE_System_Administration/Environment_Variables

containers#1696
containers#1698
@debarshiray debarshiray force-pushed the wip/rishi/bkoropoff-kde-envvar branch from e7e040d to 610b291 Compare August 6, 2025 23:54
Copy link

debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Aug 7, 2025
A KDE session sets some environment variables to influence the behaviour
of various programs and to access various settings [1].  eg., if the
KDE_SESSION_VERSION environment variable is absent then applications
won't respect KDE's theme or display scaling settings.

These environment variables are not meant to be set by the shell's
start-up scripts, but directly by KDE, and hence needs to be preserved
across the host operating system and Toolbx container.

[1] https://userbase.kde.org/KDE_System_Administration/Environment_Variables

containers#1696
containers#1698
@debarshiray debarshiray force-pushed the wip/rishi/bkoropoff-kde-envvar branch from 610b291 to 6ef02da Compare August 7, 2025 13:07
@debarshiray
Copy link
Member Author

Build failed. https://softwarefactory-project.io/zuul/t/local/buildset/169e15b6a8734b49bdc557975702c654

system-test-fedora-rawhide-commands-options FAILURE in 1h 17m 29s

The error is the same as we have seen recently on Fedora Rawhide:

fedora-rawhide | not ok 186 run: Try /etc as a command
fedora-rawhide | # tags: commands-options
fedora-rawhide | # (from function `assert_line' in file test/system/libs/bats-assert/src/assert.bash, line 488,
fedora-rawhide | #  in test file test/system/104-run.bats, line 814)
fedora-rawhide | #   `assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory"' failed
fedora-rawhide | # ~ /home/zuul-worker/src/github.com/containers/toolbox
fedora-rawhide | #
fedora-rawhide | # -- line differs --
fedora-rawhide | # index    : 1
fedora-rawhide | # expected : bash: line 1: exec: /etc: cannot execute: Is a directory
fedora-rawhide | # actual   : Error: failed to invoke command /etc in container fedora-toolbox-43
fedora-rawhide | # --

It seems unrelated, and is probably due to some change in Fedora Rawhide.

debarshiray pushed a commit to debarshiray/toolbox that referenced this pull request Aug 7, 2025
Konsole injects the name of the current profile, and the identifiers
of the current tab and window into the process running inside it
through the KONSOLE_PROFILE_NAME, KONSOLE_DBUS_SESSION and
KONSOLE_DBUS_WINDOW environment variables respectively [1,2,3].  These
are used by programs like Neovim to detect the terminal features
supported by Konsole [4,5], or by users to save the shell's history
separately for each profile, tab or window [6].

These environment variables are not meant to be set by the shell's
start-up scripts, but directly by Konsole, and hence needs to be
preserved across the host operating system and Toolbx container.

Note that KONSOLE_PROFILE_NAME was later removed from Konsole [7].
However, Neovim still uses it, so it's better to preserve it.

[1] Konsole commit debfec2eb3c8ede8
    https://invent.kde.org/utilities/konsole/-/commit/debfec2eb3c8ede8
    https://bugs.kde.org/show_bug.cgi?id=227296

[2] Konsole commit fcd815256c3729f2
    https://invent.kde.org/utilities/konsole/-/commit/fcd815256c3729f2

[3] Konsole commit 07cddfe302233c35
    https://invent.kde.org/utilities/konsole/-/commit/07cddfe302233c35
    https://bugs.kde.org/show_bug.cgi?id=276912
    https://bugs.kde.org/show_bug.cgi?id=281513
    https://bugs.kde.org/show_bug.cgi?id=292309

[4] Neovim commit 5fc4c2d442f01ab5
    neovim/neovim@5fc4c2d442f01ab5
    neovim/neovim#3129

[5] Neovim commit 3ccd59ee8216f3da
    neovim/neovim@3ccd59ee8216f3da
    neovim/neovim#6432
    neovim/neovim#6429
    neovim/neovim#6430

[6] https://userbase.kde.org/Konsole/en

[7] Konsole commit 9e3a30fdca2078e0
    https://invent.kde.org/utilities/konsole/-/commit/9e3a30fdca2078e0
    https://bugs.kde.org/show_bug.cgi?id=406955

containers#1449
containers#1696
containers#1698
@debarshiray debarshiray changed the title pkg/utils: Preserve environment variables set by a KDE session pkg/utils: Preserve environment variables set by a KDE session and Konsole Aug 7, 2025
debarshiray and others added 4 commits August 8, 2025 01:05
Detected by https://www.shellcheck.net/:
  Line 1255:
  if ! localtime_target=$(readlink /etc/localtime >/dev/null 2>&3) \
                        ^-- SC2327 (warning): This command substitution
                            will be empty because the command's output
                            gets redirected away.
                                                  ^-- SC2328 (error):
                                                      This redirection
                                                      takes output away
                                                      from the command
                                                      substitution.

See:
https://www.shellcheck.net/wiki/SC2327
https://www.shellcheck.net/wiki/SC2328

Fallout from 8db414d

containers#1701
Bash 5.3.0 changed the error messages shown by its exec built-in [1].

With Bash 5.2.37:
  $ exec /etc
  bash: /etc: Is a directory
  bash: exec: /etc: cannot execute: Is a directory

With Bash 5.3.0:
  $ exec /etc
  bash: /etc: Is a directory

The 'assert' function cannot directly handle compound commands.  So,
those need to be wrapped in 'bash -c "..."' [2].

[1] Bash commit b8c60bc9ca365f82
    See how exec_builtin() handles EX_NOEXEC and EISDIR from
    shell_execve() to avoid printing a duplicate error message.
    https://cgit.git.savannah.gnu.org/cgit/bash.git/commit/?id=b8c60bc9ca365f82

[2] https://github.com/bats-core/bats-assert

containers#1688
containers#1699
A KDE session sets some environment variables to influence the behaviour
of various programs and to access various settings [1].  eg., if the
KDE_SESSION_VERSION environment variable is absent then applications
won't respect KDE's theme or display scaling settings.

These environment variables are not meant to be set by the shell's
start-up scripts, but directly by KDE, and hence needs to be preserved
across the host operating system and Toolbx container.

[1] https://userbase.kde.org/KDE_System_Administration/Environment_Variables

containers#1696
containers#1698
Konsole injects the name of the current profile, and the identifiers
of the current tab and window into the process running inside it
through the KONSOLE_PROFILE_NAME, KONSOLE_DBUS_SESSION and
KONSOLE_DBUS_WINDOW environment variables respectively [1,2,3].  These
are used by programs like Neovim to detect the terminal features
supported by Konsole [4,5], or by users to save the shell's history
separately for each profile, tab or window [6].

These environment variables are not meant to be set by the shell's
start-up scripts, but directly by Konsole, and hence needs to be
preserved across the host operating system and Toolbx container.

Note that KONSOLE_PROFILE_NAME was later removed from Konsole [7].
However, Neovim still uses it, so it's better to preserve it.

[1] Konsole commit debfec2eb3c8ede8
    https://invent.kde.org/utilities/konsole/-/commit/debfec2eb3c8ede8
    https://bugs.kde.org/show_bug.cgi?id=227296

[2] Konsole commit fcd815256c3729f2
    https://invent.kde.org/utilities/konsole/-/commit/fcd815256c3729f2

[3] Konsole commit 07cddfe302233c35
    https://invent.kde.org/utilities/konsole/-/commit/07cddfe302233c35
    https://bugs.kde.org/show_bug.cgi?id=276912
    https://bugs.kde.org/show_bug.cgi?id=281513
    https://bugs.kde.org/show_bug.cgi?id=292309

[4] Neovim commit 5fc4c2d442f01ab5
    neovim/neovim@5fc4c2d442f01ab5
    neovim/neovim#3129

[5] Neovim commit 3ccd59ee8216f3da
    neovim/neovim@3ccd59ee8216f3da
    neovim/neovim#6432
    neovim/neovim#6429
    neovim/neovim#6430

[6] https://userbase.kde.org/Konsole/en

[7] Konsole commit 9e3a30fdca2078e0
    https://invent.kde.org/utilities/konsole/-/commit/9e3a30fdca2078e0
    https://bugs.kde.org/show_bug.cgi?id=406955

containers#1449
containers#1696
containers#1698
@debarshiray debarshiray force-pushed the wip/rishi/bkoropoff-kde-envvar branch from 157d7d6 to 1f12775 Compare August 7, 2025 23:09
Copy link

@debarshiray
Copy link
Member Author

recheck

Copy link

Copy link

@debarshiray debarshiray merged commit 39e0800 into containers:main Aug 8, 2025
3 checks passed
@debarshiray debarshiray deleted the wip/rishi/bkoropoff-kde-envvar branch August 8, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants