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.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp
index b6ae1d9..565d03f 100644
--- a/noncore/apps/opie-console/MyPty.cpp
+++ b/noncore/apps/opie-console/MyPty.cpp
@@ -114,16 +114,19 @@ void MyPty::donePty()
114 ::close(m_fd); 114 ::close(m_fd);
115 115
116 if (m_cpid) { 116 if (m_cpid) {
117 kill(m_cpid, SIGHUP); 117 kill(m_cpid, SIGHUP);
118 //waitpid(m_cpid, &status, 0); 118 //waitpid(m_cpid, &status, 0);
119 delete m_sn_e; 119 delete m_sn_e;
120 delete m_sn_r;
120 m_sn_e = 0l; 121 m_sn_e = 0l;
122 m_sn_r = 0l;
121 } 123 }
122 124
123 m_cpid = 0; 125 m_cpid = 0;
126 m_fd = -1;
124// emit done(status); 127// emit done(status);
125} 128}
126 129
127 130
128const char* MyPty::deviceName() 131const char* MyPty::deviceName()
129{ 132{
@@ -182,16 +185,17 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int)
182 185
183 donePty(); 186 donePty();
184 exit(-1); 187 exit(-1);
185 } 188 }
186 189
187 // parent - continue as a widget 190 // parent - continue as a widget
188 QSocketNotifier* sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this); 191 delete m_sn_r;
192 m_sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this);
189 delete m_sn_e; 193 delete m_sn_e;
190 m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this); 194 m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this);
191 connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); 195 connect(m_sn_r,SIGNAL(activated(int)),this,SLOT(readPty()));
192 connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error())); 196 connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error()));
193 197
194 return 0; 198 return 0;
195} 199}
196 200
197int MyPty::openPty() 201int MyPty::openPty()
@@ -218,25 +222,26 @@ int MyPty::openPty()
218 } 222 }
219 } 223 }
220 } 224 }
221#endif 225#endif
222 226
223 if ( ptyfd < 0 ) { 227 if ( ptyfd < 0 ) {
224 qApp->exit(1); 228 //qApp->exit(1);
225 return -1; 229 return -1;
226 } 230 }
227 231
228 return ptyfd; 232 return ptyfd;
229} 233}
230 234
231/*! 235/*!
232 Create an instance. 236 Create an instance.
233*/ 237*/
234MyPty::MyPty(const Profile&) : m_cpid(0) 238MyPty::MyPty(const Profile&) : m_cpid(0)
235{ 239{
236 m_sn_e = 0l; 240 m_sn_e = 0l;
241 m_sn_r = 0l;
237 m_fd = openPty(); 242 m_fd = openPty();
238 ProcCtl* ctl = ProcCtl::self(); 243 ProcCtl* ctl = ProcCtl::self();
239} 244}
240 245
241/*! 246/*!
242 Destructor. 247 Destructor.
@@ -251,17 +256,21 @@ QString MyPty::identifier()const {
251 return QString::fromLatin1("term"); 256 return QString::fromLatin1("term");
252} 257}
253QString MyPty::name()const{ 258QString MyPty::name()const{
254 return identifier(); 259 return identifier();
255} 260}
256bool MyPty::open() { 261bool MyPty::open() {
262 if (m_fd < 0)
263 m_fd = openPty();
264
257 start(); 265 start();
258 return true; 266 return true;
259} 267}
260void MyPty::close() { 268void MyPty::close() {
261 donePty(); 269 donePty();
270 m_fd = openPty();
262} 271}
263void MyPty::reload( const Profile& ) { 272void MyPty::reload( const Profile& ) {
264 273
265} 274}
266/*! sends len bytes through the line */ 275/*! sends len bytes through the line */
267void MyPty::send(const QByteArray& ar) 276void MyPty::send(const QByteArray& ar)
@@ -283,13 +292,12 @@ void MyPty::readPty()
283 QByteArray buf(4096); 292 QByteArray buf(4096);
284 293
285 int len = ::read( m_fd, buf.data(), 4096 ); 294 int len = ::read( m_fd, buf.data(), 4096 );
286 295
287 if (len == -1 || len == 0) { 296 if (len == -1 || len == 0) {
288 donePty(); 297 donePty();
289 delete sender();
290 return; 298 return;
291 } 299 }
292 300
293 if (len < 0) 301 if (len < 0)
294 return; 302 return;
295 303
@@ -303,7 +311,14 @@ void MyPty::readPty()
303 for (uint i = 0; i < buf.count(); i++) 311 for (uint i = 0; i < buf.count(); i++)
304 printf("%c", buf[i]); 312 printf("%c", buf[i]);
305 printf("\n"); 313 printf("\n");
306#endif 314#endif
307 315
308} 316}
317QBitArray MyPty::supports()const {
318 QBitArray ar(3);
319 ar[0] = 1;
320 ar[1] = 0;
321 ar[2] = 0;
309 322
323 return ar;
324}