• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KPty

  • kpty
kptyprocess.cpp
Go to the documentation of this file.
1/*
2 This file is part of the KDE libraries
3
4 Copyright (C) 2007 Oswald Buddenhagen <ossi@kde.org>
5
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.
10
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.
15
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.
20*/
21
22
23#include "kptyprocess.h"
24#include "kprocess_p.h"
25
26#include <kuser.h>
27#include <kptydevice.h>
28
29#include <stdlib.h>
30#include <unistd.h>
31
33// private data //
35
36struct KPtyProcessPrivate : KProcessPrivate {
37 KPtyProcessPrivate() :
38 ptyChannels(KPtyProcess::NoChannels),
39 addUtmp(false)
40 {
41 }
42
43 void _k_onStateChanged(QProcess::ProcessState newState)
44 {
45 if (newState == QProcess::NotRunning && addUtmp)
46 pty->logout();
47 }
48
49 KPtyDevice *pty;
50 KPtyProcess::PtyChannels ptyChannels;
51 bool addUtmp : 1;
52};
53
54KPtyProcess::KPtyProcess(QObject *parent) :
55 KProcess(new KPtyProcessPrivate, parent)
56{
57 Q_D(KPtyProcess);
58
59 d->pty = new KPtyDevice(this);
60 d->pty->open();
61 connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
62 SLOT(_k_onStateChanged(QProcess::ProcessState)));
63}
64
65KPtyProcess::KPtyProcess(int ptyMasterFd, QObject *parent) :
66 KProcess(new KPtyProcessPrivate, parent)
67{
68 Q_D(KPtyProcess);
69
70 d->pty = new KPtyDevice(this);
71 d->pty->open(ptyMasterFd);
72 connect(this, SIGNAL(stateChanged(QProcess::ProcessState)),
73 SLOT(_k_onStateChanged(QProcess::ProcessState)));
74}
75
76KPtyProcess::~KPtyProcess()
77{
78 Q_D(KPtyProcess);
79
80 if (state() != QProcess::NotRunning && d->addUtmp) {
81 d->pty->logout();
82 disconnect(SIGNAL(stateChanged(QProcess::ProcessState)),
83 this, SLOT(_k_onStateChanged(QProcess::ProcessState)));
84 }
85 delete d->pty;
86}
87
88void KPtyProcess::setPtyChannels(PtyChannels channels)
89{
90 Q_D(KPtyProcess);
91
92 d->ptyChannels = channels;
93}
94
95KPtyProcess::PtyChannels KPtyProcess::ptyChannels() const
96{
97 Q_D(const KPtyProcess);
98
99 return d->ptyChannels;
100}
101
102void KPtyProcess::setUseUtmp(bool value)
103{
104 Q_D(KPtyProcess);
105
106 d->addUtmp = value;
107}
108
109bool KPtyProcess::isUseUtmp() const
110{
111 Q_D(const KPtyProcess);
112
113 return d->addUtmp;
114}
115
116KPtyDevice *KPtyProcess::pty() const
117{
118 Q_D(const KPtyProcess);
119
120 return d->pty;
121}
122
123void KPtyProcess::setupChildProcess()
124{
125 Q_D(KPtyProcess);
126
127 d->pty->setCTty();
128 if (d->addUtmp)
129 d->pty->login(KUser(KUser::UseRealUserID).loginName().toLocal8Bit().data(), qgetenv("DISPLAY"));
130 if (d->ptyChannels & StdinChannel)
131 dup2(d->pty->slaveFd(), 0);
132 if (d->ptyChannels & StdoutChannel)
133 dup2(d->pty->slaveFd(), 1);
134 if (d->ptyChannels & StderrChannel)
135 dup2(d->pty->slaveFd(), 2);
136
137 KProcess::setupChildProcess();
138}
139
140#include "kptyprocess.moc"
KProcessPrivate
KProcess
KPtyDevice
Encapsulates KPty into a QIODevice, so it can be used with Q*Stream, etc.
Definition: kptydevice.h:38
KPtyProcess
This class extends KProcess by support for PTYs (pseudo TTYs).
Definition: kptyprocess.h:49
KPtyProcess::isUseUtmp
bool isUseUtmp() const
Get whether to register the process as a TTY login in utmp.
Definition: kptyprocess.cpp:109
KPtyProcess::ptyChannels
PtyChannels ptyChannels() const
Query to which channels the PTY is assigned.
Definition: kptyprocess.cpp:95
KPtyProcess::setUseUtmp
void setUseUtmp(bool value)
Set whether to register the process as a TTY login in utmp.
Definition: kptyprocess.cpp:102
KPtyProcess::setPtyChannels
void setPtyChannels(PtyChannels channels)
Set to which channels the PTY should be assigned.
Definition: kptyprocess.cpp:88
KPtyProcess::setupChildProcess
virtual void setupChildProcess()
Definition: kptyprocess.cpp:123
KPtyProcess::pty
KPtyDevice * pty() const
Get the PTY device of this process.
Definition: kptyprocess.cpp:116
KPtyProcess::~KPtyProcess
virtual ~KPtyProcess()
Destructor.
Definition: kptyprocess.cpp:76
KPtyProcess::StdinChannel
@ StdinChannel
Connect PTY to stdin.
Definition: kptyprocess.h:56
KPtyProcess::StdoutChannel
@ StdoutChannel
Connect PTY to stdout.
Definition: kptyprocess.h:57
KPtyProcess::StderrChannel
@ StderrChannel
Connect PTY to stderr.
Definition: kptyprocess.h:58
KPtyProcess::KPtyProcess
KPtyProcess(QObject *parent=0)
Constructor.
Definition: kptyprocess.cpp:54
KUser
KUser::UseRealUserID
UseRealUserID
QObject
kprocess_p.h
kptydevice.h
kptyprocess.h
kuser.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPty

Skip menu "KPty"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal