Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/modem.cpp | 85 |
1 files changed, 71 insertions, 14 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp index d23fee4..3dbc8c3 100644 --- a/noncore/settings/networksettings/ppp/modem.cpp +++ b/noncore/settings/networksettings/ppp/modem.cpp @@ -53,7 +53,4 @@ #include "pppdata.h" -//#include <klocale.h> -#define i18n QObject::tr #define qError qDebug -//#include <kdebug.h> -//#include <config.h> + @@ -101,3 +98,3 @@ Modem::Modem( PPPData* pd ) pppdPid = -1; - sn = 0L; + sn = m_modemDebug = 0L; data_mode = false; @@ -171,3 +168,3 @@ bool Modem::opentty() { qDebug("error opening modem device !"); - errmsg = i18n("Unable to open modem."); + errmsg = QObject::tr("Unable to open modem."); return false; @@ -180,3 +177,3 @@ bool Modem::opentty() { if(ioctl(modemfd, TIOCMGET, &flags) == -1) { - errmsg = i18n("Unable to detect state of CD line."); + errmsg = QObject::tr("Unable to detect state of CD line."); ::close(modemfd); @@ -186,3 +183,3 @@ bool Modem::opentty() { if ((flags&TIOCM_CD) == 0) { - errmsg = i18n("The modem is not ready."); + errmsg = QObject::tr("The modem is not ready."); ::close(modemfd); @@ -202,3 +199,3 @@ bool Modem::opentty() { if(tcgetattr(modemfd, &tty) < 0){ - errmsg = i18n("The modem is busy."); + errmsg = QObject::tr("The modem is busy."); ::close(modemfd); @@ -247,3 +244,3 @@ bool Modem::opentty() { if(tcsetattr(modemfd, TCSANOW, &tty) < 0){ - errmsg = i18n("The modem is busy."); + errmsg = QObject::tr("The modem is busy."); ::close(modemfd); @@ -253,3 +250,3 @@ bool Modem::opentty() { - errmsg = i18n("Modem Ready."); + errmsg = QObject::tr("Modem Ready."); return true; @@ -265,3 +262,3 @@ bool Modem::closetty() { if(tcsetattr(modemfd, TCSANOW, &initial_tty) < 0){ - errmsg = i18n("Can't restore tty settings: tcsetattr()\n"); + errmsg = QObject::tr("Can't restore tty settings: tcsetattr()\n"); ::close(modemfd); @@ -415,3 +412,3 @@ bool Modem::hangup() { modemfd = -1; - errmsg = i18n("The modem does not respond."); + errmsg = QObject::tr("The modem does not respond."); return false; @@ -557,3 +554,3 @@ QString Modem::parseModemSpeed(const QString &s) { if(rx == -1 && tx == -1) - result = i18n("Unknown speed"); + result = QObject::tr("Unknown speed"); else if(tx == -1) @@ -879,2 +876,4 @@ bool Modem::execpppd(const char *arguments) { + (void)::pipe( m_pppdLOG ); + switch(pppdPid = fork()) @@ -883,2 +882,4 @@ bool Modem::execpppd(const char *arguments) { fprintf(stderr,"In parent: fork() failed\n"); + ::close( m_pppdLOG[0] ); + ::close( m_pppdLOG[1] ); return false; @@ -904,2 +905,5 @@ bool Modem::execpppd(const char *arguments) { + ::close( m_pppdLOG[0] ); + ::setenv( "LANG", "C", 1 ); // overwrite + dup2(m_pppdLOG[1], 11 ); // for logfd 11 dup2(modemfd, 0); @@ -907,2 +911,3 @@ bool Modem::execpppd(const char *arguments) { + switch (checkForInterface()) { @@ -926,3 +931,20 @@ bool Modem::execpppd(const char *arguments) { close(modemfd); + + ::close( m_pppdLOG[1] ); + // set it to nonblocking io + int flag = ::fcntl( m_pppdLOG[0], F_GETFL ); + + if ( !(flag & O_NONBLOCK) ) { + qDebug("Setting nonblocking io"); + flag |= O_NONBLOCK; + ::fcntl(m_pppdLOG[0], F_SETFL, flag ); + } + + delete m_modemDebug; + m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this ); + connect(m_modemDebug, SIGNAL(activated(int) ), + this, SLOT(slotModemDebug(int) ) ); + modemfd = -1; + m_pppdDev = QString::fromLatin1("ppp0"); return true; @@ -934,3 +956,6 @@ bool Modem::execpppd(const char *arguments) { bool Modem::killpppd() { + qDebug("In killpppd and pid is %d", pppdPid ); if(pppdPid > 0) { + delete m_modemDebug; + m_modemDebug = 0; qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid); @@ -1023 +1048,33 @@ bool Modem::setHostname(const QString & name) +QString Modem::pppDevice()const { + return m_pppdDev; +} +void Modem::setPPPDevice( const QString& dev ) { + m_pppdDev = dev; +} +pid_t Modem::pppPID()const { + return pppdPid; +} +void Modem::setPPPDPid( pid_t pid ) { + qDebug("Modem setting pid"); + _pppdExitStatus = -1; + pppdPid = pid; + modemfd = -1; +} +void Modem::slotModemDebug(int fd) { + char buf[2049]; + int len; + + // read in pppd data look for Using interface + // then read the interface + // we limit to 10 device now 0-9 + if((len = ::read(fd, buf, 2048)) > 0) { + buf[len+1] = '\0'; + char *found; + if ( (found = ::strstr(buf, "Using interface ") ) ) { + found += 16; + m_pppdDev = QString::fromLatin1(found, 5 ); + m_pppdDev = m_pppdDev.simplifyWhiteSpace(); + } + } +} |