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.cpp27
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
@@ -137,24 +137,18 @@ const char* MyPty::deviceName()
137 137
138void MyPty::error() 138void 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
144void MyPty::start() { 144void 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*/
158int MyPty::run(const char* cmd, QStrList &, const char*, int) 152int 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
@@ -177,17 +171,20 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int)
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);
@@ -258,16 +255,17 @@ MyPty::MyPty(const Profile& prof) : m_cpid(0)
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*/
273MyPty::~MyPty() 271MyPty::~MyPty()
@@ -286,18 +284,27 @@ bool MyPty::open() {
286 284
287 start(); 285 start();
288 return true; 286 return true;
289} 287}
290void MyPty::close() { 288void MyPty::close() {
291 donePty(); 289 donePty();
292 m_fd = openPty(); 290 m_fd = openPty();
293} 291}
294void MyPty::reload( const Profile& ) { 292void 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 */
298void MyPty::send(const QByteArray& ar) 305void 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++)