summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/MyPty.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-console/MyPty.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/MyPty.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp
index 10828b0..cacb4ce 100644
--- a/noncore/apps/opie-console/MyPty.cpp
+++ b/noncore/apps/opie-console/MyPty.cpp
@@ -79,12 +79,13 @@
79#include <sys/wait.h> 79#include <sys/wait.h>
80 80
81#ifdef HAVE_OPENPTY 81#ifdef HAVE_OPENPTY
82#include <pty.h> 82#include <pty.h>
83#endif 83#endif
84 84
85#include "procctl.h"
85#include "MyPty.h" 86#include "MyPty.h"
86 87
87 88
88#undef VERBOSE_DEBUG 89#undef VERBOSE_DEBUG
89 90
90 91
@@ -110,28 +111,31 @@ void MyPty::donePty()
110 // This is code from the Qt DumbTerminal example 111 // This is code from the Qt DumbTerminal example
111 int status = 0; 112 int status = 0;
112 113
113 ::close(m_fd); 114 ::close(m_fd);
114 115
115 if (m_cpid) { 116 if (m_cpid) {
117 qWarning("killing!!!");
116 kill(m_cpid, SIGHUP); 118 kill(m_cpid, SIGHUP);
117 waitpid(m_cpid, &status, 0); 119 waitpid(m_cpid, &status, 0);
118 } 120 }
119 121
120 emit done(status); 122 m_cpid = 0;
123// emit done(status);
121} 124}
122 125
123 126
124const char* MyPty::deviceName() 127const char* MyPty::deviceName()
125{ 128{
126 return m_ttynam; 129 return m_ttynam;
127} 130}
128 131
129 132
130void MyPty::error() 133void MyPty::error()
131{ 134{
135 qWarning("error");
132 // This is code from the Qt DumbTerminal example 136 // This is code from the Qt DumbTerminal example
133 donePty(); 137 donePty();
134} 138}
135 139
136void MyPty::start() { 140void MyPty::start() {
137 char* cmd = "/bin/sh"; 141 char* cmd = "/bin/sh";
@@ -179,15 +183,15 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int)
179 donePty(); 183 donePty();
180 exit(-1); 184 exit(-1);
181 } 185 }
182 186
183 // parent - continue as a widget 187 // parent - continue as a widget
184 QSocketNotifier* sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this); 188 QSocketNotifier* sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this);
185 QSocketNotifier* sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this); 189// QSocketNotifier* sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this);
186 connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); 190 connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty()));
187 connect(sn_e,SIGNAL(activated(int)),this,SLOT(error())); 191// connect(sn_e,SIGNAL(activated(int)),this,SLOT(error()));
188 192
189 return 0; 193 return 0;
190} 194}
191 195
192int MyPty::openPty() 196int MyPty::openPty()
193{ 197{
@@ -226,12 +230,13 @@ int MyPty::openPty()
226/*! 230/*!
227 Create an instance. 231 Create an instance.
228*/ 232*/
229MyPty::MyPty(const Profile&) : m_cpid(0) 233MyPty::MyPty(const Profile&) : m_cpid(0)
230{ 234{
231 m_fd = openPty(); 235 m_fd = openPty();
236 ProcCtl* ctl = ProcCtl::self();
232} 237}
233 238
234/*! 239/*!
235 Destructor. 240 Destructor.
236 Note that the related client program is not killed 241 Note that the related client program is not killed
237 (yet) when a instance is deleted. 242 (yet) when a instance is deleted.
@@ -256,13 +261,13 @@ void MyPty::close() {
256void MyPty::reload( const Profile& ) { 261void MyPty::reload( const Profile& ) {
257 262
258} 263}
259/*! sends len bytes through the line */ 264/*! sends len bytes through the line */
260void MyPty::send(const QByteArray& ar) 265void MyPty::send(const QByteArray& ar)
261{ 266{
262 267 qWarning("sending!");
263#ifdef VERBOSE_DEBUG 268#ifdef VERBOSE_DEBUG
264 // verbose debug 269 // verbose debug
265 printf("sending bytes:\n"); 270 printf("sending bytes:\n");
266 for (uint i = 0; i < ar.count(); i++) 271 for (uint i = 0; i < ar.count(); i++)
267 printf("%c", ar[i]); 272 printf("%c", ar[i]);
268 printf("\n"); 273 printf("\n");
@@ -271,22 +276,29 @@ void MyPty::send(const QByteArray& ar)
271 ::write(m_fd, ar.data(), ar.count()); 276 ::write(m_fd, ar.data(), ar.count());
272} 277}
273 278
274/*! indicates that a block of data is received */ 279/*! indicates that a block of data is received */
275void MyPty::readPty() 280void MyPty::readPty()
276{ 281{
282 qWarning("read");
277 QByteArray buf(4096); 283 QByteArray buf(4096);
278 284
279 int len = ::read( m_fd, buf.data(), 4096 ); 285 int len = ::read( m_fd, buf.data(), 4096 );
280 286
281 if (len == -1) 287 if (len == -1 || len == 0) {
288 qWarning("donePty!!! now!");
282 donePty(); 289 donePty();
290 qWarning("return %s", sender()->className() );
291 delete sender();
292 return;
293 }
283 294
284 if (len < 0) 295 if (len < 0)
285 return; 296 return;
286 297
298
287 buf.resize(len); 299 buf.resize(len);
288 emit received(buf); 300 emit received(buf);
289 301
290#ifdef VERBOSE_DEBUG 302#ifdef VERBOSE_DEBUG
291 // verbose debug 303 // verbose debug
292 printf("read bytes:\n"); 304 printf("read bytes:\n");