diff --git a/lib/Pty.cpp b/lib/Pty.cpp index 46c10280..a0f2604e 100644 --- a/lib/Pty.cpp +++ b/lib/Pty.cpp @@ -271,6 +271,26 @@ Pty::Pty(QObject* parent) } void Pty::init() { + // Must call parent class child process modifier, as it sets file descriptors ...etc + auto parentChildProcModifier = KPtyProcess::childProcessModifier(); + setChildProcessModifier([parentChildProcModifier = std::move(parentChildProcModifier)]() { + if (parentChildProcModifier) { + parentChildProcModifier(); + } + + // reset all signal handlers + // this ensures that terminal applications respond to + // signals generated via key sequences such as Ctrl+C + // (which sends SIGINT) + struct sigaction action; + sigemptyset(&action.sa_mask); + action.sa_handler = SIG_DFL; + action.sa_flags = 0; + for (int signal = 1; signal < NSIG; signal++) { + sigaction(signal, &action, nullptr); + } + }); + _windowColumns = 0; _windowLines = 0; _eraseChar = 0; @@ -326,23 +346,3 @@ int Pty::foregroundProcessGroup() const return 0; } -void Pty::onSetupChildProcess() -{ - KPtyProcess::onSetupChildProcess(); - - // reset all signal handlers - // this ensures that terminal applications respond to - // signals generated via key sequences such as Ctrl+C - // (which sends SIGINT) - struct sigaction action; - sigset_t sigset; - sigemptyset(&action.sa_mask); - sigemptyset(&sigset); - action.sa_handler = SIG_DFL; - action.sa_flags = 0; - for (int signal=1;signal < NSIG; signal++) { - sigaction(signal,&action,nullptr); - sigaddset(&sigset, signal); - } - sigprocmask(SIG_UNBLOCK, &sigset, nullptr); -} diff --git a/lib/Pty.h b/lib/Pty.h index 446c1374..5ff7d36a 100644 --- a/lib/Pty.h +++ b/lib/Pty.h @@ -188,9 +188,6 @@ Q_OBJECT */ void receivedData(const char* buffer, int length); - protected: - void onSetupChildProcess() override; - private slots: // called when data is received from the terminal process void dataReceived(); diff --git a/lib/kptyprocess.cpp b/lib/kptyprocess.cpp index 2ccd3bab..4bbb0d26 100644 --- a/lib/kptyprocess.cpp +++ b/lib/kptyprocess.cpp @@ -40,9 +40,6 @@ KPtyProcess::KPtyProcess(QObject *parent) : KPtyProcess(-1, parent) { - setChildProcessModifier([this](){ - onSetupChildProcess(); - }); } KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) : @@ -51,6 +48,24 @@ KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) : { Q_D(KPtyProcess); + setChildProcessModifier([d]() { + d->pty->setCTty(); +#if 0 + if (d->addUtmp) { + d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().constData(), qgetenv("DISPLAY").constData()); + } +#endif + if (d->ptyChannels & StdinChannel) { + dup2(d->pty->slaveFd(), 0); + } + if (d->ptyChannels & StdoutChannel) { + dup2(d->pty->slaveFd(), 1); + } + if (d->ptyChannels & StderrChannel) { + dup2(d->pty->slaveFd(), 2); + } + }); + d->pty = std::make_unique(this); if (ptyMasterFd == -1) { @@ -124,24 +139,4 @@ KPtyDevice *KPtyProcess::pty() const return d->pty.get(); } -void KPtyProcess::onSetupChildProcess() -{ - Q_D(KPtyProcess); - - d->pty->setCTty(); - -#if 0 - if (d->addUtmp) - d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().data(), qgetenv("DISPLAY")); -#endif - if (d->ptyChannels & StdinChannel) - dup2(d->pty->slaveFd(), 0); - - if (d->ptyChannels & StdoutChannel) - dup2(d->pty->slaveFd(), 1); - - if (d->ptyChannels & StderrChannel) - dup2(d->pty->slaveFd(), 2); -} - //#include "kptyprocess.moc" diff --git a/lib/kptyprocess.h b/lib/kptyprocess.h index ee1234d3..05061ccf 100644 --- a/lib/kptyprocess.h +++ b/lib/kptyprocess.h @@ -142,10 +142,6 @@ class KPtyProcess : public KProcess KPtyDevice *pty() const; protected: - /** - * Child process configuration - */ - virtual void onSetupChildProcess(); private: std::unique_ptr const d_ptr;