Bug 286367 - zsh crash in dolphin (konsole part) leads to all processes in X getting killed
Summary: zsh crash in dolphin (konsole part) leads to all processes in X getting killed
Status: VERIFIED FIXED
Alias: None
Product: konsole
Classification: Applications
Component: kpart (show other bugs)
Version: 2.7.3
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-11 20:53 UTC by aditsu
Modified: 2012-07-15 16:31 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
The drkonqi backtrace (4.25 KB, text/plain)
2012-01-21 10:43 UTC, Fabian
Details
The emerging window with the error message. (4.03 KB, image/png)
2012-01-21 10:44 UTC, Fabian
Details

Note You need to log in before you can comment on or make changes to this bug.
Description aditsu 2011-11-11 20:53:34 UTC
Version:           2.7.3 (using KDE 4.7.3) 
OS:                Linux

Sometimes when I open a new dolphin window and it comes up with a terminal too (probably remembered from the last window), it fails to run the shell (zsh) - I can see the message "Warning: program /bin/zsh crashed" in red text - and after a couple of seconds all the processes in X suddenly die and I'm left with a black screen + mouse cursor.
I first noticed this problem in kde 4.7.2, and reproduced it in 4.7.3. Couldn't find anything useful in the logs.

Reproducible: Sometimes

Steps to Reproduce:
Open dolphin, press F4 to open the terminal, then open a new dolphin window.

Actual Results:  
zsh crash and process genocide

Expected Results:  
dolphin window with working shell
Comment 1 Jekyll Wu 2011-11-11 22:06:18 UTC
Interesting and mysterious. I do not see how zsh might crash due to konsole kpart and how that crash can cause that serious damage.

So is that zsh a login zsh(run as zsh -l) or a non-login zsh?

And, if all customized configuration of zsh(for example, ~/.zprofile and ~/.zshrc) are removed, does the crash still happen?

And, does the crash also happen in standalone konsole ? Does it happen in other KDE apps which embed konsole kpart, such as kate and okteta?
Comment 2 aditsu 2011-11-12 12:21:08 UTC
Hi, if you think this is not about konsole, feel free to modify it. I didn't know where else to file it.

I'm not sure about the login vs non-login zsh, it's just my shell (set with chsh to /bin/zsh). Anyway, I pressed F4 in dolphin and then ran "ps -p $$ -o cmd", it printed "/bin/zsh".

I'm not very eager to test this actively, since it is quite disruptive, but I'll try to find some time for it.

The crash never happened in the standalone konsole. I've never seen konsole embedded in apps other than dolphin; I don't have kate, but I can install it or check in okteta.
Comment 3 Fabian 2012-01-20 19:08:33 UTC
I can reproduce this bug on Chakra Linux with KDE 4.7.4 quite reliably when opening a folder by clicking on a it in the folder view plasmoid. I also got some Kate crashes.zsh is my login shell.
Comment 4 Jekyll Wu 2012-01-21 03:54:25 UTC
(In reply to comment #3)
> I can reproduce this bug on Chakra Linux with KDE 4.7.4 quite reliably when
> opening a folder by clicking on a it in the folder view plasmoid. I also got
> some Kate crashes.zsh is my login shell.

Thanks for your information, although I can't reproduce the crash either.

Since you can reproduce the crash quite reliably when opening folder from the folder view plasmoid, could you post the backtrace(of dolphin) when it happens next time? That would help to see whether the crash happens in konsolepart or other components. 

And could you give one by one steps for the kate crash?
Comment 5 Fabian 2012-01-21 10:43:02 UTC
I have some problems getting the backtrace. I've attached the backtrace from drkonqi, but I think that it doesn't trace the the initial error. I might have some useful information, though: I have that autocd feature enabled (when you click on a folder, it does cd to its location). Furthermore, when I get the red error message, kde does not crash immediately. In fact, if I close the window or just the konsole kpart, everything keeps working. However, when I do any other action like opening a file, I get a crash. Sometimes it crashes instantly and I'm back at the kdm login screen, sometimes only plasma-desktop crashes and a window emerges, claiming "Could not start ksmserver. Check you installation." If I click on OK, I'll get the crash, else it doesn't crash and I can even restart kwin.

Unfortunately, I have not found a pattern which circumstances lead to a kate crash.
Comment 6 Fabian 2012-01-21 10:43:45 UTC
Created attachment 68063 [details]
The drkonqi backtrace
Comment 7 Fabian 2012-01-21 10:44:19 UTC
Created attachment 68064 [details]
The emerging window with the error message.
Comment 8 Jekyll Wu 2012-01-21 14:32:08 UTC
(In reply to comment #5 and comment #7)

Hi Fabian, thanks for your feedback. Now I can reproduce the problem and get the error message as shown in comment #7 from startkde: "Could not start ksmserver. Check your installation."

Here is the steps for reproducing:

1. open dolphin and show the terminal panel

2. find some way to crash the zsh running in the terminal panel, so that konsolepart display the warning messaged in red: "Warning: Program 'zsh' crashed."

3. click some folder in dolphin so that it sends "cd /path/to/some/folder" into the terminal panel where zsh has just crashed.

4. Both plasma-desktop and kwin are killed, only leaving the error message "Could not start ksmserver. Check your installation." from startkde in the screen.

The tricky step is how to make zsh crash. My method of crashing zsh is quite complex and seems highly dependent upon my various customized settings :(.

Although I'm still confused by its disastrous damage, there is clearly a problem in the code of konsolepart: it does not check whether the underlying program(zsh in this case) is still available before sending input into it.
Comment 9 Jekyll Wu 2012-01-24 16:50:30 UTC
Well, I get some clue for the disastrous damage. It is in the code of terminal panel of dolphin.

void TerminalPanel::sendCdToTerminal(const QString& dir)
{
    if (!m_clearTerminal) {
        // 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 send.
        kill(m_terminal->terminalProcessId(), SIGINT);
    }
    ...
}

When zsh crashes, 'm_terminal->terminalProcessId()' returns 0 since that is what QProcess::pid() returns in that situation. So that line becomes 'kill(0, SIGINT)' and it causes big problem.

@Peter:

I think this is firstly a problem of konsolepart. But I currently have no clear idea about what konsole and konsolepart should do and return in this case. Could you add some safeguard for pid being 0 ?
Comment 10 Peter Penz 2012-01-25 08:10:33 UTC
Thanks Jekyll for finding out what goes wrong here. Of course I'll add a check regarding the "PID is 0" and will push the patch during this week.
Comment 11 Peter Penz 2012-01-25 14:20:45 UTC
Git commit 7dfe3632f52d30f79f1c21c9acbaf68c05d63006 by Peter Penz.
Committed on 25/01/2012 at 15:18.
Pushed by ppenz into branch 'KDE/4.8'.

Terminal: only consider process IDs > 0

Thanks to Jekyll Wu for the analyses.

M  +4    -1    dolphin/src/panels/terminal/terminalpanel.cpp

http://commits.kde.org/kde-baseapps/7dfe3632f52d30f79f1c21c9acbaf68c05d63006
Comment 12 Peter Penz 2012-01-25 14:21:20 UTC
Git commit f68956e63c93c7d6eac20e1cc9557a59e14f9502 by Peter Penz.
Committed on 25/01/2012 at 15:18.
Pushed by ppenz into branch 'master'.

Terminal: only consider process IDs > 0

Thanks to Jekyll Wu for the analyses.

M  +4    -1    dolphin/src/panels/terminal/terminalpanel.cpp

http://commits.kde.org/kde-baseapps/f68956e63c93c7d6eac20e1cc9557a59e14f9502
Comment 13 aditsu 2012-07-15 16:31:04 UTC
Just got a zsh crash in dolphin (first one in a long time) and everything else keeps working normally.
kde 4.8.3