author | zecke <zecke> | 2002-10-15 01:14:17 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-15 01:14:17 (UTC) |
commit | e0efd37513192d9a17fa9a9f46bbaed0ca38029c (patch) (unidiff) | |
tree | 04163d93fc4c4185d322912e9430eff9b36b71cc | |
parent | b12b38a00c66ddc100f3fff75478539b8b797928 (diff) | |
download | opie-e0efd37513192d9a17fa9a9f46bbaed0ca38029c.zip opie-e0efd37513192d9a17fa9a9f46bbaed0ca38029c.tar.gz opie-e0efd37513192d9a17fa9a9f46bbaed0ca38029c.tar.bz2 |
The right way to deal with the pipe
-rw-r--r-- | noncore/apps/opie-console/MyPty.cpp | 10 | ||||
-rw-r--r-- | noncore/apps/opie-console/MyPty.h | 2 |
2 files changed, 9 insertions, 3 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp index cacb4ce..ae01392 100644 --- a/noncore/apps/opie-console/MyPty.cpp +++ b/noncore/apps/opie-console/MyPty.cpp | |||
@@ -107,25 +107,27 @@ void MyPty::setSize(int lines, int columns) | |||
107 | 107 | ||
108 | 108 | ||
109 | void MyPty::donePty() | 109 | void MyPty::donePty() |
110 | { | 110 | { |
111 | // This is code from the Qt DumbTerminal example | 111 | // This is code from the Qt DumbTerminal example |
112 | int status = 0; | 112 | int status = 0; |
113 | 113 | ||
114 | ::close(m_fd); | 114 | ::close(m_fd); |
115 | 115 | ||
116 | if (m_cpid) { | 116 | if (m_cpid) { |
117 | qWarning("killing!!!"); | 117 | qWarning("killing!!!"); |
118 | kill(m_cpid, SIGHUP); | 118 | kill(m_cpid, SIGHUP); |
119 | waitpid(m_cpid, &status, 0); | 119 | //waitpid(m_cpid, &status, 0); |
120 | delete m_sn_e; | ||
121 | m_sn_e = 0l; | ||
120 | } | 122 | } |
121 | 123 | ||
122 | m_cpid = 0; | 124 | m_cpid = 0; |
123 | // emit done(status); | 125 | // emit done(status); |
124 | } | 126 | } |
125 | 127 | ||
126 | 128 | ||
127 | const char* MyPty::deviceName() | 129 | const char* MyPty::deviceName() |
128 | { | 130 | { |
129 | return m_ttynam; | 131 | return m_ttynam; |
130 | } | 132 | } |
131 | 133 | ||
@@ -177,27 +179,28 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int) | |||
177 | if (getuid() == 0) { | 179 | if (getuid() == 0) { |
178 | char msg[] = "WARNING: You are running this shell as root!\n"; | 180 | char msg[] = "WARNING: You are running this shell as root!\n"; |
179 | write(ttyfd, msg, sizeof(msg)); | 181 | write(ttyfd, msg, sizeof(msg)); |
180 | } | 182 | } |
181 | execl(cmd, cmd, 0); | 183 | execl(cmd, cmd, 0); |
182 | 184 | ||
183 | donePty(); | 185 | donePty(); |
184 | exit(-1); | 186 | exit(-1); |
185 | } | 187 | } |
186 | 188 | ||
187 | // parent - continue as a widget | 189 | // parent - continue as a widget |
188 | QSocketNotifier* sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this); | 190 | QSocketNotifier* sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this); |
189 | // QSocketNotifier* sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this); | 191 | delete m_sn_e; |
192 | m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this); | ||
190 | connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); | 193 | connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); |
191 | // connect(sn_e,SIGNAL(activated(int)),this,SLOT(error())); | 194 | connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error())); |
192 | 195 | ||
193 | return 0; | 196 | return 0; |
194 | } | 197 | } |
195 | 198 | ||
196 | int MyPty::openPty() | 199 | int MyPty::openPty() |
197 | { | 200 | { |
198 | // This is code from the Qt DumbTerminal example | 201 | // This is code from the Qt DumbTerminal example |
199 | int ptyfd = -1; | 202 | int ptyfd = -1; |
200 | 203 | ||
201 | #ifdef HAVE_OPENPTY | 204 | #ifdef HAVE_OPENPTY |
202 | int ttyfd; | 205 | int ttyfd; |
203 | if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) ) | 206 | if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) ) |
@@ -223,24 +226,25 @@ int MyPty::openPty() | |||
223 | qApp->exit(1); | 226 | qApp->exit(1); |
224 | return -1; | 227 | return -1; |
225 | } | 228 | } |
226 | 229 | ||
227 | return ptyfd; | 230 | return ptyfd; |
228 | } | 231 | } |
229 | 232 | ||
230 | /*! | 233 | /*! |
231 | Create an instance. | 234 | Create an instance. |
232 | */ | 235 | */ |
233 | MyPty::MyPty(const Profile&) : m_cpid(0) | 236 | MyPty::MyPty(const Profile&) : m_cpid(0) |
234 | { | 237 | { |
238 | m_sn_e = 0l; | ||
235 | m_fd = openPty(); | 239 | m_fd = openPty(); |
236 | ProcCtl* ctl = ProcCtl::self(); | 240 | ProcCtl* ctl = ProcCtl::self(); |
237 | } | 241 | } |
238 | 242 | ||
239 | /*! | 243 | /*! |
240 | Destructor. | 244 | Destructor. |
241 | Note that the related client program is not killed | 245 | Note that the related client program is not killed |
242 | (yet) when a instance is deleted. | 246 | (yet) when a instance is deleted. |
243 | */ | 247 | */ |
244 | MyPty::~MyPty() | 248 | MyPty::~MyPty() |
245 | { | 249 | { |
246 | donePty(); | 250 | donePty(); |
diff --git a/noncore/apps/opie-console/MyPty.h b/noncore/apps/opie-console/MyPty.h index 9231a8a..3166fa0 100644 --- a/noncore/apps/opie-console/MyPty.h +++ b/noncore/apps/opie-console/MyPty.h | |||
@@ -19,24 +19,25 @@ | |||
19 | /*! \file | 19 | /*! \file |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef MY_PTY_H | 22 | #ifndef MY_PTY_H |
23 | #define MY_PTY_H | 23 | #define MY_PTY_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstrlist.h> | 26 | #include <qstrlist.h> |
27 | 27 | ||
28 | #include "io_layer.h" | 28 | #include "io_layer.h" |
29 | 29 | ||
30 | class Profile; | 30 | class Profile; |
31 | class QSocketNotifier; | ||
31 | class MyPty : public IOLayer | 32 | class MyPty : public IOLayer |
32 | { | 33 | { |
33 | Q_OBJECT | 34 | Q_OBJECT |
34 | public: | 35 | public: |
35 | 36 | ||
36 | MyPty(const Profile&); | 37 | MyPty(const Profile&); |
37 | ~MyPty(); | 38 | ~MyPty(); |
38 | 39 | ||
39 | 40 | ||
40 | 41 | ||
41 | QString identifier()const; | 42 | QString identifier()const; |
42 | QString name()const; | 43 | QString name()const; |
@@ -81,15 +82,16 @@ protected slots: | |||
81 | void readPty(); | 82 | void readPty(); |
82 | void donePty(); | 83 | void donePty(); |
83 | 84 | ||
84 | private: | 85 | private: |
85 | int openPty(); | 86 | int openPty(); |
86 | 87 | ||
87 | private: | 88 | private: |
88 | 89 | ||
89 | char m_ptynam[16]; // "/dev/ptyxx" | "/dev/ptmx" | 90 | char m_ptynam[16]; // "/dev/ptyxx" | "/dev/ptmx" |
90 | char m_ttynam[16]; // "/dev/ttyxx" | "/dev/pts/########..." | 91 | char m_ttynam[16]; // "/dev/ttyxx" | "/dev/pts/########..." |
91 | int m_fd; | 92 | int m_fd; |
92 | int m_cpid; | 93 | int m_cpid; |
94 | QSocketNotifier* m_sn_e; | ||
93 | }; | 95 | }; |
94 | 96 | ||
95 | #endif | 97 | #endif |