From a7e015198a8c5ad3b6e144a9032b059086253e00 Mon Sep 17 00:00:00 2001 From: kergoth Date: Sat, 09 Aug 2003 17:14:54 +0000 Subject: Merge from BRANCH_1_0 --- (limited to 'noncore/settings/networksettings/ppp/modem.cpp') 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 @@ -51,11 +51,8 @@ #include "auth.h" #include "modem.h" #include "pppdata.h" -//#include -#define i18n QObject::tr #define qError qDebug -//#include -//#include + #define MY_ASSERT(x) if (!(x)) { \ qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \ @@ -99,7 +96,7 @@ Modem::Modem( PPPData* pd ) modemfd = -1; _pppdExitStatus = -1; pppdPid = -1; - sn = 0L; + sn = m_modemDebug = 0L; data_mode = false; modem_is_locked = false; lockfile[0] = '\0'; @@ -169,7 +166,7 @@ bool Modem::opentty() { device = _pppdata->modemDevice(); if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { qDebug("error opening modem device !"); - errmsg = i18n("Unable to open modem."); + errmsg = QObject::tr("Unable to open modem."); return false; } //bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { @@ -178,13 +175,13 @@ bool Modem::opentty() { #if 0 if(_pppdata->UseCDLine()) { 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); modemfd = -1; return false; } if ((flags&TIOCM_CD) == 0) { - errmsg = i18n("The modem is not ready."); + errmsg = QObject::tr("The modem is not ready."); ::close(modemfd); modemfd = -1; return false; @@ -200,7 +197,7 @@ bool Modem::opentty() { tcsendbreak(modemfd, 0); sleep(1); if(tcgetattr(modemfd, &tty) < 0){ - errmsg = i18n("The modem is busy."); + errmsg = QObject::tr("The modem is busy."); ::close(modemfd); modemfd = -1; return false; @@ -245,13 +242,13 @@ bool Modem::opentty() { tcdrain(modemfd); if(tcsetattr(modemfd, TCSANOW, &tty) < 0){ - errmsg = i18n("The modem is busy."); + errmsg = QObject::tr("The modem is busy."); ::close(modemfd); modemfd=-1; return false; } - errmsg = i18n("Modem Ready."); + errmsg = QObject::tr("Modem Ready."); return true; } @@ -263,7 +260,7 @@ bool Modem::closetty() { tcflush(modemfd, TCIOFLUSH); 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); modemfd = -1; return false; @@ -413,7 +410,7 @@ bool Modem::hangup() { closetty(); close(modemfd); modemfd = -1; - errmsg = i18n("The modem does not respond."); + errmsg = QObject::tr("The modem does not respond."); return false; } @@ -555,7 +552,7 @@ QString Modem::parseModemSpeed(const QString &s) { } if(rx == -1 && tx == -1) - result = i18n("Unknown speed"); + result = QObject::tr("Unknown speed"); else if(tx == -1) result.setNum(rx); else if(rx == -1) // should not happen @@ -877,10 +874,14 @@ bool Modem::execpppd(const char *arguments) { _pppdExitStatus = -1; + (void)::pipe( m_pppdLOG ); + switch(pppdPid = fork()) { case -1: fprintf(stderr,"In parent: fork() failed\n"); + ::close( m_pppdLOG[0] ); + ::close( m_pppdLOG[1] ); return false; break; @@ -902,9 +903,13 @@ bool Modem::execpppd(const char *arguments) { if(tcsetpgrp(modemfd, pgrpid)<0) fprintf(stderr, "tcsetpgrp() failed.\n"); + ::close( m_pppdLOG[0] ); + ::setenv( "LANG", "C", 1 ); // overwrite + dup2(m_pppdLOG[1], 11 ); // for logfd 11 dup2(modemfd, 0); dup2(modemfd, 1); + switch (checkForInterface()) { case 1: fprintf(stderr, "Cannot determine if kernel supports ppp.\n"); @@ -924,7 +929,24 @@ bool Modem::execpppd(const char *arguments) { default: qDebug("In parent: pppd pid %d\n",pppdPid); 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; break; } @@ -932,7 +954,10 @@ 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); if(kill(pppdPid, SIGTERM) < 0) { qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid); @@ -1021,3 +1046,35 @@ bool Modem::setHostname(const QString & name) return sethostname(name, name.length()) == 0; } +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(); + } + } +} -- cgit v0.9.0.2