Diffstat (limited to 'noncore/apps/opie-console/MyPty.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/MyPty.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp index 534f79a..b0f0275 100644 --- a/noncore/apps/opie-console/MyPty.cpp +++ b/noncore/apps/opie-console/MyPty.cpp | |||
@@ -133,32 +133,26 @@ const char* MyPty::deviceName() | |||
133 | { | 133 | { |
134 | return m_ttynam; | 134 | return m_ttynam; |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | void MyPty::error() | 138 | void MyPty::error() |
139 | { | 139 | { |
140 | // This is code from the Qt DumbTerminal example | 140 | // This is code from the Qt DumbTerminal example |
141 | donePty(); | 141 | donePty(); |
142 | } | 142 | } |
143 | 143 | ||
144 | void MyPty::start() { | 144 | void MyPty::start() { |
145 | char* cmd = "/bin/sh"; | ||
146 | |||
147 | if ( QFile::exists( "/bin/bash" ) ) { | ||
148 | cmd = "/bin/bash"; | ||
149 | } | ||
150 | |||
151 | QStrList lis; | 145 | QStrList lis; |
152 | int r =run(cmd, lis, 0, 0); | 146 | int r =run(m_cmd.latin1(), lis, 0, 0); |
153 | r = r; | 147 | r = r; |
154 | } | 148 | } |
155 | /*! | 149 | /*! |
156 | start the client program. | 150 | start the client program. |
157 | */ | 151 | */ |
158 | int MyPty::run(const char* cmd, QStrList &, const char*, int) | 152 | int MyPty::run(const char* cmd, QStrList &, const char*, int) |
159 | { | 153 | { |
160 | // This is code from the Qt DumbTerminal example | 154 | // This is code from the Qt DumbTerminal example |
161 | m_cpid = fork(); | 155 | m_cpid = fork(); |
162 | 156 | ||
163 | if ( !m_cpid ) { | 157 | if ( !m_cpid ) { |
164 | // child - exec shell on tty | 158 | // child - exec shell on tty |
@@ -173,25 +167,28 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int) | |||
173 | if ( setsid() < 0 ) | 167 | if ( setsid() < 0 ) |
174 | perror( "failed to set process group" ); | 168 | perror( "failed to set process group" ); |
175 | #if defined (TIOCSCTTY) | 169 | #if defined (TIOCSCTTY) |
176 | // grabbed from APUE by Stevens | 170 | // grabbed from APUE by Stevens |
177 | ioctl(STDIN_FILENO, TIOCSCTTY, 0); | 171 | ioctl(STDIN_FILENO, TIOCSCTTY, 0); |
178 | #endif | 172 | #endif |
179 | tcgetattr( STDIN_FILENO, &ttmode ); | 173 | tcgetattr( STDIN_FILENO, &ttmode ); |
180 | ttmode.c_cc[VINTR] = 3; | 174 | ttmode.c_cc[VINTR] = 3; |
181 | ttmode.c_cc[VERASE] = 8; | 175 | ttmode.c_cc[VERASE] = 8; |
182 | tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); | 176 | tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); |
183 | setenv("TERM",m_term,1); | 177 | setenv("TERM",m_term,1); |
184 | setenv("COLORTERM","0",1); | 178 | setenv("COLORTERM","0",1); |
185 | 179 | EnvironmentMap::Iterator it; | |
180 | for (it = m_env.begin(); it != m_env.end(); it++) { | ||
181 | setenv(it.key().latin1(), it.data().latin1(), 1); | ||
182 | } | ||
186 | if (getuid() == 0) { | 183 | if (getuid() == 0) { |
187 | char msg[] = "WARNING: You are running this shell as root!\n"; | 184 | char msg[] = "WARNING: You are running this shell as root!\n"; |
188 | write(ttyfd, msg, sizeof(msg)); | 185 | write(ttyfd, msg, sizeof(msg)); |
189 | } | 186 | } |
190 | execl(cmd, cmd, 0); | 187 | execl(cmd, cmd, 0); |
191 | 188 | ||
192 | donePty(); | 189 | donePty(); |
193 | exit(-1); | 190 | exit(-1); |
194 | } | 191 | } |
195 | 192 | ||
196 | // parent - continue as a widget | 193 | // parent - continue as a widget |
197 | delete m_sn_r; | 194 | delete m_sn_r; |
@@ -254,24 +251,25 @@ MyPty::MyPty(const Profile& prof) : m_cpid(0) | |||
254 | case Profile::Linux: | 251 | case Profile::Linux: |
255 | m_term = "linux"; | 252 | m_term = "linux"; |
256 | break; | 253 | break; |
257 | case Profile::XTerm: | 254 | case Profile::XTerm: |
258 | m_term = "xterm"; | 255 | m_term = "xterm"; |
259 | break; | 256 | break; |
260 | } | 257 | } |
261 | m_sn_e = 0l; | 258 | m_sn_e = 0l; |
262 | m_sn_r = 0l; | 259 | m_sn_r = 0l; |
263 | m_fd = openPty(); | 260 | m_fd = openPty(); |
264 | ProcCtl* ctl = ProcCtl::self(); | 261 | ProcCtl* ctl = ProcCtl::self(); |
265 | Q_UNUSED(ctl); | 262 | Q_UNUSED(ctl); |
263 | reload(prof); | ||
266 | } | 264 | } |
267 | 265 | ||
268 | /*! | 266 | /*! |
269 | Destructor. | 267 | Destructor. |
270 | Note that the related client program is not killed | 268 | Note that the related client program is not killed |
271 | (yet) when a instance is deleted. | 269 | (yet) when a instance is deleted. |
272 | */ | 270 | */ |
273 | MyPty::~MyPty() | 271 | MyPty::~MyPty() |
274 | { | 272 | { |
275 | donePty(); | 273 | donePty(); |
276 | } | 274 | } |
277 | QString MyPty::identifier()const { | 275 | QString MyPty::identifier()const { |
@@ -282,26 +280,35 @@ QString MyPty::name()const{ | |||
282 | } | 280 | } |
283 | bool MyPty::open() { | 281 | bool MyPty::open() { |
284 | if (m_fd < 0) | 282 | if (m_fd < 0) |
285 | m_fd = openPty(); | 283 | m_fd = openPty(); |
286 | 284 | ||
287 | start(); | 285 | start(); |
288 | return true; | 286 | return true; |
289 | } | 287 | } |
290 | void MyPty::close() { | 288 | void MyPty::close() { |
291 | donePty(); | 289 | donePty(); |
292 | m_fd = openPty(); | 290 | m_fd = openPty(); |
293 | } | 291 | } |
294 | void MyPty::reload( const Profile& ) { | 292 | void MyPty::reload( const Profile& prof) { |
295 | 293 | m_env.clear(); | |
294 | m_cmd = prof.readEntry("Command", "/bin/bash"); | ||
295 | int envcount = prof.readNumEntry("EnvVars", 0); | ||
296 | for (int i=0; i<envcount; i++) { | ||
297 | QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); | ||
298 | QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); | ||
299 | if (!(name.isEmpty() || value.isEmpty())) { | ||
300 | m_env.insert(name, value); | ||
301 | } | ||
302 | } | ||
296 | } | 303 | } |
297 | /*! sends len bytes through the line */ | 304 | /*! sends len bytes through the line */ |
298 | void MyPty::send(const QByteArray& ar) | 305 | void MyPty::send(const QByteArray& ar) |
299 | { | 306 | { |
300 | #ifdef VERBOSE_DEBUG | 307 | #ifdef VERBOSE_DEBUG |
301 | // verbose debug | 308 | // verbose debug |
302 | printf("sending bytes:\n"); | 309 | printf("sending bytes:\n"); |
303 | for (uint i = 0; i < ar.count(); i++) | 310 | for (uint i = 0; i < ar.count(); i++) |
304 | printf("%c", ar[i]); | 311 | printf("%c", ar[i]); |
305 | printf("\n"); | 312 | printf("\n"); |
306 | #endif | 313 | #endif |
307 | 314 | ||