fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / kpty / kptyprocess.cpp
blob52c1135cfbda984b3167595edaac22e044ccf6fb
1 /*
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.
23 #include "kptyprocess.h"
24 #include "kprocess_p.h"
26 #include <kuser.h>
27 #include <kptydevice.h>
29 #include <stdlib.h>
30 #include <unistd.h>
32 //////////////////
33 // private data //
34 //////////////////
36 struct KPtyProcessPrivate : KProcessPrivate {
37 KPtyProcessPrivate() :
38 ptyChannels(KPtyProcess::NoChannels),
39 addUtmp(false)
43 KPtyDevice *pty;
44 KPtyProcess::PtyChannels ptyChannels;
45 bool addUtmp : 1;
48 KPtyProcess::KPtyProcess(QObject *parent) :
49 KProcess(new KPtyProcessPrivate, parent)
51 Q_D(KPtyProcess);
53 d->pty = new KPtyDevice(this);
54 d->pty->open();
57 KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
58 KProcess(new KPtyProcessPrivate, parent)
60 Q_D(KPtyProcess);
62 d->pty = new KPtyDevice(this);
63 d->pty->open(ptyMasterFd);
66 KPtyProcess::~KPtyProcess()
68 Q_D(KPtyProcess);
70 delete d->pty;
73 void KPtyProcess::setPtyChannels(PtyChannels channels)
75 Q_D(KPtyProcess);
77 d->ptyChannels = channels;
80 KPtyProcess::PtyChannels KPtyProcess::ptyChannels() const
82 Q_D(const KPtyProcess);
84 return d->ptyChannels;
87 void KPtyProcess::setUseUtmp(bool value)
89 Q_D(KPtyProcess);
91 d->addUtmp = value;
94 bool KPtyProcess::isUseUtmp() const
96 Q_D(const KPtyProcess);
98 return d->addUtmp;
101 KPtyDevice *KPtyProcess::pty() const
103 Q_D(const KPtyProcess);
105 return d->pty;
108 void KPtyProcess::setupChildProcess()
110 Q_D(KPtyProcess);
112 d->pty->setCTty();
113 if (d->addUtmp)
114 d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().data(), qgetenv("DISPLAY"));
115 if (d->ptyChannels & StdinChannel)
116 dup2(d->pty->slaveFd(), 0);
117 if (d->ptyChannels & StdoutChannel)
118 dup2(d->pty->slaveFd(), 1);
119 if (d->ptyChannels & StderrChannel)
120 dup2(d->pty->slaveFd(), 2);
122 KProcess::setupChildProcess();
125 #include "kptyprocess.moc"