Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/modem.cpp | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp index 5913a22..3bc7d43 100644 --- a/noncore/settings/networksettings/ppp/modem.cpp +++ b/noncore/settings/networksettings/ppp/modem.cpp | |||
@@ -169,9 +169,9 @@ bool Modem::opentty() { | |||
169 | //begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { | 169 | //begin if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { |
170 | close(modemfd); | 170 | close(modemfd); |
171 | device = _pppdata->modemDevice(); | 171 | device = _pppdata->modemDevice(); |
172 | if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { | 172 | if ((modemfd = open(device, O_RDWR|O_NDELAY|O_NOCTTY)) == -1) { |
173 | odebug << "error opening modem device !" << oendl; | 173 | odebug << "error opening modem device !" << oendl; |
174 | errmsg = QObject::tr("Unable to open modem."); | 174 | errmsg = QObject::tr("Unable to open modem."); |
175 | return false; | 175 | return false; |
176 | } | 176 | } |
177 | //bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { | 177 | //bend if((modemfd = Requester::rq->openModem(gpppdata.modemDevice()))<0) { |
@@ -310,11 +310,11 @@ void Modem::startNotifier() { | |||
310 | if(modemfd >= 0) { | 310 | if(modemfd >= 0) { |
311 | if(sn == 0) { | 311 | if(sn == 0) { |
312 | sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this); | 312 | sn = new QSocketNotifier(modemfd, QSocketNotifier::Read, this); |
313 | connect(sn, SIGNAL(activated(int)), SLOT(readtty(int))); | 313 | connect(sn, SIGNAL(activated(int)), SLOT(readtty(int))); |
314 | odebug << "QSocketNotifier started!" << oendl; | 314 | odebug << "QSocketNotifier started!" << oendl; |
315 | } else { | 315 | } else { |
316 | odebug << "QSocketNotifier re-enabled!" << oendl; | 316 | odebug << "QSocketNotifier re-enabled!" << oendl; |
317 | sn->setEnabled(true); | 317 | sn->setEnabled(true); |
318 | } | 318 | } |
319 | } | 319 | } |
320 | } | 320 | } |
@@ -325,9 +325,9 @@ void Modem::stopNotifier() { | |||
325 | sn->setEnabled(false); | 325 | sn->setEnabled(false); |
326 | disconnect(sn); | 326 | disconnect(sn); |
327 | delete sn; | 327 | delete sn; |
328 | sn = 0; | 328 | sn = 0; |
329 | odebug << "QSocketNotifier stopped!" << oendl; | 329 | odebug << "QSocketNotifier stopped!" << oendl; |
330 | } | 330 | } |
331 | } | 331 | } |
332 | 332 | ||
333 | 333 | ||
@@ -341,9 +341,9 @@ bool Modem::writeChar(unsigned char c) { | |||
341 | int s; | 341 | int s; |
342 | do { | 342 | do { |
343 | s = write(modemfd, &c, 1); | 343 | s = write(modemfd, &c, 1); |
344 | if (s < 0) { | 344 | if (s < 0) { |
345 | oerr << "write() in Modem::writeChar failed" << oendl; | 345 | oerr << "write() in Modem::writeChar failed" << oendl; |
346 | return false; | 346 | return false; |
347 | } | 347 | } |
348 | } while(s == 0); | 348 | } while(s == 0); |
349 | 349 | ||
@@ -369,9 +369,9 @@ bool Modem::writeLine(const char *buf) { | |||
369 | while(l) { | 369 | while(l) { |
370 | int wr = write(modemfd, &b[len-l], l); | 370 | int wr = write(modemfd, &b[len-l], l); |
371 | if(wr < 0) { | 371 | if(wr < 0) { |
372 | // TODO do something meaningful with the error code (or ignore it | 372 | // TODO do something meaningful with the error code (or ignore it |
373 | oerr << "write() in Modem::writeLine failed" << oendl; | 373 | oerr << "write() in Modem::writeLine failed" << oendl; |
374 | delete[] b; | 374 | delete[] b; |
375 | return false; | 375 | return false; |
376 | } | 376 | } |
377 | l -= wr; | 377 | l -= wr; |
@@ -478,9 +478,9 @@ QString Modem::parseModemSpeed(const QString &s) { | |||
478 | int tx = -1; | 478 | int tx = -1; |
479 | int i; | 479 | int i; |
480 | QString result; | 480 | QString result; |
481 | 481 | ||
482 | odebug << "Modem reported result string: " << s.latin1() << "" << oendl; | 482 | odebug << "Modem reported result string: " << s.latin1() << "" << oendl; |
483 | 483 | ||
484 | const int RXMAX = 7; | 484 | const int RXMAX = 7; |
485 | const int TXMAX = 2; | 485 | const int TXMAX = 2; |
486 | QRegExp rrx[RXMAX] = { | 486 | QRegExp rrx[RXMAX] = { |
@@ -564,9 +564,9 @@ QString Modem::parseModemSpeed(const QString &s) { | |||
564 | result.setNum(tx); | 564 | result.setNum(tx); |
565 | else | 565 | else |
566 | result.sprintf("%d/%d", rx, tx); | 566 | result.sprintf("%d/%d", rx, tx); |
567 | 567 | ||
568 | odebug << "The parsed result is: " << result.latin1() << "" << oendl; | 568 | odebug << "The parsed result is: " << result.latin1() << "" << oendl; |
569 | 569 | ||
570 | return result; | 570 | return result; |
571 | } | 571 | } |
572 | 572 | ||
@@ -577,9 +577,9 @@ int Modem::lockdevice() { | |||
577 | int fd; | 577 | int fd; |
578 | char newlock[80]=""; // safe | 578 | char newlock[80]=""; // safe |
579 | 579 | ||
580 | if(!_pppdata->modemLockFile()) { | 580 | if(!_pppdata->modemLockFile()) { |
581 | odebug << "The user doesn't want a lockfile." << oendl; | 581 | odebug << "The user doesn't want a lockfile." << oendl; |
582 | return 0; | 582 | return 0; |
583 | } | 583 | } |
584 | 584 | ||
585 | if (modem_is_locked) | 585 | if (modem_is_locked) |
@@ -599,9 +599,9 @@ if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { | |||
599 | if (sz <= 0) | 599 | if (sz <= 0) |
600 | return 1; | 600 | return 1; |
601 | oldlock[sz] = '\0'; | 601 | oldlock[sz] = '\0'; |
602 | 602 | ||
603 | odebug << "Device is locked by: " << oldlock << "" << oendl; | 603 | odebug << "Device is locked by: " << oldlock << "" << oendl; |
604 | 604 | ||
605 | int oldpid; | 605 | int oldpid; |
606 | int match = sscanf(oldlock, "%d", &oldpid); | 606 | int match = sscanf(oldlock, "%d", &oldpid); |
607 | 607 | ||
@@ -612,16 +612,16 @@ if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { | |||
612 | // check if process exists | 612 | // check if process exists |
613 | if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH) | 613 | if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH) |
614 | return 1; | 614 | return 1; |
615 | 615 | ||
616 | odebug << "lockfile is stale" << oendl; | 616 | odebug << "lockfile is stale" << oendl; |
617 | } | 617 | } |
618 | } | 618 | } |
619 | 619 | ||
620 | fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); | 620 | fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); |
621 | if(fd >= 0) { | 621 | if(fd >= 0) { |
622 | sprintf(newlock,"%010d\n", getpid()); | 622 | sprintf(newlock,"%010d\n", getpid()); |
623 | odebug << "Locking Device: " << newlock << "" << oendl; | 623 | odebug << "Locking Device: " << newlock << "" << oendl; |
624 | 624 | ||
625 | write(fd, newlock, strlen(newlock)); | 625 | write(fd, newlock, strlen(newlock)); |
626 | close(fd); | 626 | close(fd); |
627 | modem_is_locked=true; | 627 | modem_is_locked=true; |
@@ -636,9 +636,9 @@ if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { | |||
636 | 636 | ||
637 | // UnLock modem device | 637 | // UnLock modem device |
638 | void Modem::unlockdevice() { | 638 | void Modem::unlockdevice() { |
639 | if (modem_is_locked) { | 639 | if (modem_is_locked) { |
640 | odebug << "UnLocking Modem Device" << oendl; | 640 | odebug << "UnLocking Modem Device" << oendl; |
641 | close(modemfd); | 641 | close(modemfd); |
642 | modemfd = -1; | 642 | modemfd = -1; |
643 | unlink(lockfile); | 643 | unlink(lockfile); |
644 | lockfile[0] = '\0'; | 644 | lockfile[0] = '\0'; |
@@ -658,9 +658,9 @@ int Modem::openLockfile( QString lockfile, int flags) | |||
658 | 658 | ||
659 | lockfile = LOCK_DIR; | 659 | lockfile = LOCK_DIR; |
660 | lockfile += "/LCK.."; | 660 | lockfile += "/LCK.."; |
661 | lockfile += device.right( device.length() - device.findRev("/") -1 ); | 661 | lockfile += device.right( device.length() - device.findRev("/") -1 ); |
662 | odebug << "lockfile >" << lockfile.latin1() << "<" << oendl; | 662 | odebug << "lockfile >" << lockfile.latin1() << "<" << oendl; |
663 | // TODO: | 663 | // TODO: |
664 | // struct stat st; | 664 | // struct stat st; |
665 | // if(stat(lockfile.data(), &st) == -1) { | 665 | // if(stat(lockfile.data(), &st) == -1) { |
666 | // if(errno == EBADF) | 666 | // if(errno == EBADF) |
@@ -670,9 +670,9 @@ int Modem::openLockfile( QString lockfile, int flags) | |||
670 | // if(!S_ISREG(st.st_mode)) | 670 | // if(!S_ISREG(st.st_mode)) |
671 | // return -1; | 671 | // return -1; |
672 | // } | 672 | // } |
673 | if ((fd = open(lockfile, flags, mode)) == -1) { | 673 | if ((fd = open(lockfile, flags, mode)) == -1) { |
674 | odebug << "error opening lockfile!" << oendl; | 674 | odebug << "error opening lockfile!" << oendl; |
675 | lockfile = QString::null; | 675 | lockfile = QString::null; |
676 | fd = open(DEVNULL, O_RDONLY); | 676 | fd = open(DEVNULL, O_RDONLY); |
677 | } else | 677 | } else |
678 | fchown(fd, 0, 0); | 678 | fchown(fd, 0, 0); |
@@ -931,17 +931,17 @@ bool Modem::execpppd(const char *arguments) { | |||
931 | _exit(0); | 931 | _exit(0); |
932 | break; | 932 | break; |
933 | 933 | ||
934 | default: | 934 | default: |
935 | odebug << "In parent: pppd pid " << pppdPid << "\n" << oendl; | 935 | odebug << "In parent: pppd pid " << pppdPid << "\n" << oendl; |
936 | close(modemfd); | 936 | close(modemfd); |
937 | 937 | ||
938 | ::close( m_pppdLOG[1] ); | 938 | ::close( m_pppdLOG[1] ); |
939 | // set it to nonblocking io | 939 | // set it to nonblocking io |
940 | int flag = ::fcntl( m_pppdLOG[0], F_GETFL ); | 940 | int flag = ::fcntl( m_pppdLOG[0], F_GETFL ); |
941 | 941 | ||
942 | if ( !(flag & O_NONBLOCK) ) { | 942 | if ( !(flag & O_NONBLOCK) ) { |
943 | odebug << "Setting nonblocking io" << oendl; | 943 | odebug << "Setting nonblocking io" << oendl; |
944 | flag |= O_NONBLOCK; | 944 | flag |= O_NONBLOCK; |
945 | ::fcntl(m_pppdLOG[0], F_SETFL, flag ); | 945 | ::fcntl(m_pppdLOG[0], F_SETFL, flag ); |
946 | } | 946 | } |
947 | 947 | ||
@@ -958,17 +958,17 @@ bool Modem::execpppd(const char *arguments) { | |||
958 | } | 958 | } |
959 | 959 | ||
960 | 960 | ||
961 | bool Modem::killpppd() { | 961 | bool Modem::killpppd() { |
962 | odebug << "In killpppd and pid is " << pppdPid << "" << oendl; | 962 | odebug << "In killpppd and pid is " << pppdPid << "" << oendl; |
963 | if(pppdPid > 0) { | 963 | if(pppdPid > 0) { |
964 | delete m_modemDebug; | 964 | delete m_modemDebug; |
965 | m_modemDebug = 0; | 965 | m_modemDebug = 0; |
966 | odebug << "In killpppd(): Sending SIGTERM to " << pppdPid << "\n" << oendl; | 966 | odebug << "In killpppd(): Sending SIGTERM to " << pppdPid << "\n" << oendl; |
967 | if(kill(pppdPid, SIGTERM) < 0) { | 967 | if(kill(pppdPid, SIGTERM) < 0) { |
968 | odebug << "Error terminating " << pppdPid << ". Sending SIGKILL\n" << oendl; | 968 | odebug << "Error terminating " << pppdPid << ". Sending SIGKILL\n" << oendl; |
969 | if(kill(pppdPid, SIGKILL) < 0) { | 969 | if(kill(pppdPid, SIGKILL) < 0) { |
970 | odebug << "Error killing " << pppdPid << "\n" << oendl; | 970 | odebug << "Error killing " << pppdPid << "\n" << oendl; |
971 | return false; | 971 | return false; |
972 | } | 972 | } |
973 | } | 973 | } |
974 | } | 974 | } |
@@ -1003,13 +1003,13 @@ void Modem::parseargs(char* buf, char** args) { | |||
1003 | } | 1003 | } |
1004 | 1004 | ||
1005 | if (!quotes) | 1005 | if (!quotes) |
1006 | while ((*buf != '\0') && (*buf != '\n') && | 1006 | while ((*buf != '\0') && (*buf != '\n') && |
1007 | (*buf != '\t') && (*buf != ' ')) | 1007 | (*buf != '\t') && (*buf != ' ')) |
1008 | buf++; | 1008 | buf++; |
1009 | else { | 1009 | else { |
1010 | while ((*buf != '\0') && (*buf != quotes)) | 1010 | while ((*buf != '\0') && (*buf != quotes)) |
1011 | buf++; | 1011 | buf++; |
1012 | *buf++ = '\0'; | 1012 | *buf++ = '\0'; |
1013 | } | 1013 | } |
1014 | } | 1014 | } |
1015 | 1015 | ||
@@ -1039,9 +1039,9 @@ int Modem::pppdExitStatus() | |||
1039 | int Modem::openResolv(int flags) | 1039 | int Modem::openResolv(int flags) |
1040 | { | 1040 | { |
1041 | int fd; | 1041 | int fd; |
1042 | if ((fd = open(_PATH_RESCONF, flags)) == -1) { | 1042 | if ((fd = open(_PATH_RESCONF, flags)) == -1) { |
1043 | odebug << "error opening resolv.conf!" << oendl; | 1043 | odebug << "error opening resolv.conf!" << oendl; |
1044 | fd = open(DEVNULL, O_RDONLY); | 1044 | fd = open(DEVNULL, O_RDONLY); |
1045 | } | 1045 | } |
1046 | return fd; | 1046 | return fd; |
1047 | } | 1047 | } |
@@ -1060,9 +1060,9 @@ void Modem::setPPPDevice( const QString& dev ) { | |||
1060 | pid_t Modem::pppPID()const { | 1060 | pid_t Modem::pppPID()const { |
1061 | return pppdPid; | 1061 | return pppdPid; |
1062 | } | 1062 | } |
1063 | void Modem::setPPPDPid( pid_t pid ) { | 1063 | void Modem::setPPPDPid( pid_t pid ) { |
1064 | odebug << "Modem setting pid" << oendl; | 1064 | odebug << "Modem setting pid" << oendl; |
1065 | _pppdExitStatus = -1; | 1065 | _pppdExitStatus = -1; |
1066 | pppdPid = pid; | 1066 | pppdPid = pid; |
1067 | modemfd = -1; | 1067 | modemfd = -1; |
1068 | } | 1068 | } |