Commit 18dc0fde authored by Christoph Cullmann's avatar Christoph Cullmann 🐮 Committed by Kurt Hindenburg
Browse files

improve session closing behavior

the new session close behavior is again the old

- first send SIGHUP and wait one second if that works
- then hard kill

before we tried to send an EOF character
this needed workaround to not kill "non shell" programs
unexpected and doesn't work e.g. if

- you have some not finished command input in your shell
- on e.g. FreeBSD in general

When closing the session with some background process still running:
- using Ctrl+D (which sends EOF) will leave that background process running
  (which is the expected behaviour with e.g. BASH:
  https://lists.gnu.org/archive/html/bug-bash/2009-03/msg00091.html)
- using e.g. the close button on the titlebar will close the session and kill any background processes

You can also use 'somecommand & disown', if you want to ensure background processes
aren't killed when you close a konsole window.

BUG: 401898
CCBUG: 185140
(cherry picked from commit 3d967a59)
parent c988702f
......@@ -278,22 +278,6 @@ void Pty::closePty()
pty()->close();
}
void Pty::sendEof()
{
if (pty()->masterFd() < 0) {
qCDebug(KonsoleDebug) << "Unable to get eof char attribute, terminal not connected.";
return;
}
struct ::termios ttyAttributes;
pty()->tcGetAttr(&ttyAttributes);
char eofChar = ttyAttributes.c_cc[VEOF];
if (pty()->write(QByteArray(1, eofChar)) == -1) {
qCDebug(KonsoleDebug) << "Unable to send EOF";
}
pty()->waitForBytesWritten();
}
int Pty::foregroundProcessGroup() const
{
const int master_fd = pty()->masterFd();
......
......@@ -122,11 +122,6 @@ public:
*/
void closePty();
/**
* Sends EOF to the controlled process, this is the preferred method of telling e. g. bash to close
*/
void sendEof();
public Q_SLOTS:
/**
* Put the pty into UTF-8 mode on systems which support it.
......
......@@ -872,27 +872,16 @@ bool Session::closeInNormalWay()
return true;
}
static QSet<QString> knownShells({QStringLiteral("ash"), QStringLiteral("bash"), QStringLiteral("csh"), QStringLiteral("dash"), QStringLiteral("fish"), QStringLiteral("hush"), QStringLiteral("ksh"), QStringLiteral("mksh"), QStringLiteral("pdksh"), QStringLiteral("tcsh"), QStringLiteral("zsh")});
// If only the session's shell is running, try sending an EOF for a clean exit
if (!isForegroundProcessActive() && knownShells.contains(QFileInfo(_program).fileName())) {
_shellProcess->sendEof();
if (_shellProcess->waitForFinished(1000)) {
return true;
}
qWarning() << "shell did not close, sending SIGHUP";
}
// We tried asking nicely, ask a bit less nicely
// try SIGHUP, afterwards do hard kill
// this is the sequence used by most other terminal emulators like xterm, gnome-terminal, ...
// see bug 401898 for details about tries to have some "soft-terminate" via EOF character
if (kill(SIGHUP)) {
return true;
} else {
qWarning() << "Process " << processId() << " did not die with SIGHUP";
_shellProcess->closePty();
return (_shellProcess->waitForFinished(1000));
}
qWarning() << "Process " << processId() << " did not die with SIGHUP";
_shellProcess->closePty();
return (_shellProcess->waitForFinished(1000));
}
bool Session::closeInForceWay()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment