Bug 369496 - KPart doesn't respect Scrollback File Location for "Unlimited Scrollback"
Summary: KPart doesn't respect Scrollback File Location for "Unlimited Scrollback"
Status: RESOLVED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: kpart (show other bugs)
Version: 16.08.1
Platform: Neon Linux
: NOR major
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-28 18:21 UTC by Vangelis
Modified: 2020-08-11 06:59 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vangelis 2016-09-28 18:21:52 UTC
I am not sure if this is a yakuake or a konsole-part bug, but I will describe it here since I only experience the issue in Yakuake (I guess the same will be happening in other applications that use the konsole-part).

In a dropped-down Yakuake window I do a "right click -> Scrollback -> Adjust Scrollback..." and I choose the "Unlimited scrollback" option, where it gives me the following notification:

----
When using this option, the scrollback data will be written unencrypted to temporary files. Those temporary files will be deleted automatically when Konsole is closed in a normal manner.
Use Settings->Configure Konsole->File Location to select the location of the temporary files.
----

Then I open the konsole and I choose "Settings -> Configure Konsole -> File Location -> Use user specific location". I kill and restart yakuake. Now yakuake should save the scrollback files in /home/user/.cache/konsole directory, but the global /tmp is still used instead.

I tried to debug the konsole (not yakuake) code since the konsole-part is involved here, and I found that the choice of path is happening in the History.cpp file issue and in the HistoryFile::HistoryFile() constructor.

I added the following qDebug lines in the code:

HistoryFile::HistoryFile()
    : _fd(-1),
      _length(0),
      _fileMap(0),
      _readWriteBalance(0)
{
    // Determine the temp directory once
    // This class is called 3 times for each "unlimited" scrollback.
    // This has the down-side that users must restart to
    // load changes (currently only 2 choices).

    if (!historyFileLocation.exists()) {
        KConfigGroup configGroup(KSharedConfig::openConfig(), "FileLocation");
        KSharedConfig::Ptr k = KSharedConfig::openConfig();
        qDebug() << "KConfig::mainConfigName() = " << k->name();
        qDebug() << "configGroup.readEntry(\"scrollbackUseCacheLocation\", false) = " << configGroup.readEntry("scrollbackUseCacheLocation", false);
        qDebug() << "configGroup.name() = " << configGroup.name();
        qDebug() << "configGroup.exists() = " << configGroup.exists();
        if (configGroup.readEntry("scrollbackUseCacheLocation", false)) {
            *historyFileLocation() = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
        } else {
            *historyFileLocation() = QDir::tempPath();
        }
        QDir().mkpath(*historyFileLocation());
    }
    const QString tmpDir = *historyFileLocation();
    const QString tmpFormat = tmpDir + QLatin1Char('/') + "konsole-XXXXXX.history";
    _tmpFile.setFileTemplate(tmpFormat);
    if (_tmpFile.open()) {
        _tmpFile.setAutoRemove(true);
        _fd = _tmpFile.handle();
    }
}

And what I realized is that yakuake doesn't respect the scrollback file location because the config file yakuakerc doesn't contain a config group "FileLocation".

This is a sample debug output for when I run "konsole":
~$ konsole
KConfig::mainConfigName() =  "konsolerc"
configGroup.readEntry("scrollbackUseCacheLocation", false) =  true
configGroup.name() =  "FileLocation"
configGroup.exists() =  true

And this is a sample debug output when I run "yakuake":
~$ yakuake
KConfig::mainConfigName() =  "yakuakerc"
configGroup.readEntry("scrollbackUseCacheLocation", false) =  false
configGroup.name() =  "FileLocation"
configGroup.exists() =  false

What is happening here is that in the line "KConfigGroup configGroup(KSharedConfig::openConfig(), "FileLocation");" the config file is loaded and we try to read the config group "FileLocation". Since there is no filename provided to the function KSharedConfig::openConfig(), the default KConfig::mainConfigName() is used as the configuration file. Eventually, when one uses "konsole" the default configuration file is "konsolerc", that contains the config group "FileLocation", and the scrollback file location works as expected, while when konsole-part is loaded from yakuake the default configuration file is "yakuakerc". Of course, yakuakerc doesn't contain the config group "FileLocation" and the scrollback files are saved to the default /tmp location.

When I added in ~/.config/yakuakerc the following lines (that are the lines added by konsole to the konsolerc when the user chooses the option "Use user specific location" for storing the scrollback files), the problem is solved.

[FileLocation]
scrollbackUseCacheLocation=true
scrollbackUseSystemLocation=false

Reproducible: Always




I would choose the bug severity as "Normal", but I chose "Major" because this bug may lead to privacy/security issues in shared environments.
Comment 1 Nick 2017-08-17 19:13:18 UTC
I can confirm this behavior with Yakuake. I have Konsole configured to store the scrollback file under ~/.cache/konsole but they are still ending up in /tmp. This is particularly annoying since my home directory is encrypted with eCryptfs so this is leaking potentially sensitive information on to an unencrypted part of the disk.
Comment 2 Nick 2017-08-17 19:15:12 UTC
Forgot to add 

Konsole 16.12.3
Yakuake 3.0.2

Kubuntu 17.04
Comment 3 Kurt Hindenburg 2017-08-27 00:39:48 UTC
Thanks for the ping, I had forgotten about this bko; I'll fix this for next release
Comment 4 Kurt Hindenburg 2017-08-27 02:07:06 UTC
Git commit a70ff34d28e061bec33513c21fa710f426721fd0 by Kurt Hindenburg.
Committed on 27/08/2017 at 01:51.
Pushed by hindenburg into branch 'master'.

For KParts, read Scrollback File Location from konsolerc

Apps using KonsolePart will now use Konsole's setting for the
scrollback file location.  There is also a check in the apprc for this
info.
Note that for the 2nd option "Use user specific location", the app
name will be used (e.g. /home/user/.cache/yakuake).

M  +11   -1    src/History.cpp

https://commits.kde.org/konsole/a70ff34d28e061bec33513c21fa710f426721fd0
Comment 5 Nick 2017-08-27 15:00:05 UTC
Awesome. Thank you!
Comment 6 Kurt Hindenburg 2017-08-29 13:23:26 UTC
Git commit 0f16d66cacf77df0e00ba66e0e409556d2786a16 by Kurt Hindenburg.
Committed on 29/08/2017 at 13:17.
Pushed by hindenburg into branch 'Applications/17.08'.

For KParts, read Scrollback File Location from konsolerc

Apps using KonsolePart will now use Konsole's setting for the
scrollback file location.  There is also a check in the apprc for this
info.
Note that for the 2nd option "Use user specific location", the app
name will be used (e.g. /home/user/.cache/yakuake).
(cherry picked from commit a70ff34d28e061bec33513c21fa710f426721fd0)

M  +11   -1    src/History.cpp

https://commits.kde.org/konsole/0f16d66cacf77df0e00ba66e0e409556d2786a16
Comment 7 rubo77 2020-08-11 06:59:00 UTC
This fix doesn't seem to be working in yakuake 19.12.2 (19.12.3-0ubuntu1)
which uses konsole version 4:19.12.3-0ubuntu1 on Ubuntu 20.04

I still an only scroll back 1024 lines

workaround: open `konsole` directly and set the scrollback amount there, this will also take effect on new sessions inside `yakuake`