summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/modem.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index 3dbc8c3..f3f2639 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -52,13 +52,13 @@
52#include "modem.h" 52#include "modem.h"
53#include "pppdata.h" 53#include "pppdata.h"
54#define qError qDebug 54#define qError qDebug
55 55
56 56
57#define MY_ASSERT(x) if (!(x)) { \ 57#define MY_ASSERT(x) if (!(x)) { \
58 qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \ 58 ofatal << "ASSERT: \"" << #x << "\" in " << __FILE__ << " (" << __LINE__ << ")\n" << oendl; \
59 exit(1); } 59 exit(1); }
60 60
61 61
62static sigjmp_buf jmp_buffer; 62static sigjmp_buf jmp_buffer;
63 63
64//Modem *Modem::modem = 0; 64//Modem *Modem::modem = 0;
@@ -162,13 +162,13 @@ bool Modem::opentty() {
162 // int flags; 162 // int flags;
163 163
164//begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { 164//begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
165 close(modemfd); 165 close(modemfd);
166 device = _pppdata->modemDevice(); 166 device = _pppdata->modemDevice();
167 if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { 167 if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) {
168 qDebug("error opening modem device !"); 168 odebug << "error opening modem device !" << oendl;
169 errmsg = QObject::tr("Unable to open modem."); 169 errmsg = QObject::tr("Unable to open modem.");
170 return false; 170 return false;
171 } 171 }
172//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { 172//bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) {
173//} 173//}
174 174
@@ -303,28 +303,28 @@ void Modem::stop() {
303 303
304void Modem::startNotifier() { 304void Modem::startNotifier() {
305 if(modemfd >= 0) { 305 if(modemfd >= 0) {
306 if(sn == 0) { 306 if(sn == 0) {
307 sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this); 307 sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this);
308 connect(sn, SIGNAL(activated(int)), SLOT(readtty(int))); 308 connect(sn, SIGNAL(activated(int)), SLOT(readtty(int)));
309 qDebug("QSocketNotifier started!"); 309 odebug << "QSocketNotifier started!" << oendl;
310 } else { 310 } else {
311 qDebug("QSocketNotifier re-enabled!"); 311 odebug << "QSocketNotifier re-enabled!" << oendl;
312 sn->setEnabled(true); 312 sn->setEnabled(true);
313 } 313 }
314 } 314 }
315} 315}
316 316
317 317
318void Modem::stopNotifier() { 318void Modem::stopNotifier() {
319 if(sn != 0) { 319 if(sn != 0) {
320 sn->setEnabled(false); 320 sn->setEnabled(false);
321 disconnect(sn); 321 disconnect(sn);
322 delete sn; 322 delete sn;
323 sn = 0; 323 sn = 0;
324 qDebug( "QSocketNotifier stopped!" ); 324 odebug << "QSocketNotifier stopped!" << oendl;
325 } 325 }
326} 326}
327 327
328 328
329void Modem::flush() { 329void Modem::flush() {
330 char c; 330 char c;
@@ -334,13 +334,13 @@ void Modem::flush() {
334 334
335bool Modem::writeChar(unsigned char c) { 335bool Modem::writeChar(unsigned char c) {
336 int s; 336 int s;
337 do { 337 do {
338 s = write(modemfd, &c, 1); 338 s = write(modemfd, &c, 1);
339 if (s < 0) { 339 if (s < 0) {
340 qError( "write() in Modem::writeChar failed" ); 340 oerr << "write() in Modem::writeChar failed" << oendl;
341 return false; 341 return false;
342 } 342 }
343 } while(s == 0); 343 } while(s == 0);
344 344
345 return true; 345 return true;
346} 346}
@@ -362,13 +362,13 @@ bool Modem::writeLine(const char *buf) {
362 } 362 }
363 int l = len; 363 int l = len;
364 while(l) { 364 while(l) {
365 int wr = write(modemfd, &b[len-l], l); 365 int wr = write(modemfd, &b[len-l], l);
366 if(wr < 0) { 366 if(wr < 0) {
367 // TODO do something meaningful with the error code (or ignore it 367 // TODO do something meaningful with the error code (or ignore it
368 qError( "write() in Modem::writeLine failed" ); 368 oerr << "write() in Modem::writeLine failed" << oendl;
369 delete[] b; 369 delete[] b;
370 return false; 370 return false;
371 } 371 }
372 l -= wr; 372 l -= wr;
373 } 373 }
374 delete[] b; 374 delete[] b;
@@ -471,13 +471,13 @@ QString Modem::parseModemSpeed(const QString &s) {
471 // this is a small (and bad) parser for modem speeds 471 // this is a small (and bad) parser for modem speeds
472 int rx = -1; 472 int rx = -1;
473 int tx = -1; 473 int tx = -1;
474 int i; 474 int i;
475 QString result; 475 QString result;
476 476
477 qDebug( "Modem reported result string: %s", s.latin1()); 477 odebug << "Modem reported result string: " << s.latin1() << "" << oendl;
478 478
479 const int RXMAX = 7; 479 const int RXMAX = 7;
480 const int TXMAX = 2; 480 const int TXMAX = 2;
481 QRegExp rrx[RXMAX] = { 481 QRegExp rrx[RXMAX] = {
482 QRegExp("[0-9]+[:/ ]RX", false), 482 QRegExp("[0-9]+[:/ ]RX", false),
483 QRegExp("[0-9]+RX", false), 483 QRegExp("[0-9]+RX", false),
@@ -557,26 +557,26 @@ QString Modem::parseModemSpeed(const QString &s) {
557 result.setNum(rx); 557 result.setNum(rx);
558 else if(rx == -1) // should not happen 558 else if(rx == -1) // should not happen
559 result.setNum(tx); 559 result.setNum(tx);
560 else 560 else
561 result.sprintf("%d/%d", rx, tx); 561 result.sprintf("%d/%d", rx, tx);
562 562
563 qDebug( "The parsed result is: %s", result.latin1()); 563 odebug << "The parsed result is: " << result.latin1() << "" << oendl;
564 564
565 return result; 565 return result;
566} 566}
567 567
568 568
569// Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if 569// Lock modem device. Returns 0 on success 1 if the modem is locked and -1 if
570// a lock file can't be created ( permission problem ) 570// a lock file can't be created ( permission problem )
571int Modem::lockdevice() { 571int Modem::lockdevice() {
572 int fd; 572 int fd;
573 char newlock[80]=""; // safe 573 char newlock[80]=""; // safe
574 574
575 if(!_pppdata->modemLockFile()) { 575 if(!_pppdata->modemLockFile()) {
576 qDebug("The user doesn't want a lockfile."); 576 odebug << "The user doesn't want a lockfile." << oendl;
577 return 0; 577 return 0;
578 } 578 }
579 579
580 if (modem_is_locked) 580 if (modem_is_locked)
581 return 1; 581 return 1;
582 582
@@ -592,33 +592,33 @@ if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) {
592 int sz = read(fd, &oldlock, 32); 592 int sz = read(fd, &oldlock, 32);
593 close (fd); 593 close (fd);
594 if (sz <= 0) 594 if (sz <= 0)
595 return 1; 595 return 1;
596 oldlock[sz] = '\0'; 596 oldlock[sz] = '\0';
597 597
598 qDebug( "Device is locked by: %s", oldlock); 598 odebug << "Device is locked by: " << oldlock << "" << oendl;
599 599
600 int oldpid; 600 int oldpid;
601 int match = sscanf(oldlock, "%d", &oldpid); 601 int match = sscanf(oldlock, "%d", &oldpid);
602 602
603 // found a pid in lockfile ? 603 // found a pid in lockfile ?
604 if (match < 1 || oldpid <= 0) 604 if (match < 1 || oldpid <= 0)
605 return 1; 605 return 1;
606 606
607 // check if process exists 607 // check if process exists
608 if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH) 608 if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH)
609 return 1; 609 return 1;
610 610
611 qDebug( "lockfile is stale" ); 611 odebug << "lockfile is stale" << oendl;
612 } 612 }
613 } 613 }
614 614
615 fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); 615 fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT);
616 if(fd >= 0) { 616 if(fd >= 0) {
617 sprintf(newlock,"%010d\n", getpid()); 617 sprintf(newlock,"%010d\n", getpid());
618 qDebug("Locking Device: %s", newlock); 618 odebug << "Locking Device: " << newlock << "" << oendl;
619 619
620 write(fd, newlock, strlen(newlock)); 620 write(fd, newlock, strlen(newlock));
621 close(fd); 621 close(fd);
622 modem_is_locked=true; 622 modem_is_locked=true;
623 623
624 return 0; 624 return 0;
@@ -629,13 +629,13 @@ if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) {
629} 629}
630 630
631 631
632// UnLock modem device 632// UnLock modem device
633void Modem::unlockdevice() { 633void Modem::unlockdevice() {
634 if (modem_is_locked) { 634 if (modem_is_locked) {
635 qDebug( "UnLocking Modem Device" ); 635 odebug << "UnLocking Modem Device" << oendl;
636 close(modemfd); 636 close(modemfd);
637 modemfd = -1; 637 modemfd = -1;
638 unlink(lockfile); 638 unlink(lockfile);
639 lockfile[0] = '\0'; 639 lockfile[0] = '\0';
640 modem_is_locked=false; 640 modem_is_locked=false;
641 } 641 }
@@ -651,25 +651,25 @@ int Modem::openLockfile( QString lockfile, int flags)
651 else 651 else
652 mode = 0; 652 mode = 0;
653 653
654 lockfile = LOCK_DIR; 654 lockfile = LOCK_DIR;
655 lockfile += "/LCK.."; 655 lockfile += "/LCK..";
656 lockfile += device.right( device.length() - device.findRev("/") -1 ); 656 lockfile += device.right( device.length() - device.findRev("/") -1 );
657 qDebug("lockfile >%s<",lockfile.latin1()); 657 odebug << "lockfile >" << lockfile.latin1() << "<" << oendl;
658 // TODO: 658 // TODO:
659 // struct stat st; 659 // struct stat st;
660 // if(stat(lockfile.data(), &st) == -1) { 660 // if(stat(lockfile.data(), &st) == -1) {
661 // if(errno == EBADF) 661 // if(errno == EBADF)
662 // return -1; 662 // return -1;
663 // } else { 663 // } else {
664 // // make sure that this is a regular file 664 // // make sure that this is a regular file
665 // if(!S_ISREG(st.st_mode)) 665 // if(!S_ISREG(st.st_mode))
666 // return -1; 666 // return -1;
667 // } 667 // }
668 if ((fd = open(lockfile, flags, mode)) == -1) { 668 if ((fd = open(lockfile, flags, mode)) == -1) {
669 qDebug("error opening lockfile!"); 669 odebug << "error opening lockfile!" << oendl;
670 lockfile = QString::null; 670 lockfile = QString::null;
671 fd = open(DEVNULL, O_RDONLY); 671 fd = open(DEVNULL, O_RDONLY);
672 } else 672 } else
673 fchown(fd, 0, 0); 673 fchown(fd, 0, 0);
674 return fd; 674 return fd;
675} 675}
@@ -924,21 +924,21 @@ bool Modem::execpppd(const char *arguments) {
924 924
925 execve(pppdPath(), args, 0L); 925 execve(pppdPath(), args, 0L);
926 _exit(0); 926 _exit(0);
927 break; 927 break;
928 928
929 default: 929 default:
930 qDebug("In parent: pppd pid %d\n",pppdPid); 930 odebug << "In parent: pppd pid " << pppdPid << "\n" << oendl;
931 close(modemfd); 931 close(modemfd);
932 932
933 ::close( m_pppdLOG[1] ); 933 ::close( m_pppdLOG[1] );
934 // set it to nonblocking io 934 // set it to nonblocking io
935 int flag = ::fcntl( m_pppdLOG[0], F_GETFL ); 935 int flag = ::fcntl( m_pppdLOG[0], F_GETFL );
936 936
937 if ( !(flag & O_NONBLOCK) ) { 937 if ( !(flag & O_NONBLOCK) ) {
938 qDebug("Setting nonblocking io"); 938 odebug << "Setting nonblocking io" << oendl;
939 flag |= O_NONBLOCK; 939 flag |= O_NONBLOCK;
940 ::fcntl(m_pppdLOG[0], F_SETFL, flag ); 940 ::fcntl(m_pppdLOG[0], F_SETFL, flag );
941 } 941 }
942 942
943 delete m_modemDebug; 943 delete m_modemDebug;
944 m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this ); 944 m_modemDebug = new QSocketNotifier(m_pppdLOG[0], QSocketNotifier::Read, this );
@@ -951,21 +951,21 @@ bool Modem::execpppd(const char *arguments) {
951 break; 951 break;
952 } 952 }
953} 953}
954 954
955 955
956bool Modem::killpppd() { 956bool Modem::killpppd() {
957 qDebug("In killpppd and pid is %d", pppdPid ); 957 odebug << "In killpppd and pid is " << pppdPid << "" << oendl;
958 if(pppdPid > 0) { 958 if(pppdPid > 0) {
959 delete m_modemDebug; 959 delete m_modemDebug;
960 m_modemDebug = 0; 960 m_modemDebug = 0;
961 qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid); 961 odebug << "In killpppd(): Sending SIGTERM to " << pppdPid << "\n" << oendl;
962 if(kill(pppdPid, SIGTERM) < 0) { 962 if(kill(pppdPid, SIGTERM) < 0) {
963 qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid); 963 odebug << "Error terminating " << pppdPid << ". Sending SIGKILL\n" << oendl;
964 if(kill(pppdPid, SIGKILL) < 0) { 964 if(kill(pppdPid, SIGKILL) < 0) {
965 qDebug("Error killing %d\n", pppdPid); 965 odebug << "Error killing " << pppdPid << "\n" << oendl;
966 return false; 966 return false;
967 } 967 }
968 } 968 }
969 } 969 }
970 return true; 970 return true;
971} 971}
@@ -1032,13 +1032,13 @@ int Modem::pppdExitStatus()
1032} 1032}
1033 1033
1034int Modem::openResolv(int flags) 1034int Modem::openResolv(int flags)
1035{ 1035{
1036 int fd; 1036 int fd;
1037 if ((fd = open(_PATH_RESCONF, flags)) == -1) { 1037 if ((fd = open(_PATH_RESCONF, flags)) == -1) {
1038 qDebug("error opening resolv.conf!"); 1038 odebug << "error opening resolv.conf!" << oendl;
1039 fd = open(DEVNULL, O_RDONLY); 1039 fd = open(DEVNULL, O_RDONLY);
1040 } 1040 }
1041 return fd; 1041 return fd;
1042} 1042}
1043 1043
1044bool Modem::setHostname(const QString & name) 1044bool Modem::setHostname(const QString & name)
@@ -1053,13 +1053,13 @@ void Modem::setPPPDevice( const QString& dev ) {
1053 m_pppdDev = dev; 1053 m_pppdDev = dev;
1054} 1054}
1055pid_t Modem::pppPID()const { 1055pid_t Modem::pppPID()const {
1056 return pppdPid; 1056 return pppdPid;
1057} 1057}
1058void Modem::setPPPDPid( pid_t pid ) { 1058void Modem::setPPPDPid( pid_t pid ) {
1059 qDebug("Modem setting pid"); 1059 odebug << "Modem setting pid" << oendl;
1060 _pppdExitStatus = -1; 1060 _pppdExitStatus = -1;
1061 pppdPid = pid; 1061 pppdPid = pid;
1062 modemfd = -1; 1062 modemfd = -1;
1063} 1063}
1064void Modem::slotModemDebug(int fd) { 1064void Modem::slotModemDebug(int fd) {
1065 char buf[2049]; 1065 char buf[2049];