From 34e522bcad11b1264a92e46379991fb4d344f1d1 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 30 Aug 2011 15:03:25 +0200 Subject: added check for file existens. renamed the dhcpcd bin to customdhcpcd. temporal solution for the message loss problem => added a sleep(1) function after every send operation. this makes the programm a bit slower but it solves the problem, we now receive every message (issue 339) --- workspace/LogReceiver/LogReceiver | Bin 113415 -> 117864 bytes workspace/LogReceiver/logreceiver.cpp | 49 ++++++++++++++++++++++++++------ workspace/LogReceiver/logreceiver.h | 6 +++- workspace/customdhcpcd/src/Makefile | 2 +- workspace/customdhcpcd/src/customdhcpcd | Bin 0 -> 173204 bytes workspace/customdhcpcd/src/dhcpcd.c | 2 +- workspace/customdhcpcd/src/logwriter.c | 1 + 7 files changed, 49 insertions(+), 11 deletions(-) create mode 100755 workspace/customdhcpcd/src/customdhcpcd diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver index 7fee3c5..a2450ce 100755 Binary files a/workspace/LogReceiver/LogReceiver and b/workspace/LogReceiver/LogReceiver differ diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp index 127d69e..9f73862 100644 --- a/workspace/LogReceiver/logreceiver.cpp +++ b/workspace/LogReceiver/logreceiver.cpp @@ -39,14 +39,23 @@ void LogReceiver::initAndRun(QString serverPath, QString pathToExe, close(); */ // emit signal to the gui that a critial error occoured - qDebug() << "--- \t [LogReceiver::initAndRun] Unable to start server:" + QString errorInfo("Unable to start server: "); + qDebug() << "--- \t [LogReceiver::initAndRun] " + errorInfo << server->errorString(); + emit abortBoot(errorInfo + server->errorString()); return; } connect(server, SIGNAL(newConnection()), this, SLOT(handleNewConnection())); pathToDhcpcdExe = pathToExe; + // check if the path to the customdhcpcd file is correct + QFileInfo fInfo(pathToDhcpcdExe); + if (!fInfo.exists()) { + qDebug() << "couldn't find customdhcpcd exe. Please check the path to this file."; + emit abortBoot("couldn't find customdhcpcd exe. Please check the path to this file."); + return; + } if (args != NULL && !args->isEmpty()) { qDebug() << "--- \t [LogReceiver::initAndRun] added additional args"; @@ -250,23 +259,46 @@ void LogReceiver::checkInternetConnectionViaTCP(QString ifName) { void LogReceiver::handleNewConnection() { qDebug() << "New Connection arrived"; - QLocalSocket * client = server ->nextPendingConnection(); + /*QLocalSocket **/ client = server ->nextPendingConnection(); clients.insert(client, client); - connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater())); + connect(client, SIGNAL(disconnected()), this, SLOT(handleClientDisconnect())); connect(client, SIGNAL(readyRead()), this, SLOT(handleNewInput())); } +void LogReceiver::handleClientDisconnect() { + QLocalSocket* socket = qobject_cast (QObject::sender()); + + QLocalSocket * client = clients.value(socket); + + qDebug() << "disconnect client"; + handleNewInput(client); + client->deleteLater(); +} + +void LogReceiver::handleNewInput(QLocalSocket * client) { + QString data(client->readAll()); + + data = data.trimmed(); + qDebug() << data; + QStringList lines = data.split("\n"); + + for (int i = 0; i < lines.length(); i++) { + handleNewInputLine(lines.at(i)); + } +} + void LogReceiver::handleNewInput() { - QObject* sender = const_cast (QObject::sender()); - QLocalSocket* socket = static_cast (sender); + //QObject* sender = const_cast (QObject::sender()); + //QLocalSocket* socket = static_cast (sender); + QLocalSocket* socket = qobject_cast(QObject::sender()); QLocalSocket * client = clients.value(socket); QString data(client->readAll()); data = data.trimmed(); - + qDebug() << data; QStringList lines = data.split("\n"); for (int i=0; i < lines.length(); i++) { @@ -283,7 +315,7 @@ void LogReceiver::handleNewInputLine(QString data) { QString msg = logMsg.section(";", 3, 3); int st = s_state.trimmed().toInt(); int sst = s_subState.trimmed().toInt(); - qDebug() << logMsg; + //qDebug() << logMsg; switch (st) { case LOG_INFO: switch (sst) { @@ -320,7 +352,7 @@ void LogReceiver::handleNewInputLine(QString data) { emit changeProgressBarValue(interface, 80); break; case DHCPCD_EXIT: - emit changeProgressBarValue(interface, 100); + //emit changeProgressBarValue(interface, 100); break; case DHCPCD_LOG: @@ -353,6 +385,7 @@ void LogReceiver::handleProcessFinished(int exitCode, else { qDebug() << "process normal exit"; qDebug() << "check internet connction"; + emit changeProgressBarValue(ifName, 100); emit updateStatusLabel(ifName, "check connectivity"); //checkInternetConnection(ifName); checkInternetConnectionViaTCP(ifName); diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h index 6611d15..6b32aa8 100644 --- a/workspace/LogReceiver/logreceiver.h +++ b/workspace/LogReceiver/logreceiver.h @@ -16,7 +16,7 @@ class LogReceiver: public QObject { Q_OBJECT #define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default" -#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/workspace/customdhcpcd/src/dhcpcd" +#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/workspace/customdhcpcd/src/customdhcpcd" public: LogReceiver(); @@ -32,6 +32,7 @@ private slots: void handleNewInputLine(QString data); void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); void handleProcessStarted(); + void handleClientDisconnect(); signals: void addNewInterface(QString ifName); @@ -47,6 +48,7 @@ private: //QMap interfacesMap; //QMap indexToIfaceNameMap; QMap clients; + QLocalSocket * client; QMap clientProcessToIfNameMap; QString pathToDhcpcdExe; QStringList dhcpcdArguments; @@ -54,6 +56,8 @@ private: QNetworkAccessManager *accessManager; int numberOfProcesses; + void handleNewInput(QLocalSocket * client); + void runDHCPCD(QList &interfaces); void runDHCPCD(QString interface); QListcheckCarrierState(QList &interfaces); diff --git a/workspace/customdhcpcd/src/Makefile b/workspace/customdhcpcd/src/Makefile index 13d9f28..7f90db4 100644 --- a/workspace/customdhcpcd/src/Makefile +++ b/workspace/customdhcpcd/src/Makefile @@ -2,7 +2,7 @@ # Our mk stubs also work with GNU make. # Copyright 2008 Roy Marples -PROG= dhcpcd +PROG= customdhcpcd SRCS= arp.c client.c common.c configure.c dhcp.c dhcpcd.c duid.c \ info.c interface.c ipv4ll.c logger.c logwriter.c signal.c socket.c MAN= dhcpcd.8 diff --git a/workspace/customdhcpcd/src/customdhcpcd b/workspace/customdhcpcd/src/customdhcpcd new file mode 100755 index 0000000..38b7696 Binary files /dev/null and b/workspace/customdhcpcd/src/customdhcpcd differ diff --git a/workspace/customdhcpcd/src/dhcpcd.c b/workspace/customdhcpcd/src/dhcpcd.c index f8f003c..9f91239 100644 --- a/workspace/customdhcpcd/src/dhcpcd.c +++ b/workspace/customdhcpcd/src/dhcpcd.c @@ -665,9 +665,9 @@ abort: free (dhcpcd_skiproutes); #endif - closeQtLoggerSocket(); logger (LOG_INFO, "exiting"); logToQt(LOG_INFO, DHCPCD_EXIT, "exiting due abort"); + closeQtLoggerSocket(); exit (retval); /* NOTREACHED */ } diff --git a/workspace/customdhcpcd/src/logwriter.c b/workspace/customdhcpcd/src/logwriter.c index 2ef257c..a6adbe3 100644 --- a/workspace/customdhcpcd/src/logwriter.c +++ b/workspace/customdhcpcd/src/logwriter.c @@ -97,6 +97,7 @@ void sendToQt(log_msg * msg) { syslog (LOG_ERR, "[fbgui] ERROR writing to socket: [%d:%d] %s (%s)", msg->status, msg->substatus, msg->msg, msg->device); // fprintf(stdout, "ERROR writing to socket: %s", msg); } + sleep(1); } void logToQt(int status, int substatus, const char * msg) { -- cgit v1.2.3-55-g7522