author | llornkcor <llornkcor> | 2002-10-10 19:31:03 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-10-10 19:31:03 (UTC) |
commit | 946708623722041624b0435acfb2fa678959adba (patch) (unidiff) | |
tree | cc5e249b7798145a82ca03cd52b7a7dcb3973082 /core/apps | |
parent | 3f838aec8ec65ff0820c92095b9948413ad895aa (diff) | |
download | opie-946708623722041624b0435acfb2fa678959adba.zip opie-946708623722041624b0435acfb2fa678959adba.tar.gz opie-946708623722041624b0435acfb2fa678959adba.tar.bz2 |
execute /bin/bash --login now
-rw-r--r-- | core/apps/embeddedkonsole/MyPty.cpp | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/core/apps/embeddedkonsole/MyPty.cpp b/core/apps/embeddedkonsole/MyPty.cpp index 3622d48..6421ab0 100644 --- a/core/apps/embeddedkonsole/MyPty.cpp +++ b/core/apps/embeddedkonsole/MyPty.cpp | |||
@@ -9,9 +9,9 @@ | |||
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* -------------------------------------------------------------------------- */ | 10 | /* -------------------------------------------------------------------------- */ |
11 | /* */ | 11 | /* */ |
12 | /* Ported Konsole to Qt/Embedded */ | 12 | /* Ported Konsole to Qt/Embedded */ |
13 | /* */ | 13 | /* */ |
14 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 14 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
15 | /* */ | 15 | /* */ |
16 | /* -------------------------------------------------------------------------- */ | 16 | /* -------------------------------------------------------------------------- */ |
17 | 17 | ||
@@ -114,6 +114,6 @@ void MyPty::donePty() | |||
114 | 114 | ||
115 | if (cpid) { | 115 | if (cpid) { |
116 | kill(cpid, SIGHUP); | 116 | kill(cpid, SIGHUP); |
117 | waitpid(cpid, &status, 0); | 117 | waitpid(cpid, &status, 0); |
118 | } | 118 | } |
119 | 119 | ||
@@ -140,38 +140,39 @@ void MyPty::error() | |||
140 | int MyPty::run(const char* cmd, QStrList &, const char*, int) | 140 | int MyPty::run(const char* cmd, QStrList &, const char*, int) |
141 | { | 141 | { |
142 | // This is code from the Qt DumbTerminal example | 142 | // This is code from the Qt DumbTerminal example |
143 | cpid = fork(); | 143 | cpid = fork(); |
144 | 144 | ||
145 | if ( !cpid ) { | 145 | if ( !cpid ) { |
146 | // child - exec shell on tty | 146 | // child - exec shell on tty |
147 | for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL); | 147 | for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL); |
148 | int ttyfd = open(ttynam, O_RDWR); | 148 | int ttyfd = open(ttynam, O_RDWR); |
149 | dup2(ttyfd, STDIN_FILENO); | 149 | dup2(ttyfd, STDIN_FILENO); |
150 | dup2(ttyfd, STDOUT_FILENO); | 150 | dup2(ttyfd, STDOUT_FILENO); |
151 | dup2(ttyfd, STDERR_FILENO); | 151 | dup2(ttyfd, STDERR_FILENO); |
152 | // should be done with tty, so close it | 152 | // should be done with tty, so close it |
153 | close(ttyfd); | 153 | close(ttyfd); |
154 | static struct termios ttmode; | 154 | static struct termios ttmode; |
155 | if ( setsid() < 0 ) | 155 | if ( setsid() < 0 ) |
156 | perror( "failed to set process group" ); | 156 | perror( "failed to set process group" ); |
157 | #if defined (TIOCSCTTY) | 157 | #if defined (TIOCSCTTY) |
158 | // grabbed from APUE by Stevens | 158 | // grabbed from APUE by Stevens |
159 | ioctl(STDIN_FILENO, TIOCSCTTY, 0); | 159 | ioctl(STDIN_FILENO, TIOCSCTTY, 0); |
160 | #endif | 160 | #endif |
161 | tcgetattr( STDIN_FILENO, &ttmode ); | 161 | tcgetattr( STDIN_FILENO, &ttmode ); |
162 | ttmode.c_cc[VINTR] = 3; | 162 | ttmode.c_cc[VINTR] = 3; |
163 | ttmode.c_cc[VERASE] = 8; | 163 | ttmode.c_cc[VERASE] = 8; |
164 | tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); | 164 | tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); |
165 | setenv("TERM","vt100",1); | 165 | setenv("TERM","vt100",1); |
166 | setenv("COLORTERM","0",1); | 166 | setenv("COLORTERM","0",1); |
167 | 167 | ||
168 | if (getuid() == 0) { | 168 | if (getuid() == 0) { |
169 | char msg[] = "WARNING: You are running this shell as root!\n"; | 169 | char msg[] = "WARNING: You are running this shell as root!\n"; |
170 | write(ttyfd, msg, sizeof(msg)); | 170 | write(ttyfd, msg, sizeof(msg)); |
171 | } | 171 | } |
172 | execl(cmd, cmd, 0); | 172 | ; //creates a login shell |
173 | 173 | execl(cmd, cmd, "--login", 0); | |
174 | donePty(); | 174 | |
175 | exit(-1); | 175 | donePty(); |
176 | exit(-1); | ||
176 | } | 177 | } |
177 | 178 | ||
@@ -193,25 +194,25 @@ int MyPty::openPty() | |||
193 | int ttyfd; | 194 | int ttyfd; |
194 | if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) ) | 195 | if ( openpty(&ptyfd,&ttyfd,ttynam,0,0) ) |
195 | ptyfd = -1; | 196 | ptyfd = -1; |
196 | else | 197 | else |
197 | close(ttyfd); // we open the ttynam ourselves. | 198 | close(ttyfd); // we open the ttynam ourselves. |
198 | #else | 199 | #else |
199 | for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) { | 200 | for (const char* c0 = "pqrstuvwxyzabcde"; ptyfd < 0 && *c0 != 0; c0++) { |
200 | for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) { | 201 | for (const char* c1 = "0123456789abcdef"; ptyfd < 0 && *c1 != 0; c1++) { |
201 | sprintf(ptynam,"/dev/pty%c%c",*c0,*c1); | 202 | sprintf(ptynam,"/dev/pty%c%c",*c0,*c1); |
202 | sprintf(ttynam,"/dev/tty%c%c",*c0,*c1); | 203 | sprintf(ttynam,"/dev/tty%c%c",*c0,*c1); |
203 | if ((ptyfd = ::open(ptynam,O_RDWR)) >= 0) { | 204 | if ((ptyfd = ::open(ptynam,O_RDWR)) >= 0) { |
204 | if (geteuid() != 0 && !access(ttynam,R_OK|W_OK) == 0) { | 205 | if (geteuid() != 0 && !access(ttynam,R_OK|W_OK) == 0) { |
205 | ::close(ptyfd); | 206 | ::close(ptyfd); |
206 | ptyfd = -1; | 207 | ptyfd = -1; |
207 | } | 208 | } |
208 | } | 209 | } |
209 | } | 210 | } |
210 | } | 211 | } |
211 | #endif | 212 | #endif |
212 | 213 | ||
213 | if ( ptyfd < 0 ) { | 214 | if ( ptyfd < 0 ) { |
214 | qApp->exit(1); | 215 | qApp->exit(1); |
215 | return -1; | 216 | return -1; |
216 | } | 217 | } |
217 | 218 | ||
@@ -250,5 +251,5 @@ void MyPty::send_bytes(const char* s, int len) | |||
250 | #endif | 251 | #endif |
251 | 252 | ||
252 | ::write(fd, s, len); | 253 | ::write(fd, s, len); |
253 | } | 254 | } |
254 | 255 | ||