mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kpty: format and indent
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
3aaef7077e
commit
575b10a273
4 changed files with 91 additions and 103 deletions
|
@ -125,12 +125,10 @@ KPty::~KPty()
|
||||||
|
|
||||||
bool KPty::open()
|
bool KPty::open()
|
||||||
{
|
{
|
||||||
Q_D(KPty);
|
Q_D(KPty);
|
||||||
|
|
||||||
if (d->masterFd >= 0) {
|
if (d->masterFd >= 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->ownMaster = true;
|
d->ownMaster = true;
|
||||||
|
|
||||||
// Find a master pty that we can open ////////////////////////////////
|
// Find a master pty that we can open ////////////////////////////////
|
||||||
|
@ -222,30 +220,27 @@ bool KPty::open(int fd)
|
||||||
kWarning(175) << "Attempting to open an already open pty";
|
kWarning(175) << "Attempting to open an already open pty";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->ownMaster = false;
|
d->ownMaster = false;
|
||||||
|
|
||||||
# ifdef HAVE_PTSNAME_R
|
#ifdef HAVE_PTSNAME_R
|
||||||
char ptsn[32];
|
char ptsn[32];
|
||||||
::memset(ptsn, '\0', sizeof(ptsn) * sizeof(char));
|
::memset(ptsn, '\0', sizeof(ptsn) * sizeof(char));
|
||||||
if (ptsname_r(fd, ptsn, sizeof(ptsn)) == 0) {
|
if (ptsname_r(fd, ptsn, sizeof(ptsn)) == 0) {
|
||||||
d->ttyName = ptsn;
|
d->ttyName = ptsn;
|
||||||
# else
|
#else
|
||||||
char *ptsn = ptsname(fd);
|
char *ptsn = ptsname(fd);
|
||||||
if (ptsn) {
|
if (ptsn) {
|
||||||
d->ttyName = ptsn;
|
d->ttyName = ptsn;
|
||||||
# endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
kWarning(175) << "Failed to determine pty slave device for fd" << fd;
|
kWarning(175) << "Failed to determine pty slave device for fd" << fd;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->masterFd = fd;
|
d->masterFd = fd;
|
||||||
if (!openSlave()) {
|
if (!openSlave()) {
|
||||||
d->masterFd = -1;
|
d->masterFd = -1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,6 @@ public:
|
||||||
char *reserve(int bytes)
|
char *reserve(int bytes)
|
||||||
{
|
{
|
||||||
totalSize += bytes;
|
totalSize += bytes;
|
||||||
|
|
||||||
char *ptr;
|
char *ptr;
|
||||||
if (tail + bytes <= buffers.last().size()) {
|
if (tail + bytes <= buffers.last().size()) {
|
||||||
ptr = buffers.last().data() + tail;
|
ptr = buffers.last().data() + tail;
|
||||||
|
@ -169,17 +168,19 @@ public:
|
||||||
int start = head;
|
int start = head;
|
||||||
QList<QByteArray>::ConstIterator it = buffers.begin();
|
QList<QByteArray>::ConstIterator it = buffers.begin();
|
||||||
forever {
|
forever {
|
||||||
if (!maxLength)
|
if (!maxLength) {
|
||||||
return index;
|
return index;
|
||||||
if (index == size())
|
}
|
||||||
|
if (index == size()) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
const QByteArray &buf = *it;
|
const QByteArray &buf = *it;
|
||||||
++it;
|
++it;
|
||||||
int len = qMin((it == buffers.end() ? tail : buf.size()) - start,
|
int len = qMin((it == buffers.end() ? tail : buf.size()) - start, maxLength);
|
||||||
maxLength);
|
|
||||||
const char *ptr = buf.data() + start;
|
const char *ptr = buf.data() + start;
|
||||||
if (const char *rptr = (const char *)memchr(ptr, c, len))
|
if (const char *rptr = (const char *)memchr(ptr, c, len)) {
|
||||||
return index + (rptr - ptr) + 1;
|
return index + (rptr - ptr) + 1;
|
||||||
|
}
|
||||||
index += len;
|
index += len;
|
||||||
maxLength -= len;
|
maxLength -= len;
|
||||||
start = 0;
|
start = 0;
|
||||||
|
@ -240,7 +241,8 @@ static void qt_ignore_sigpipe()
|
||||||
|
|
||||||
#define NO_INTR(ret,func) do { ret = func; } while (ret < 0 && errno == EINTR)
|
#define NO_INTR(ret,func) do { ret = func; } while (ret < 0 && errno == EINTR)
|
||||||
|
|
||||||
class KPtyDevicePrivate : public KPtyPrivate {
|
class KPtyDevicePrivate : public KPtyPrivate
|
||||||
|
{
|
||||||
Q_DECLARE_PUBLIC(KPtyDevice)
|
Q_DECLARE_PUBLIC(KPtyDevice)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -307,7 +309,7 @@ bool KPtyDevicePrivate::_k_canRead()
|
||||||
#endif
|
#endif
|
||||||
// Useless block braces except in Solaris
|
// Useless block braces except in Solaris
|
||||||
{
|
{
|
||||||
NO_INTR(readBytes, read(q->masterFd(), ptr, available));
|
NO_INTR(readBytes, read(q->masterFd(), ptr, available));
|
||||||
}
|
}
|
||||||
if (readBytes < 0) {
|
if (readBytes < 0) {
|
||||||
readBuffer.unreserve(available);
|
readBuffer.unreserve(available);
|
||||||
|
@ -321,43 +323,38 @@ bool KPtyDevicePrivate::_k_canRead()
|
||||||
readNotifier->setEnabled(false);
|
readNotifier->setEnabled(false);
|
||||||
emit q->readEof();
|
emit q->readEof();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
if (!emittedReadyRead) {
|
|
||||||
emittedReadyRead = true;
|
|
||||||
emit q->readyRead();
|
|
||||||
emittedReadyRead = false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (!emittedReadyRead) {
|
||||||
|
emittedReadyRead = true;
|
||||||
|
emit q->readyRead();
|
||||||
|
emittedReadyRead = false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KPtyDevicePrivate::_k_canWrite()
|
bool KPtyDevicePrivate::_k_canWrite()
|
||||||
{
|
{
|
||||||
Q_Q(KPtyDevice);
|
Q_Q(KPtyDevice);
|
||||||
|
|
||||||
writeNotifier->setEnabled(false);
|
writeNotifier->setEnabled(false);
|
||||||
if (writeBuffer.isEmpty())
|
if (writeBuffer.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
qt_ignore_sigpipe();
|
qt_ignore_sigpipe();
|
||||||
int wroteBytes;
|
int wroteBytes;
|
||||||
NO_INTR(wroteBytes,
|
NO_INTR(wroteBytes, write(q->masterFd(), writeBuffer.readPointer(), writeBuffer.readSize()));
|
||||||
write(q->masterFd(),
|
|
||||||
writeBuffer.readPointer(), writeBuffer.readSize()));
|
|
||||||
if (wroteBytes < 0) {
|
if (wroteBytes < 0) {
|
||||||
q->setErrorString(i18n("Error writing to PTY"));
|
q->setErrorString(i18n("Error writing to PTY"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
writeBuffer.free(wroteBytes);
|
writeBuffer.free(wroteBytes);
|
||||||
|
|
||||||
if (!emittedBytesWritten) {
|
if (!emittedBytesWritten) {
|
||||||
emittedBytesWritten = true;
|
emittedBytesWritten = true;
|
||||||
emit q->bytesWritten(wroteBytes);
|
emit q->bytesWritten(wroteBytes);
|
||||||
emittedBytesWritten = false;
|
emittedBytesWritten = false;
|
||||||
}
|
}
|
||||||
|
if (!writeBuffer.isEmpty()) {
|
||||||
if (!writeBuffer.isEmpty())
|
|
||||||
writeNotifier->setEnabled(true);
|
writeNotifier->setEnabled(true);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,10 +407,12 @@ bool KPtyDevicePrivate::doWait(int msecs, bool reading)
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
|
|
||||||
if (readNotifier->isEnabled())
|
if (readNotifier->isEnabled()) {
|
||||||
FD_SET(q->masterFd(), &rfds);
|
FD_SET(q->masterFd(), &rfds);
|
||||||
if (!writeBuffer.isEmpty())
|
}
|
||||||
|
if (!writeBuffer.isEmpty()) {
|
||||||
FD_SET(q->masterFd(), &wfds);
|
FD_SET(q->masterFd(), &wfds);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef Q_OS_LINUX
|
#ifndef Q_OS_LINUX
|
||||||
if (tvp) {
|
if (tvp) {
|
||||||
|
@ -425,25 +424,30 @@ bool KPtyDevicePrivate::doWait(int msecs, bool reading)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (select(q->masterFd() + 1, &rfds, &wfds, 0, tvp)) {
|
switch (select(q->masterFd() + 1, &rfds, &wfds, 0, tvp)) {
|
||||||
case -1:
|
case -1: {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
|
break;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case 0: {
|
||||||
|
q->setErrorString(i18n("PTY operation timed out"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
if (FD_ISSET(q->masterFd(), &rfds)) {
|
||||||
|
bool canRead = _k_canRead();
|
||||||
|
if (reading && canRead) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (FD_ISSET(q->masterFd(), &wfds)) {
|
||||||
|
bool canWrite = _k_canWrite();
|
||||||
|
if (!reading) {
|
||||||
|
return canWrite;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
return false;
|
|
||||||
case 0:
|
|
||||||
q->setErrorString(i18n("PTY operation timed out"));
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
if (FD_ISSET(q->masterFd(), &rfds)) {
|
|
||||||
bool canRead = _k_canRead();
|
|
||||||
if (reading && canRead)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
if (FD_ISSET(q->masterFd(), &wfds)) {
|
|
||||||
bool canWrite = _k_canWrite();
|
|
||||||
if (!reading)
|
|
||||||
return canWrite;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -452,7 +456,6 @@ bool KPtyDevicePrivate::doWait(int msecs, bool reading)
|
||||||
void KPtyDevicePrivate::finishOpen(QIODevice::OpenMode mode)
|
void KPtyDevicePrivate::finishOpen(QIODevice::OpenMode mode)
|
||||||
{
|
{
|
||||||
Q_Q(KPtyDevice);
|
Q_Q(KPtyDevice);
|
||||||
|
|
||||||
q->QIODevice::open(mode);
|
q->QIODevice::open(mode);
|
||||||
fcntl(q->masterFd(), F_SETFL, O_NONBLOCK);
|
fcntl(q->masterFd(), F_SETFL, O_NONBLOCK);
|
||||||
readBuffer.clear();
|
readBuffer.clear();
|
||||||
|
@ -467,8 +470,8 @@ void KPtyDevicePrivate::finishOpen(QIODevice::OpenMode mode)
|
||||||
// public member functions //
|
// public member functions //
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
KPtyDevice::KPtyDevice(QObject *parent) :
|
KPtyDevice::KPtyDevice(QObject *parent)
|
||||||
QIODevice(parent),
|
: QIODevice(parent),
|
||||||
KPty(new KPtyDevicePrivate(this))
|
KPty(new KPtyDevicePrivate(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -481,46 +484,37 @@ KPtyDevice::~KPtyDevice()
|
||||||
bool KPtyDevice::open(OpenMode mode)
|
bool KPtyDevice::open(OpenMode mode)
|
||||||
{
|
{
|
||||||
Q_D(KPtyDevice);
|
Q_D(KPtyDevice);
|
||||||
|
if (masterFd() >= 0) {
|
||||||
if (masterFd() >= 0)
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
if (!KPty::open()) {
|
if (!KPty::open()) {
|
||||||
setErrorString(i18n("Error opening PTY"));
|
setErrorString(i18n("Error opening PTY"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->finishOpen(mode);
|
d->finishOpen(mode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KPtyDevice::open(int fd, OpenMode mode)
|
bool KPtyDevice::open(int fd, OpenMode mode)
|
||||||
{
|
{
|
||||||
Q_D(KPtyDevice);
|
Q_D(KPtyDevice);
|
||||||
|
|
||||||
if (!KPty::open(fd)) {
|
if (!KPty::open(fd)) {
|
||||||
setErrorString(i18n("Error opening PTY"));
|
setErrorString(i18n("Error opening PTY"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->finishOpen(mode);
|
d->finishOpen(mode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPtyDevice::close()
|
void KPtyDevice::close()
|
||||||
{
|
{
|
||||||
Q_D(KPtyDevice);
|
Q_D(KPtyDevice);
|
||||||
|
if (masterFd() < 0) {
|
||||||
if (masterFd() < 0)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
delete d->readNotifier;
|
delete d->readNotifier;
|
||||||
delete d->writeNotifier;
|
delete d->writeNotifier;
|
||||||
|
|
||||||
QIODevice::close();
|
QIODevice::close();
|
||||||
|
|
||||||
KPty::close();
|
KPty::close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,19 +526,19 @@ bool KPtyDevice::isSequential() const
|
||||||
bool KPtyDevice::canReadLine() const
|
bool KPtyDevice::canReadLine() const
|
||||||
{
|
{
|
||||||
Q_D(const KPtyDevice);
|
Q_D(const KPtyDevice);
|
||||||
return QIODevice::canReadLine() || d->readBuffer.canReadLine();
|
return (QIODevice::canReadLine() || d->readBuffer.canReadLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KPtyDevice::atEnd() const
|
bool KPtyDevice::atEnd() const
|
||||||
{
|
{
|
||||||
Q_D(const KPtyDevice);
|
Q_D(const KPtyDevice);
|
||||||
return QIODevice::atEnd() && d->readBuffer.isEmpty();
|
return (QIODevice::atEnd() && d->readBuffer.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 KPtyDevice::bytesAvailable() const
|
qint64 KPtyDevice::bytesAvailable() const
|
||||||
{
|
{
|
||||||
Q_D(const KPtyDevice);
|
Q_D(const KPtyDevice);
|
||||||
return QIODevice::bytesAvailable() + d->readBuffer.size();
|
return (QIODevice::bytesAvailable() + d->readBuffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 KPtyDevice::bytesToWrite() const
|
qint64 KPtyDevice::bytesToWrite() const
|
||||||
|
@ -596,7 +590,6 @@ qint64 KPtyDevice::writeData(const char *data, qint64 len)
|
||||||
{
|
{
|
||||||
Q_D(KPtyDevice);
|
Q_D(KPtyDevice);
|
||||||
Q_ASSERT(len <= KMAXINT);
|
Q_ASSERT(len <= KMAXINT);
|
||||||
|
|
||||||
d->writeBuffer.write(data, len);
|
d->writeBuffer.write(data, len);
|
||||||
d->writeNotifier->setEnabled(true);
|
d->writeNotifier->setEnabled(true);
|
||||||
return len;
|
return len;
|
||||||
|
|
|
@ -33,54 +33,59 @@
|
||||||
// private data //
|
// private data //
|
||||||
//////////////////
|
//////////////////
|
||||||
|
|
||||||
class KPtyProcessPrivate : public KProcessPrivate {
|
class KPtyProcessPrivate : public KProcessPrivate
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
KPtyProcessPrivate() :
|
KPtyProcessPrivate()
|
||||||
ptyChannels(KPtyProcess::NoChannels),
|
: ptyChannels(KPtyProcess::NoChannels),
|
||||||
addUtmp(false)
|
addUtmp(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void _k_onStateChanged(QProcess::ProcessState newState)
|
void _k_onStateChanged(QProcess::ProcessState newState)
|
||||||
{
|
{
|
||||||
if (newState == QProcess::NotRunning && addUtmp)
|
if (newState == QProcess::NotRunning && addUtmp) {
|
||||||
pty->logout();
|
pty->logout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KPtyDevice *pty;
|
KPtyDevice *pty;
|
||||||
KPtyProcess::PtyChannels ptyChannels;
|
KPtyProcess::PtyChannels ptyChannels;
|
||||||
bool addUtmp : 1;
|
bool addUtmp;
|
||||||
};
|
};
|
||||||
|
|
||||||
KPtyProcess::KPtyProcess(QObject *parent) :
|
KPtyProcess::KPtyProcess(QObject *parent) :
|
||||||
KProcess(new KPtyProcessPrivate, parent)
|
KProcess(new KPtyProcessPrivate, parent)
|
||||||
{
|
{
|
||||||
Q_D(KPtyProcess);
|
Q_D(KPtyProcess);
|
||||||
|
|
||||||
d->pty = new KPtyDevice(this);
|
d->pty = new KPtyDevice(this);
|
||||||
d->pty->open();
|
d->pty->open();
|
||||||
connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
|
connect(
|
||||||
SLOT(_k_onStateChanged(QProcess::ProcessState)));
|
this, SIGNAL(stateChanged(QProcess::ProcessState)),
|
||||||
|
SLOT(_k_onStateChanged(QProcess::ProcessState))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
|
KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
|
||||||
KProcess(new KPtyProcessPrivate, parent)
|
KProcess(new KPtyProcessPrivate, parent)
|
||||||
{
|
{
|
||||||
Q_D(KPtyProcess);
|
Q_D(KPtyProcess);
|
||||||
|
|
||||||
d->pty = new KPtyDevice(this);
|
d->pty = new KPtyDevice(this);
|
||||||
d->pty->open(ptyMasterFd);
|
d->pty->open(ptyMasterFd);
|
||||||
connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
|
connect(
|
||||||
SLOT(_k_onStateChanged(QProcess::ProcessState)));
|
this, SIGNAL(stateChanged(QProcess::ProcessState)),
|
||||||
|
SLOT(_k_onStateChanged(QProcess::ProcessState))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
KPtyProcess::~KPtyProcess()
|
KPtyProcess::~KPtyProcess()
|
||||||
{
|
{
|
||||||
Q_D(KPtyProcess);
|
Q_D(KPtyProcess);
|
||||||
|
|
||||||
if (state() != QProcess::NotRunning && d->addUtmp) {
|
if (state() != QProcess::NotRunning && d->addUtmp) {
|
||||||
disconnect(SIGNAL(stateChanged(QProcess::ProcessState)),
|
disconnect(
|
||||||
this, SLOT(_k_onStateChanged(QProcess::ProcessState)));
|
SIGNAL(stateChanged(QProcess::ProcessState)),
|
||||||
|
this, SLOT(_k_onStateChanged(QProcess::ProcessState))
|
||||||
|
);
|
||||||
d->pty->logout();
|
d->pty->logout();
|
||||||
}
|
}
|
||||||
delete d->pty;
|
delete d->pty;
|
||||||
|
@ -89,52 +94,48 @@ KPtyProcess::~KPtyProcess()
|
||||||
void KPtyProcess::setPtyChannels(PtyChannels channels)
|
void KPtyProcess::setPtyChannels(PtyChannels channels)
|
||||||
{
|
{
|
||||||
Q_D(KPtyProcess);
|
Q_D(KPtyProcess);
|
||||||
|
|
||||||
d->ptyChannels = channels;
|
d->ptyChannels = channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
KPtyProcess::PtyChannels KPtyProcess::ptyChannels() const
|
KPtyProcess::PtyChannels KPtyProcess::ptyChannels() const
|
||||||
{
|
{
|
||||||
Q_D(const KPtyProcess);
|
Q_D(const KPtyProcess);
|
||||||
|
|
||||||
return d->ptyChannels;
|
return d->ptyChannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPtyProcess::setUseUtmp(bool value)
|
void KPtyProcess::setUseUtmp(bool value)
|
||||||
{
|
{
|
||||||
Q_D(KPtyProcess);
|
Q_D(KPtyProcess);
|
||||||
|
|
||||||
d->addUtmp = value;
|
d->addUtmp = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KPtyProcess::isUseUtmp() const
|
bool KPtyProcess::isUseUtmp() const
|
||||||
{
|
{
|
||||||
Q_D(const KPtyProcess);
|
Q_D(const KPtyProcess);
|
||||||
|
|
||||||
return d->addUtmp;
|
return d->addUtmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
KPtyDevice *KPtyProcess::pty() const
|
KPtyDevice *KPtyProcess::pty() const
|
||||||
{
|
{
|
||||||
Q_D(const KPtyProcess);
|
Q_D(const KPtyProcess);
|
||||||
|
|
||||||
return d->pty;
|
return d->pty;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KPtyProcess::setupChildProcess()
|
void KPtyProcess::setupChildProcess()
|
||||||
{
|
{
|
||||||
Q_D(KPtyProcess);
|
Q_D(KPtyProcess);
|
||||||
|
|
||||||
d->pty->setCTty();
|
d->pty->setCTty();
|
||||||
if (d->addUtmp)
|
if (d->addUtmp)
|
||||||
d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().data(), qgetenv("DISPLAY"));
|
d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().data(), qgetenv("DISPLAY"));
|
||||||
if (d->ptyChannels & StdinChannel)
|
if (d->ptyChannels & StdinChannel) {
|
||||||
dup2(d->pty->slaveFd(), 0);
|
::dup2(d->pty->slaveFd(), 0);
|
||||||
if (d->ptyChannels & StdoutChannel)
|
}
|
||||||
dup2(d->pty->slaveFd(), 1);
|
if (d->ptyChannels & StdoutChannel) {
|
||||||
if (d->ptyChannels & StderrChannel)
|
::dup2(d->pty->slaveFd(), 1);
|
||||||
dup2(d->pty->slaveFd(), 2);
|
}
|
||||||
|
if (d->ptyChannels & StderrChannel) {
|
||||||
|
::dup2(d->pty->slaveFd(), 2);
|
||||||
|
}
|
||||||
KProcess::setupChildProcess();
|
KProcess::setupChildProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "kpty_export.h"
|
#include "kpty_export.h"
|
||||||
|
|
||||||
class KPtyDevice;
|
class KPtyDevice;
|
||||||
|
|
||||||
class KPtyProcessPrivate;
|
class KPtyProcessPrivate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +64,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
explicit KPtyProcess(QObject *parent = 0);
|
explicit KPtyProcess(QObject *parent = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a process using an open pty master.
|
* Construct a process using an open pty master.
|
||||||
|
@ -74,7 +73,7 @@ public:
|
||||||
* The process does not take ownership of the descriptor;
|
* The process does not take ownership of the descriptor;
|
||||||
* it will not be automatically closed at any point.
|
* it will not be automatically closed at any point.
|
||||||
*/
|
*/
|
||||||
KPtyProcess(int ptyMasterFd, QObject *parent = 0);
|
KPtyProcess(int ptyMasterFd, QObject *parent = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
|
@ -136,4 +135,4 @@ private:
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(KPtyProcess::PtyChannels)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(KPtyProcess::PtyChannels)
|
||||||
|
|
||||||
#endif
|
#endif // KPTYPROCESS_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue