2
This file is part of the KDE libraries
4
Copyright (C) 2007 Oswald Buddenhagen <ossi@kde.org>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
Boston, MA 02110-1301, USA.
22
#include "kptyprocess.h"
25
#include <kptydevice.h>
34
struct KPtyProcessPrivate {
35
KPtyProcessPrivate() :
36
ptyChannels(KPtyProcess::NoChannels),
41
void _k_onStateChanged(QProcess::ProcessState newState)
43
if (newState == QProcess::NotRunning && addUtmp) {
49
KPtyProcess::PtyChannels ptyChannels;
53
KPtyProcess::KPtyProcess(QObject *parent) :
54
KProcess(parent), d_ptr(new KPtyProcessPrivate)
58
d->pty = new KPtyDevice(this);
60
connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
61
SLOT(_k_onStateChanged(QProcess::ProcessState)));
64
KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
65
KProcess(parent), d_ptr(new KPtyProcessPrivate)
69
d->pty = new KPtyDevice(this);
70
d->pty->open(ptyMasterFd);
71
connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
72
SLOT(_k_onStateChanged(QProcess::ProcessState)));
75
KPtyProcess::~KPtyProcess()
79
if (state() != QProcess::NotRunning && d->addUtmp) {
81
disconnect(SIGNAL(stateChanged(QProcess::ProcessState)),
82
this, SLOT(_k_onStateChanged(QProcess::ProcessState)));
88
void KPtyProcess::setPtyChannels(PtyChannels channels)
92
d->ptyChannels = channels;
95
KPtyProcess::PtyChannels KPtyProcess::ptyChannels() const
97
Q_D(const KPtyProcess);
99
return d->ptyChannels;
102
void KPtyProcess::setUseUtmp(bool value)
109
bool KPtyProcess::isUseUtmp() const
111
Q_D(const KPtyProcess);
116
KPtyDevice *KPtyProcess::pty() const
118
Q_D(const KPtyProcess);
123
void KPtyProcess::setupChildProcess()
129
d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().constData(), qgetenv("DISPLAY").constData());
131
if (d->ptyChannels & StdinChannel) {
132
dup2(d->pty->slaveFd(), 0);
134
if (d->ptyChannels & StdoutChannel) {
135
dup2(d->pty->slaveFd(), 1);
137
if (d->ptyChannels & StderrChannel) {
138
dup2(d->pty->slaveFd(), 2);
141
KProcess::setupChildProcess();
144
#include "moc_kptyprocess.cpp"