Bug 458591 - OSC 7 stopped working to preserve path when creating a new tab
Summary: OSC 7 stopped working to preserve path when creating a new tab
Status: RESOLVED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: emulation (show other bugs)
Version: 22.08.0
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2022-09-01 06:05 UTC by Gabriel Marcano
Modified: 2022-10-22 18:22 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 22.08.3


Attachments
List of packages updated today (15.28 KB, text/plain)
2022-09-01 06:05 UTC, Gabriel Marcano
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Marcano 2022-09-01 06:05:56 UTC
Created attachment 151752 [details]
List of packages updated today

SUMMARY

This may not be a Konsole problem, but I have not been able to track down where
the problem originates (it's either in Qt or in KDE dependencies of Konsole or
Konsole itself).

I have the following on my .bashrc:
    _osc7 () {
            printf "\033]7;file://%s%s\033\\" "$HOSTNAME" $(pwd)
    }

    PROMPT_COMMAND=_osc7

With this, I was able to create new tabs when in symlinked folders, and the new
tab would preserve the path taken to get there in the path shown on bash. As an
example, /tmp/foo is an folder, /tmp/bar is a symlink to /tmp/foo:

  /tmp/foo
  /tmp/bar -> /tmp/foo

If I cd'd to /tmp/bar and then launched a new tab (Ctrl-Shift-T), the current
working directory on the new tab would show as /tmp/bar instead of /tmp/foo.

This stopped working with the latest update. Now, if I `cd /tmp/bar` and launch
a new tab, the new tab shows the current working directory as /tmp/foo.


STEPS TO REPRODUCE
1. mkdir /tmp/foo
2. ln -s /tmp/foo /tmp/bar
3. cd /tmp/bar
4. printf "\033]7;file://%s%s\033\\" "$HOSTNAME" $(pwd)
5. launch a new tab in Konsole
6. in the new tab, run pwd

OBSERVED RESULT
$ pwd
/tmp/foo

EXPECTED RESULT
$ pwd
/tmp/bar

SOFTWARE/OS VERSIONS
Linux: Gentoo Linux
(available in About System)
KDE Plasma Version: 5.25.4
KDE Frameworks Version: 5.97.0
Qt Version: 5.15.5

ADDITIONAL INFORMATION
I spent a couple of hours tracing through Konsole, qtcore, and a couple of KDE
framework projects, trying to figure out the culprit. I've ruled out the shell
as a problem, as the issue appears whether I use /bin/bash or /bin/sh as the
shell for the session.

I tried rolling back to an older Konsole release from 2021, and the problem
persists... which hints that the problem might be deeper than Konsole. I don't
have the knowledge necessary to identify the actual source of the problem,
though, so I'm choosing Konsole as the source until something more specific
can be found.

As far as I can tell through debugging, the QProcessPrivate::execChild call
deep in qtcore done by the forked process that spawns the new tab does receive
the right directory to change into. As Konsole spawns a bunch of other
processes around this time, and they all time out if I take too long stepping
through things, I was not able to debug any deeper to see what, if anything,
changed the working directory.

From what I can tell, though, there doesn't appear to be anything in Konsole to
pass the OSC 7 from one tab to the new one. Not sure if that information has a
different way to make it from one tab to another.

Let me know if you need anything specific, or if there are specific things I
can try to help debug this issue. I can build and debug Konsole, as well as any
of its dependencies. I can reproduce this on both of my Gentoo systems
currently (a desktop and a laptop), and I did confirm this morning that before
the updates, OSC 7 was working fine on my desktop.

I'm attaching the full list of KDE and QT applications/libraries that I updated
today on my desktop, in case it helps. There are a lot of applications there,
though.
Comment 1 Kurt Hindenburg 2022-09-26 22:05:55 UTC
used to work in 22.04 - doesn't in 22.08
Comment 2 Kurt Hindenburg 2022-09-26 22:32:00 UTC
bisect says it is this https://invent.kde.org/utilities/konsole/-/commit/5b5fdb0e32793f5888e3fb915501b07fa80f739a
Comment 3 Bug Janitor Service 2022-10-21 15:18:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/konsole/-/merge_requests/758
Comment 4 Gabriel Marcano 2022-10-21 17:42:47 UTC
I can confirm that the changes at https://invent.kde.org/utilities/konsole/-/merge_requests/758 do fix the problem for me.

To make sure the problem is still on the current release, I tried reproducing the problem without the patch, and I can confirm it is still happening. Applying the patch from the PR makes is such that I cannot reproduce the bug. So, at least from what I can see, it looks like once the PR is merged, this bug report can be closed. Thanks!
Comment 5 Harald Sitter 2022-10-22 18:16:12 UTC
Git commit 252eab8537d8274ed32cb0a008f5d6ce9109908f by Harald Sitter.
Committed on 21/10/2022 at 15:17.
Pushed by hindenburg into branch 'release/22.08'.

don't lose environment variables

the resetting was nonesense, Pty appends _environment on top of the
existing environment, so concat the two for potential sandboxing (the
ksandbox class will only apply the diff to system environment anyway).
once the sandboxing was applied reset the actual process environment to
the original variable rather than emptying it, this prevents us from
losing variables when outside a sandbox

M  +3    -3    src/session/Session.cpp

https://invent.kde.org/utilities/konsole/commit/252eab8537d8274ed32cb0a008f5d6ce9109908f