From 54e31640362a7a995dd49f100eee9550d745e58f Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 19 Oct 2011 17:00:58 +0200 Subject: put the NetworkDiscovery code into the src folder of the fbgui. made some test, building a usb stick iso and running it on a maschine. did some bug fixes --- NetworkDiscovery/networkdiscovery.cpp | 156 +++++++++++++++++++++++----------- 1 file changed, 108 insertions(+), 48 deletions(-) (limited to 'NetworkDiscovery/networkdiscovery.cpp') diff --git a/NetworkDiscovery/networkdiscovery.cpp b/NetworkDiscovery/networkdiscovery.cpp index da2cb1d..bac824a 100644 --- a/NetworkDiscovery/networkdiscovery.cpp +++ b/NetworkDiscovery/networkdiscovery.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "networkdiscovery.h" #include "../common/fbgui.h" @@ -63,52 +66,27 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp _dhcpcdArguments.append("-q"); _dhcpcdArguments.append(serverPath); } - /* delete the file at serverPath. this is necessary since in case the application crashes, the file still - * exists which leads to an error. - */ - - if(QFile::exists(serverPath)) { - QFile::remove(serverPath); - } - - if (!_server->listen(serverPath)) { - // emit signal to the gui that a critial error occoured - qDebug() << _tag << "Unable to start server: " - << _server->errorString(); - emit - abortBoot("Unable to start server: " + _server->errorString()); - return; - } - - // check if the path to the customdhcpcd file is correct - QFileInfo fInfo(_pathToDhcpcdExe); - if (!fInfo.exists()) { - qDebug() << _tag - << "could not find customdhcpcd exe. Please check the path to this file."; - emit abortBoot( - "could not find customdhcpcd exe. Please check the path to this file."); - return; - } - - connect(_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection())); - connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun())); - - if (args != NULL && !args->isEmpty()) { + if(QFile::exists(serverPath)){ + QFile::remove(serverPath); + } + if(!_server->listen(serverPath)){ + qDebug() << _tag << "Unable to start server: " << _server->errorString(); + abortBoot("Unable to start server: " + _server->errorString()); + return; + } + QFileInfo fInfo(_pathToDhcpcdExe); + if(!fInfo.exists()){ + qDebug() << _tag << "could not find customdhcpcd exe. Please check the path to this file."; + emit emit emit emit abortBoot("could not find customdhcpcd exe. Please check the path to this file."); + return; + } + connect(_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection())); + connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun())); + if (args != NULL && !args->isEmpty()) { qDebug() << _tag << "added additional args"; _dhcpcdArguments.append(*args); } - - // start the main work: - if (_autoUp) { - getListOfNetworkInterfacesWithAutoUp(); - _timer = new QTimer(this); - connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning())); - _timer->start(1000); - - } else { - getListOfNetworkInterfaces(); - emit readyForRun(); - } + mainWork(); } @@ -125,6 +103,7 @@ void NetworkDiscovery::slotReadyForRun() { emit addInterface(i); } _numberOfProcesses = _ifUpList.size(); + qDebug() << _tag << "number of processes:" << _numberOfProcesses ; runDHCPCD( _ifUpList); } else { qDebug() << _tag << "list is empty. Have not found usable interface."; @@ -269,6 +248,61 @@ QString NetworkDiscovery::readLogFile() { +/* + *TODO: to be bug fixed + *TODO: do it with kill and not QProcess("killall cdhcpcd") + *TODO: still some bugs. if you press tryAgain it can happen that the app stops with the mainscreen. + *TODO: reproducible: start normal with user choice. plug out the cable. press continue. abort screen should appear. + *TODO: press tryAgain. + */ +void NetworkDiscovery::tryAgain() { + // kill all cdhcpcd processes + qDebug() << " kill cdhcpcd processes"; + QProcess * p = new QProcess(this); + p->start("killall cdhcpcd"); + p->waitForFinished(); + qDebug() << _tag << "[tryAgain]" << p->errorString(); + /* + foreach(Q_PID pid , _pidsList) { + if (kill(pid,SIGKILL) <= -1) + qDebug() << _tag << " error: trying to kill process: " << pid << " error: " << strerror(errno); + } + */ + // reset everything + _clients.clear(); + _clientProcessToIfNameMap.clear(); + _ifNameToClient.clear(); + _numberOfProcesses = 0; + _blocked = false; + _ifUpCountdown = 10; + _ifUpList.clear(); + _ifDownList.clear(); + _pidsList.clear(); + _ifcMap.clear(); + + // start again + mainWork(); + + //SIGK + //kill(); +} + + +/**/ +QVariantMap NetworkDiscovery::getInterfaceConfig(QString ifName) { + QList dns; + interfaceconfiguration * ifc = _ifcMap.value(ifName, NULL); + if (ifc != NULL) { + dns.clear(); + dns = ifc->getDnsservers().trimmed().split(" "); + + //ifc->getIpAddress(), ifc->getNetmask(), ifc->getBroadcast(), + //ifc->getGateway(), 0, AF_INET, "/etc/", dns); + } +} + + + /** * ================================================================================ ********************************* Private Methods ******************************** @@ -276,6 +310,22 @@ QString NetworkDiscovery::readLogFile() { **/ +/**/ +void NetworkDiscovery::mainWork() +{ + if (_autoUp) { + getListOfNetworkInterfacesWithAutoUp(); + _timer = new QTimer(this); + connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning())); + _timer->start(1000); + + } else { + getListOfNetworkInterfaces(); + emit readyForRun(); + } +} + + /** * searches for usable interfaces and puts them into a list. @@ -478,6 +528,13 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { +/**/ +bool NetworkDiscovery::checkConnectivityViaTcp() { + return checkConnectivityViaTcp(_serverIp); +} + + + /** * try to open a tcp connection to the server * @@ -567,8 +624,8 @@ void NetworkDiscovery::handleNewInput() { QLocalSocket * client = _clients.value(socket); QString data(client->read(DHCP_MESSAGE_SIZE)); - client->write("ACK", ACK_SIZE); - client->waitForBytesWritten(); + //client->write("ACK", ACK_SIZE); + //client->waitForBytesWritten(); data = data.trimmed(); //qDebug() << _tag << data; QStringList lines = data.split("\n"); @@ -657,6 +714,7 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) { case DHCPCD_LOG: default: + qDebug() << _tag << "default" << msg; break; } break; @@ -704,6 +762,7 @@ void NetworkDiscovery::handleProcessFinished(int exitCode, QProcess* p = qobject_cast (QObject::sender()); QString ifName = _clientProcessToIfNameMap.value(p, "ifName"); + _numberOfProcesses = _numberOfProcesses - 1; if (!_blocked) { //_blocked becomes true, if _userChoice is false and we already found a usable interface if (ifName.compare("ifName") == 0) { qDebug() << _tag << "--- \t [NetworkDiscovery::handleProcessFinished] haven't found process!"; @@ -725,8 +784,8 @@ void NetworkDiscovery::handleProcessFinished(int exitCode, if (client != 0) { handleNewInput(client); } - _numberOfProcesses = _numberOfProcesses - 1; - if (_numberOfProcesses <= 0 && _userChoice) { + //_numberOfProcesses = _numberOfProcesses - 1; && _userChoice + if (_numberOfProcesses <= 0 ) { emit allProcessesFinished(); } } @@ -747,7 +806,8 @@ void NetworkDiscovery::handleProcessFinished(int exitCode, void NetworkDiscovery::handleProcessStarted() { QProcess* p = qobject_cast (QObject::sender()); QString ifName = _clientProcessToIfNameMap.value(p, "ifName"); - qDebug() << _tag << "process started for interface:" << ifName; + qDebug() << _tag << "process started for interface:" << ifName << "with pid:" << p->pid(); + _pidsList.append(p->pid()); } -- cgit v1.2.3-55-g7522