summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-console/MyPty.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-console/MyPty.cpp') (more/less context) (show 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
@@ -121,89 +121,86 @@ void MyPty::donePty()
delete m_sn_r;
m_sn_e = 0l;
m_sn_r = 0l;
}
m_cpid = 0;
m_fd = -1;
// emit done(status);
}
const char* MyPty::deviceName()
{
return m_ttynam;
}
void MyPty::error()
{
// This is code from the Qt DumbTerminal example
donePty();
}
void MyPty::start() {
- char* cmd = "/bin/sh";
-
- if ( QFile::exists( "/bin/bash" ) ) {
- cmd = "/bin/bash";
- }
-
QStrList lis;
- int r =run(cmd, lis, 0, 0);
+ int r =run(m_cmd.latin1(), lis, 0, 0);
r = r;
}
/*!
start the client program.
*/
int MyPty::run(const char* cmd, QStrList &, const char*, int)
{
// This is code from the Qt DumbTerminal example
m_cpid = fork();
if ( !m_cpid ) {
// child - exec shell on tty
for (int sig = 1; sig < NSIG; sig++) signal(sig,SIG_DFL);
int ttyfd = ::open(m_ttynam, O_RDWR);
dup2(ttyfd, STDIN_FILENO);
dup2(ttyfd, STDOUT_FILENO);
dup2(ttyfd, STDERR_FILENO);
// should be done with tty, so close it
::close(ttyfd);
static struct termios ttmode;
if ( setsid() < 0 )
perror( "failed to set process group" );
#if defined (TIOCSCTTY)
// grabbed from APUE by Stevens
ioctl(STDIN_FILENO, TIOCSCTTY, 0);
#endif
tcgetattr( STDIN_FILENO, &ttmode );
ttmode.c_cc[VINTR] = 3;
ttmode.c_cc[VERASE] = 8;
tcsetattr( STDIN_FILENO, TCSANOW, &ttmode );
setenv("TERM",m_term,1);
setenv("COLORTERM","0",1);
-
+ EnvironmentMap::Iterator it;
+ for (it = m_env.begin(); it != m_env.end(); it++) {
+ setenv(it.key().latin1(), it.data().latin1(), 1);
+ }
if (getuid() == 0) {
char msg[] = "WARNING: You are running this shell as root!\n";
write(ttyfd, msg, sizeof(msg));
}
execl(cmd, cmd, 0);
donePty();
exit(-1);
}
// parent - continue as a widget
delete m_sn_r;
m_sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this);
delete m_sn_e;
m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this);
connect(m_sn_r,SIGNAL(activated(int)),this,SLOT(readPty()));
connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error()));
return 0;
}
int MyPty::openPty()
{
// This is code from the Qt DumbTerminal example
@@ -242,78 +239,88 @@ int MyPty::openPty()
Create an instance.
*/
MyPty::MyPty(const Profile& prof) : m_cpid(0)
{
int term = prof.readNumEntry("Terminal", Profile::VT100 );
switch( term ) {
default:
case Profile::VT100:
case Profile::VT102:
m_term = "vt100";
break;
case Profile::Linux:
m_term = "linux";
break;
case Profile::XTerm:
m_term = "xterm";
break;
}
m_sn_e = 0l;
m_sn_r = 0l;
m_fd = openPty();
ProcCtl* ctl = ProcCtl::self();
Q_UNUSED(ctl);
+ reload(prof);
}
/*!
Destructor.
Note that the related client program is not killed
(yet) when a instance is deleted.
*/
MyPty::~MyPty()
{
donePty();
}
QString MyPty::identifier()const {
return QString::fromLatin1("term");
}
QString MyPty::name()const{
return identifier();
}
bool MyPty::open() {
if (m_fd < 0)
m_fd = openPty();
start();
return true;
}
void MyPty::close() {
donePty();
m_fd = openPty();
}
-void MyPty::reload( const Profile& ) {
-
+void MyPty::reload( const Profile& prof) {
+ m_env.clear();
+ m_cmd = prof.readEntry("Command", "/bin/bash");
+ int envcount = prof.readNumEntry("EnvVars", 0);
+ for (int i=0; i<envcount; i++) {
+ QString name = prof.readEntry("Env_Name_" + QString::number(i), "");
+ QString value = prof.readEntry("Env_Value_" + QString::number(i), "");
+ if (!(name.isEmpty() || value.isEmpty())) {
+ m_env.insert(name, value);
+ }
+ }
}
/*! sends len bytes through the line */
void MyPty::send(const QByteArray& ar)
{
#ifdef VERBOSE_DEBUG
// verbose debug
printf("sending bytes:\n");
for (uint i = 0; i < ar.count(); i++)
printf("%c", ar[i]);
printf("\n");
#endif
::write(m_fd, ar.data(), ar.count());
}
/*! indicates that a block of data is received */
void MyPty::readPty()
{
QByteArray buf(4096);
int len = ::read( m_fd, buf.data(), 4096 );
if (len == -1 || len == 0) {
donePty();