-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 | |||
@@ -8,11 +8,11 @@ | |||
8 | /* */ | 8 | /* */ |
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 | ||
18 | /* If you're compiling konsole on non-Linux platforms and find | 18 | /* If you're compiling konsole on non-Linux platforms and find |
@@ -113,8 +113,8 @@ void MyPty::donePty() | |||
113 | ::close(fd); | 113 | ::close(fd); |
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 | ||
120 | emit done(status); | 120 | emit done(status); |
@@ -139,40 +139,41 @@ void MyPty::error() | |||
139 | */ | 139 | */ |
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 | ||
178 | // parent - continue as a widget | 179 | // parent - continue as a widget |
@@ -192,27 +193,27 @@ int MyPty::openPty() | |||
192 | #ifdef HAVE_OPENPTY | 193 | #ifdef HAVE_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 | ||
218 | return ptyfd; | 219 | return ptyfd; |
@@ -249,7 +250,7 @@ void MyPty::send_bytes(const char* s, int len) | |||
249 | printf("\n"); | 250 | printf("\n"); |
250 | #endif | 251 | #endif |
251 | 252 | ||
252 | ::write(fd, s, len); | 253 | ::write(fd, s, len); |
253 | } | 254 | } |
254 | 255 | ||
255 | /*! indicates that a block of data is received */ | 256 | /*! indicates that a block of data is received */ |