Diffstat (limited to 'core/apps/embeddedkonsole/MyPty.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/embeddedkonsole/MyPty.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/core/apps/embeddedkonsole/MyPty.cpp b/core/apps/embeddedkonsole/MyPty.cpp index 9adc248..7e820ad 100644 --- a/core/apps/embeddedkonsole/MyPty.cpp +++ b/core/apps/embeddedkonsole/MyPty.cpp | |||
@@ -142,49 +142,50 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int) | |||
142 | { | 142 | { |
143 | // This is code from the Qt DumbTerminal example | 143 | // This is code from the Qt DumbTerminal example |
144 | cpid = fork(); | 144 | cpid = fork(); |
145 | 145 | ||
146 | if ( !cpid ) { | 146 | if ( !cpid ) { |
147 | // child - exec shell on tty | 147 | // child - exec shell on tty |
148 | for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL); | 148 | for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL); |
149 | int ttyfd = open(ttynam, O_RDWR); | 149 | int ttyfd = open(ttynam, O_RDWR); |
150 | dup2(ttyfd, STDIN_FILENO); | 150 | dup2(ttyfd, STDIN_FILENO); |
151 | dup2(ttyfd, STDOUT_FILENO); | 151 | dup2(ttyfd, STDOUT_FILENO); |
152 | dup2(ttyfd, STDERR_FILENO); | 152 | dup2(ttyfd, STDERR_FILENO); |
153 | // should be done with tty, so close it | 153 | // should be done with tty, so close it |
154 | close(ttyfd); | 154 | close(ttyfd); |
155 | static struct termios ttmode; | 155 | static struct termios ttmode; |
156 | if ( setsid() < 0 ) | 156 | if ( setsid() < 0 ) |
157 | perror( "failed to set process group" ); | 157 | perror( "failed to set process group" ); |
158 | #if defined (TIOCSCTTY) | 158 | #if defined (TIOCSCTTY) |
159 | // grabbed from APUE by Stevens | 159 | // grabbed from APUE by Stevens |
160 | ioctl(STDIN_FILENO, TIOCSCTTY, 0); | 160 | ioctl(STDIN_FILENO, TIOCSCTTY, 0); |
161 | #endif | 161 | #endif |
162 | tcgetattr( STDIN_FILENO, &ttmode ); | 162 | tcgetattr( STDIN_FILENO, &ttmode ); |
163 | ttmode.c_cc[VINTR] = 3; | 163 | ttmode.c_cc[VINTR] = 3; |
164 | ttmode.c_cc[VERASE] = 8; | 164 | ttmode.c_cc[VERASE] = 8; |
165 | tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); | 165 | tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); |
166 | setenv("TERM","vt100",1); | 166 | if(strlen(getenv("TERM"))<=0) |
167 | setenv("TERM","vt100",1); | ||
167 | setenv("COLORTERM","0",1); | 168 | setenv("COLORTERM","0",1); |
168 | 169 | ||
169 | if (getuid() == 0) { | 170 | if (getuid() == 0) { |
170 | char msg[] = "WARNING: You are running this shell as root!\n"; | 171 | char msg[] = "WARNING: You are running this shell as root!\n"; |
171 | write(ttyfd, msg, sizeof(msg)); | 172 | write(ttyfd, msg, sizeof(msg)); |
172 | } | 173 | } |
173 | 174 | ||
174 | QString ccmd = "-"+QFileInfo(cmd).fileName(); //creates a login shell | 175 | QString ccmd = "-"+QFileInfo(cmd).fileName(); //creates a login shell |
175 | 176 | ||
176 | execl(cmd, ccmd.latin1(), 0); | 177 | execl(cmd, ccmd.latin1(), 0); |
177 | 178 | ||
178 | donePty(); | 179 | donePty(); |
179 | exit(-1); | 180 | exit(-1); |
180 | } | 181 | } |
181 | 182 | ||
182 | // parent - continue as a widget | 183 | // parent - continue as a widget |
183 | QSocketNotifier* sn_r = new QSocketNotifier(fd,QSocketNotifier::Read,this); | 184 | QSocketNotifier* sn_r = new QSocketNotifier(fd,QSocketNotifier::Read,this); |
184 | QSocketNotifier* sn_e = new QSocketNotifier(fd,QSocketNotifier::Exception,this); | 185 | QSocketNotifier* sn_e = new QSocketNotifier(fd,QSocketNotifier::Exception,this); |
185 | connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); | 186 | connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty())); |
186 | connect(sn_e,SIGNAL(activated(int)),this,SLOT(error())); | 187 | connect(sn_e,SIGNAL(activated(int)),this,SLOT(error())); |
187 | 188 | ||
188 | return 0; | 189 | return 0; |
189 | } | 190 | } |
190 | 191 | ||