Skip to content

Commit

Permalink
Adapt to Qt6 QProcess::setChildProcessModifier()
Browse files Browse the repository at this point in the history
Qt5 QProcess::setupChildProcess() was removed.
Based on KDE KPty commit d429116888921814c01a57ba4ef0144a25fd33ec

It keeps sync with upstream code.
  • Loading branch information
luis-pereira committed May 2, 2024
1 parent 75c0066 commit 682864e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 50 deletions.
40 changes: 20 additions & 20 deletions lib/Pty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
3 changes: 0 additions & 3 deletions lib/Pty.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
41 changes: 18 additions & 23 deletions lib/kptyprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
KPtyProcess::KPtyProcess(QObject *parent) :
KPtyProcess(-1, parent)
{
setChildProcessModifier([this](){
onSetupChildProcess();
});
}

KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
Expand All @@ -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<KPtyDevice>(this);

if (ptyMasterFd == -1) {
Expand Down Expand Up @@ -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"
4 changes: 0 additions & 4 deletions lib/kptyprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ class KPtyProcess : public KProcess
KPtyDevice *pty() const;

protected:
/**
* Child process configuration
*/
virtual void onSetupChildProcess();

private:
std::unique_ptr<KPtyProcessPrivate> const d_ptr;
Expand Down

0 comments on commit 682864e

Please sign in to comment.