Bug 487147 - INVOCATION_ID and JOURNAL_STREAM environment variables should not be propagated from plasmashell
Summary: INVOCATION_ID and JOURNAL_STREAM environment variables should not be propagat...
Status: CONFIRMED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Startup process (show other bugs)
Version: 6.0.4
Platform: Arch Linux Linux
: VLO minor
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-17 14:12 UTC by ctxnop
Modified: 2024-08-08 08:06 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ctxnop 2024-05-17 14:12:54 UTC
SUMMARY

Plasmashell should not give its $INVOCATION_ID and $JOURNAL_STREAM environment variable to child processes. These are supposed to be set by systemd when starting an application so that this application can detect that it runs under systemd as a service and use sd-journal API to enhance logging for example.

STEPS TO REPRODUCE
1. Launch a plasma session using systemd
2. Starts a terminal emulator (konsole, kitty, ...)
3. run `echo $JOURNAL_STREAM`

OBSERVED RESULT
Both `$INVOCATION_ID` and `$JOURNAL_STREAM` are defined and have the same values as within `plasmashell`. This is confirmed by `sudo strings /proc/$(pidof plasmashell)/environ | grep JOURNAL`

EXPECTED RESULT
`$INVOCATION_ID` and `$JOURNAL_STREAM` should NOT be defined.
I checked the expected result with Ubuntu GDDM.

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: 6.8.9-arch1-2
KDE Plasma Version: 6.0.4
KDE Frameworks Version: 6.2.0
Qt Version: 6.7.0

ADDITIONAL INFORMATION
Tested on with a wayland session, will try with X11 in few hours.

Documentation about those variables:
https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#%24JOURNAL_STREAM
https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#%24INVOCATION_ID

Some comments on other unrelated bugs gives a full env dump, showing that those variables are also, wrongly, defined in their situations:
https://bugs.kde.org/show_bug.cgi?id=453202
https://bugs.kde.org/show_bug.cgi?id=468460
https://bugs.kde.org/show_bug.cgi?id=469839
Comment 1 ctxnop 2024-05-17 15:03:53 UTC
Just tried with an X11 session and I have the exact same issue.
Comment 2 David Edmundson 2024-08-06 21:23:50 UTC
In theory systemd application launching in combination with systemd services would not have this problem as the env would come from the application launch env.

So it's potentially made worse by in 21fce404e05d7180afb897fde4d1c81ea6a5ae96 in kio.
Comment 3 David Edmundson 2024-08-06 21:39:03 UTC
FWIW gnome-shell behaves the same.
Comment 4 David Redondo 2024-08-07 06:44:26 UTC
The systemd runner could/should simply remove these variables.
Comment 5 ctxnop 2024-08-08 08:06:41 UTC
I discussed it a bit on the systemd's mailing list, but did not received a clear answer: https://lists.freedesktop.org/archives/systemd-devel/2024-May/050277.html

I know that gnome-shell behave the same, but gnome-terminal remove these variables. To me it feels as the wrong place to do that, because it would mean that ALL terminal implementations have to do the exact same "workaround". And there is a lot of different terminal out there...

I did not go deep in KDE's code, so I cannot say for sure that it should be systemd side or not. From what I understood, the systemd's part is fine. If called correctly, the spawned process should receive a correct INVOCATION_ID and JOURNAL_STREAM. So that it would means that KDE's way of using systemd to spawn processes is faulty? I tried to patch plasma-shell to remove the two variables (as stated in the mailing list), and everything worked well and solved my initial issue.

In any case, if systemd runner or KDE's part is fixed so that systemd correctly provide the two variables to the spawned process, it would means that spawning a terminal (e.g. konsole) will provide a new INVOCATION_ID and JOURNAL_STREAM to that terminal, and the terminal's childs (shell and any application run from within that terminal) will inherit from it. Leading to applications having JOURNAL_STREAM defined and, consequently, writing to the sd-journal of the terminal, instead of the stdout.

Does that means that an issue should be opened to all terminals? As stated above, gnome-shell is already exclude few variables, maybe all terminals should do the same? Actually, I was wondering if it should rather be an inclusion list instead? I mean, naively, when starting a terminal, I expect it to be a new fresh and clean environment, and I expect the launched shell to set any initial variables values, just like if it was a TTY.