Bug 470983

Summary: After update from plasma5 2.24.4 to 5.27.4, when not using Systemd boot, scripts executed in terminals cannot change directory
Product: [Plasma] plasmashell Reporter: davejplater@gmail.com <plater>
Component: Startup processAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED WORKSFORME    
Severity: normal CC: kde, nate, vkrevs
Priority: NOR    
Version First Reported In: 5.27.4   
Target Milestone: 1.0   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description davejplater@gmail.com 2023-06-13 15:41:07 UTC
See https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/569 for a similar problem
See https://bugzilla.suse.com/show_bug.cgi?id=1203617

STEPS TO REPRODUCE
1. Upgrade plasma5 to 5.27.4
2. Attempt to use mc (midnight commander) to navigate to a directory
3. 

OBSERVED RESULT
On exiting mc you go back to the directory that you started from

EXPECTED RESULT
On exiting mc you are in the directory that you navigated to

SOFTWARE/OS VERSIONS
Operating System: openSUSE Leap 15.5
KDE Plasma Version: 5.27.4
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 5.14.21-150500.53-default (64-bit)
Graphics Platform: X11
Processors: 4 × Intel® Core™ i5-4590 CPU @ 3.30GHz
Memory: 7,6 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 4600
Manufacturer: MSI
Product Name: MS-7851
System Version: 2.0

ADDITIONAL INFORMATION
Midnight Commander is a valuable command line tool but if it exits into it's starting directory it becomes just another file manager. This issue was a major blocker for me until a workaround was found.

This behavior doesn't happen in any other GUI than KDE, tested on icewm and xfce.
Comment 1 davejplater@gmail.com 2023-06-23 14:21:59 UTC
I've updated the title to reflect the true problem that scripts such as:
#! /usr/bin/bash

  dirc()
  {
  pushd ../../
  }
  
  dirc

don't work in kde anymore ie. the above script does nothing unless it is prepended with the bash builtin "." which forces the script to execute in the current shell. This wasn't the case in version 5.24.4 but is now the case in 5.27.4

If this behavior has been introduced as a security feature, I would appreciate knowing when and why.
Comment 2 davejplater@gmail.com 2023-06-23 14:24:22 UTC
Sorry, I would like to know the commit's hash.
Comment 3 Bug Janitor Service 2023-07-08 03:45:04 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 4 davejplater@gmail.com 2023-08-06 11:20:48 UTC
It appears that this bug appeared after plasma 5.26.
See also:
https://bugzilla.suse.com/show_bug.cgi?id=1213156
https://bugs.kde.org/show_bug.cgi?id=433299
Comment 5 Nate Graham 2023-12-08 20:19:07 UTC
I'm afraid KDE doesn't have any control over the console behavior in VTs, so this issue will have been caused by something somewhere else. I'm pretty sure what happened is that with the newer Plasma version, we switched to Systemd boot by default, and you're running into a change in behavior coming from Systemd. So you have two options:
- Disable the systemd boot with `kwriteconfig5 --file startkderc --group General --key systemdBoot false`
- Follow up with the Systemd folks about it
Comment 6 davejplater@gmail.com 2023-12-09 09:01:06 UTC
(In reply to Nate Graham from comment #5)
> I'm afraid KDE doesn't have any control over the console behavior in VTs, so
> this issue will have been caused by something somewhere else. I'm pretty
> sure what happened is that with the newer Plasma version, we switched to
> Systemd boot by default, and you're running into a change in behavior coming
> from Systemd. So you have two options:
> - Disable the systemd boot with `kwriteconfig5 --file startkderc --group
> General --key systemdBoot false`
> - Follow up with the Systemd folks about it

I use systemdBoot false` in startkderc
Comment 7 Nate Graham 2023-12-11 21:30:33 UTC
In that case I have no idea what it could be, but maybe there's a slim chance KWin is involved here and could have caused this issue.
Comment 8 Nate Graham 2023-12-11 21:31:13 UTC
Actually, let me ask for clarification on something. Are you using virtual terminals for this? Or are you just running `mc` in a regular terminal app like Konsole?
Comment 9 davejplater@gmail.com 2023-12-12 04:27:09 UTC
(In reply to Nate Graham from comment #8)
> Actually, let me ask for clarification on something. Are you using virtual
> terminals for this? Or are you just running `mc` in a regular terminal app
> like Konsole?

I experience this bug in any terminal app running under kde. I use konsole exclusively but it happens in xterm or any other terminal app. It doesn't happen in xfce or icewm or a virtual console, it only happens under kde and the change in behavior causes scripts executed in the terminal app to be restricted to a private shell and this causes the mc shell script to fail. Another consequence is:
 https://bugzilla.suse.com/show_bug.cgi?id=1213156
Comment 10 Nate Graham 2023-12-12 18:54:41 UTC
Probably something about the environment variables set during plasmashell's startup is triggering this. Can you try to figure out which environment variable is the cause?
Comment 11 davejplater@gmail.com 2023-12-13 12:58:28 UTC
(In reply to Nate Graham from comment #10)
> Probably something about the environment variables set during plasmashell's
> startup is triggering this. Can you try to figure out which environment
> variable is the cause?

I'm not really sure how systemd actually affects the shell to cause this, seems like a security measure to prevent malicious scripts from executing. I compared the output of "set" between the non systemd startup and the systemd startup and searched through kernel settings but I couldn't  find anything.
Comment 12 Bug Janitor Service 2023-12-28 03:46:16 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 13 davejplater@gmail.com 2023-12-28 07:48:39 UTC
Info for needinfo in comment 11
Comment 14 Nate Graham 2025-04-05 21:30:15 UTC
If this is still happening in Plasma 6.3, can you try in a new clean user account to rule out any of your customizations or user-specific environment variables being at play? If it works there, hopefully we can narrow down which specific thing causes it, and then we can dig into whether our handling of it is a bug or not. Thanks!
Comment 15 Bug Janitor Service 2025-04-20 03:47:10 UTC
🐛🧹 ⚠️ This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information, then set the bug status to REPORTED. If there is no change for at least 30 days, it will be automatically closed as RESOLVED WORKSFORME.

For more information about our bug triaging procedures, please read https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging.

Thank you for helping us make KDE software even better for everyone!
Comment 16 davejplater@gmail.com 2025-04-21 14:19:20 UTC
(In reply to Nate Graham from comment #14)
> If this is still happening in Plasma 6.3, can you try in a new clean user
> account to rule out any of your customizations or user-specific environment
> variables being at play? If it works there, hopefully we can narrow down
> which specific thing causes it, and then we can dig into whether our
> handling of it is a bug or not. Thanks!

Sorry for the delay, I've openSUSE Tumbleweed with plasma6 and Leap:15.6 with plasma5 sharing the same home partition. The workaround that still works on leap but no longer fixes Tumbleweed was to start mc.sh in the current shell with bash command ".".
The best test to explain the problem is a script in your home directory "echo -e "cd bin" > testmc && chmod 0755 testmc" if you execute 
./testmc you will remain where you are and if you execute ". testmc" you will change to ~/bin
This problem first surfaced in plasma5 and has so many workarounds that it gives me a headache but my mc exits into the directory that I'm in in mc when I exit because I've modified the wrapper script. 
Unfortunately I don't have time to find the cause in plasma6, in plasma5 I only had to disable systemd boot but it seems like systemd boot can no longer be disabled. mc works for me with the workaround
Comment 17 Bug Janitor Service 2025-05-06 03:47:08 UTC
🐛🧹 ⚠️ This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information, then set the bug status to REPORTED. If there is no change for at least 30 days, it will be automatically closed as RESOLVED WORKSFORME.

For more information about our bug triaging procedures, please read https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging.

Thank you for helping us make KDE software even better for everyone!