-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqvtptythread.cpp
58 lines (49 loc) · 993 Bytes
/
qvtptythread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "qvtptythread.h"
#include <sys/ioctl.h>
#include <qstring.h>
QVTPtyThread :: QVTPtyThread ( QObject * p )
: parent ( p )
{
}
void QVTPtyThread :: run ()
{
//int md ; // master descriptor
int pid ;
winsize wsize ;
wsize.ws_row = 24 ;
wsize.ws_col = 80 ;
if ( ( pid = forkpty ( & md, NULL, NULL, NULL ) ) == 0 )
{
//ioctl ( md, TIOCGWINSZ, (char *) & wsize ) ;
// child process
execl ( "/bin/bash", "bash", ( char * ) 0 ) ;
}
else
{
ioctl ( md, TIOCSWINSZ, (char *) & wsize ) ;
// parent process
fd_set readset ;
char * c ;
QVTPtyEvent * e ;
int n ;
while (1)
{
FD_ZERO ( & readset ) ;
FD_SET ( md, & readset ) ;
select ( md + 1, & readset, NULL, NULL, NULL ) ;
c = new char [ 1024 ] ;
n = read ( md , ( void * ) c, 1023 /*SSIZE_MAX*/ ) ;
if( n >= 0 )
{
c [ n ] = 0 ;
e = new QVTPtyEvent ( n, c ) ;
QApplication :: postEvent ( parent, e ) ;
}
else
{
QApplication :: exit();
break;
}
}
}
}