Bug 413130 - New startplasma-* apps corrupt/truncate exported shell functions
Summary: New startplasma-* apps corrupt/truncate exported shell functions
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: general (show other bugs)
Version: 5.17.0
Platform: openSUSE Linux
: NOR critical
Target Milestone: 1.0
Assignee: Aleix Pol
URL: https://phabricator.kde.org/D24750
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-18 07:03 UTC by Wolfgang Bauer
Modified: 2019-10-18 13:07 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.17.1


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Bauer 2019-10-18 07:03:19 UTC
This has been reported downstream here:
https://bugzilla.opensuse.org/show_bug.cgi?id=1154345
https://lists.opensuse.org/opensuse-factory/2019-10/msg00137.html

If the environment contains exported shell functions, the new startplasma applications break them, resulting in error messages when opening a shell in the Plasma session (as a side-effect, that also breaks kdesu).

To reproduce, make sure ~/.config/plasma-locale-settings.sh exists (some script in ~/.config/plasma-workspace/env/ will probably do as well), and add something like this to ~/.bashrc, ~/.profile or similar:
--------------------
function sayhello {
echo 'Hello!'
}

export -f sayhello
--------------------
Then logout/login to Plasma. If you open Konsole, you'll get this error now:
bash: sayhello: line 1: syntax error: unexpected end of file
bash: error importing function definition for `sayhello'

Running "env" (or plasma-sourceenv.sh) inside a Plasma session gives this output:
...
BASH_FUNC_sayhello%%=() {  echo 'Hello!'
...

Correct would be:
...
BASH_FUNC_sayhello%%=() {  echo 'Hello!'
}
...
(this is what I get when running "env" in a non-Plasma session)
Comment 1 Fabian Vogt 2019-10-18 07:14:15 UTC
Might be possible to fix by running plasma-sourceenv.sh with an empty environment and avoiding to read /etc/profile. I'll give it a try.
Comment 2 Fabian Vogt 2019-10-18 07:15:01 UTC
Setting impact to critical as this breaks a ton of applications and scripts.
Comment 3 Fabian Vogt 2019-10-18 07:24:53 UTC
(In reply to Fabian Vogt from comment #1)
> Might be possible to fix by running plasma-sourceenv.sh with an empty
> environment and avoiding to read /etc/profile. I'll give it a try.

Actually, that might break some scripts which rely on (WAYLAND_)DISPLAY, XDG_RUNTIME_DIR or similar. It should be sufficient to print the variables in a better format, like delimited by \0.
Comment 4 Fabian Vogt 2019-10-18 12:39:40 UTC
Git commit 595ab88bc2ee0ed32da577ec8ae22efee90865b5 by Fabian Vogt.
Committed on 18/10/2019 at 12:38.
Pushed by fvogt into branch 'Plasma/5.17'.

Fix reading environment variables with newline

Summary:
Use '\0' as separator as '\n' is likely to appear in values.

Test Plan:
/etc/profile.d/mc.sh exported an mc() function,
which resulted in "syntax error: unexpected end of file" in the Plasma session.
Now the mc function is correctly set in the environment.

Reviewers: #plasma, apol, davidedmundson, adridg

Reviewed By: #plasma, apol, davidedmundson, adridg

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24750

M  +1    -1    startkde/plasma-sourceenv.sh
M  +1    -1    startkde/startplasma.cpp

https://commits.kde.org/plasma-workspace/595ab88bc2ee0ed32da577ec8ae22efee90865b5