author | wazlaf <wazlaf> | 2002-10-30 20:30:08 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-10-30 20:30:08 (UTC) |
commit | 3c1824f39867bc2ada45fe32785267caa5dfb04b (patch) (unidiff) | |
tree | 08a6e7872f5d100cac7c1adb983e44f6b145af2f /noncore/apps/opie-console/MyPty.cpp | |
parent | 9af1c14974a2131505b82441bfb0bf0475bb2cc9 (diff) | |
download | opie-3c1824f39867bc2ada45fe32785267caa5dfb04b.zip opie-3c1824f39867bc2ada45fe32785267caa5dfb04b.tar.gz opie-3c1824f39867bc2ada45fe32785267caa5dfb04b.tar.bz2 |
Console configuration widget done, Environment variables can now be set
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 | |||
@@ -139,20 +139,14 @@ 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) |
@@ -179,13 +173,16 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int) | |||
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 | ||
@@ -260,12 +257,13 @@ MyPty::MyPty(const Profile& prof) : m_cpid(0) | |||
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. |
@@ -288,14 +286,23 @@ bool MyPty::open() { | |||
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 |