"Warning: chdir: Permission denied" in Konsole

Hi all,

In Konsole, if I select “Start in same directory as current session” in my profile, and run “sudo -s” entering the “/root”, then I will get the following error when opening new tabs:

Warning: Could not start program '/bin/zsh' with arguments ''.
Warning: chdir: Permission denied

Is this a bug or some incorrect configuration of my Konsole profile? I am not sure because it seems I cannot find existing bug reports about the same problem. My Konsole version is 23.04.2 and I am using openSUSE Tumbleweed.

I try to solve the issue myself by modifying Pty.cpp in the Konsole source as follows:

diff --git a/src/Pty.cpp b/src/Pty.cpp
index bb30c66ca..dc0361aa3 100644
--- a/src/Pty.cpp
+++ b/src/Pty.cpp
@@ -11,6 +11,7 @@
 // Qt
 #include <QStringList>
+#include <QFileInfo>
 #include <qplatformdefs.h>
 #ifndef Q_OS_WIN
@@ -221,7 +222,11 @@ void Pty::setInitialWorkingDirectory(const QString &dir)
     if (pwd.length() > 1 && pwd.endsWith(QLatin1Char('/'))) {
+    // check if we have the permission to enter dir
+    const QFileInfo pwd_info(pwd);
+    if (pwd_info.isDir() && !pwd_info.isExecutable()) {
+        pwd = QStringLiteral("");
+    }
     // setting PWD to "." will cause problem for bash & zsh

It does work for me but I don’t know if the solution is portable.

If you think it’s worth adding to Konsole you can create a Merge Request at Merge requests · Utilities / Konsole · GitLab and the developers can review the change.