Bug 431044

Summary: Terminal panel interrupts sourcing .bashrc at dolphin startup
Product: [Applications] dolphin Reporter: Luigi Keith <b25e1938fe>
Component: panels: terminalAssignee: Dolphin Bug Assignee <dolphin-bugs-null>
Status: RESOLVED DUPLICATE    
Severity: minor CC: kfm-devel, nate
Priority: NOR    
Version: 20.12.0   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
Latest Commit: Version Fixed In:

Description Luigi Keith 2021-01-02 00:56:52 UTC
SUMMARY
Terminal panel doesn't source ~/.bashrc when dolphin is reopened.
Returns normal with CTRL+D / exit and opening again (f4).

STEPS TO REPRODUCE
1. Open dolphin with terminal panel (f4).
2. Close dolphin.
3. Open dolphin. Terminal panel is restored.

OBSERVED RESULT
When dolphin is reopened the terminal panel is missing aliases and settings from the ~/.bashrc.

EXPECTED RESULT
Terminal panel has same properties as if opened manually.

SOFTWARE/OS VERSIONS
Qt Version: 5.15.2

ADDITIONAL INFORMATION
Sourcing is interrupted at line #221 in terminalpanel.cpp. Restoring panel at dolphin start calls function twice with second call sending SIGINT to konsole instance.
https://invent.kde.org/system/dolphin/-/blob/master/src/panels/terminal/terminalpanel.cpp#L221

$BASH_ARGV has value "/home/user/.bashrc" instead of empty like when panel is working normally.
Comment 1 Nate Graham 2021-01-05 02:57:38 UTC

*** This bug has been marked as a duplicate of bug 279614 ***
Comment 2 Luigi Keith 2021-01-05 19:36:34 UTC
(In reply to Nate Graham from comment #1)
> 
> *** This bug has been marked as a duplicate of bug 279614 ***

Bug 279614 is specifically mentioned to occur during session restore which includes step to log out of the current session. This bug occurs even when not logged out of session but is probably caused by same code.
Comment 3 Luigi Keith 2021-11-19 22:52:46 UTC
You can fix this without making changes to souce code by simply making your .bashrc file as follows:

trap : SIGINT
## YOUR BASHRC CONTENT ##
trap - SIGINT

This redirects any interrup signals to null- command during the sourcing phase and clears after sourcing has been done.

Why:
- Dolphin opens with the tabs opened in the last session.
- Dolphin parses all the paths of the tabs and starts calling directory changes to the terminal.
- Dolphin has a failsafe feature when calling directory changes*[1]. It sends SIGINT to terminal process before changing directory.
- This results in terminal (bash) interrupting .bashrc / .bash_profile parsing.

[1] panels/terminal/terminalpanel.cpp: TerminalPanel::sendCdToTerminal
        // The TerminalV2 interface does not provide a way to delete the
        // current line before sending a new input. This is mandatory,
        // otherwise sending a 'cd x' to a existing 'rm -rf *' might
        // result in data loss. As workaround SIGINT is sent.
        const int processId = m_terminal->terminalProcessId();
        if (processId > 0) {
            kill(processId, SIGINT);
        }