From a43e0660eb96e07b78a70fd52cac87240226141e Mon Sep 17 00:00:00 2001 From: Alexey Shilov Date: Fri, 13 Aug 2010 17:34:18 +0300 Subject: [PATCH] Changes: sending application exit status to invoker stubs, code refactoring --- src/launcher/booster.cpp | 45 ++++++++++++++++++++++++++----------- src/launcher/booster.h | 5 ++++- src/launcher/connection.cpp | 10 +++++++-- src/launcher/connection.h | 5 ++++- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/launcher/booster.cpp b/src/launcher/booster.cpp index 9259791..1b497cb 100644 --- a/src/launcher/booster.cpp +++ b/src/launcher/booster.cpp @@ -34,13 +34,20 @@ #endif Booster::Booster() : + m_conn(NULL), m_argvArraySize(0), m_oldPriority(0), m_oldPriorityOk(false) {} Booster::~Booster() -{} +{ + if (m_conn != NULL) + { + delete m_conn; + m_conn = NULL; + } +} bool Booster::preload() { @@ -50,20 +57,24 @@ bool Booster::preload() bool Booster::readCommand() { // Setup the conversation channel with the invoker. - Connection conn(socketId()); + m_conn = new Connection(socketId()); // Accept a new invocation. - if (conn.acceptConn()) + if (m_conn->acceptConn()) { - bool res = conn.receiveApplicationData(m_app); + bool res = m_conn->receiveApplicationData(m_app); + if(!res) + { + m_conn->closeConn(); + return false; + } - if (!conn.reportAppExitStatus()) + if (!m_conn->isReportAppExitStatusNeeded()) { - conn.closeConn(); + m_conn->closeConn(); } return true; } - return false; } @@ -72,7 +83,15 @@ void Booster::run() if (!m_app.fileName().empty()) { Logger::logInfo("invoking '%s' ", m_app.fileName().c_str()); - launchProcess(); + int ret_val = launchProcess(); + + if (m_conn->isReportAppExitStatusNeeded()) + { + m_conn->reportAppExitStatus(ret_val); + m_conn->closeConn(); + Connection::closeAllSockets(); + } + } else { @@ -141,20 +160,20 @@ void Booster::renameProcess(int parentArgc, char** parentArgv) setenv("_", newProcessName, true); } -void Booster::launchProcess() +int Booster::launchProcess() { // Possibly restore process priority errno = 0; const int cur_prio = getpriority(PRIO_PROCESS, 0); if (!errno && cur_prio < m_app.priority()) - setpriority(PRIO_PROCESS, 0, m_app.priority()); + setpriority(PRIO_PROCESS, 0, m_app.priority()); // Load the application and find out the address of main() void* handle = loadMain(); for (unsigned int i = 0; i < m_app.ioDescriptors().size(); i++) - if (m_app.ioDescriptors()[i] > 0) - dup2(m_app.ioDescriptors()[i], i); + if (m_app.ioDescriptors()[i] > 0) + dup2(m_app.ioDescriptors()[i], i); Logger::logNotice("launching process: '%s' ", m_app.fileName().c_str()); @@ -165,7 +184,7 @@ void Booster::launchProcess() const int retVal = m_app.entry()(m_app.argc(), const_cast(m_app.argv())); m_app.deleteArgv(); dlclose(handle); - exit(retVal); + return retVal; } void* Booster::loadMain() diff --git a/src/launcher/booster.h b/src/launcher/booster.h index 2d50ebc..e4be724 100644 --- a/src/launcher/booster.h +++ b/src/launcher/booster.h @@ -26,6 +26,7 @@ using std::string; #include "appdata.h" +class Connection; /*! * \class Booster @@ -123,9 +124,11 @@ private: void complainAndExit(); - void launchProcess(); + int launchProcess(); void* loadMain(); + AppData m_app; + Connection* m_conn; int m_argvArraySize; int m_oldPriority; diff --git a/src/launcher/connection.cpp b/src/launcher/connection.cpp index 04bd43b..13c7ad0 100644 --- a/src/launcher/connection.cpp +++ b/src/launcher/connection.cpp @@ -74,7 +74,7 @@ void Connection::closeAllSockets() { if (it->second > 0) { - int res = close(it->second); + close(it->second); it->second = -1; } } @@ -520,7 +520,13 @@ bool Connection::receiveApplicationData(AppData & rApp) return true; } -bool Connection::reportAppExitStatus() +bool Connection::isReportAppExitStatusNeeded() { return m_sendPid; } + +void Connection::reportAppExitStatus(int status) +{ + //todo: send status to invoker +} + diff --git a/src/launcher/connection.h b/src/launcher/connection.h index e2ac012..c81f8af 100644 --- a/src/launcher/connection.h +++ b/src/launcher/connection.h @@ -77,7 +77,10 @@ public: //! \brief Return true if invoker wait for process exit status - bool reportAppExitStatus(); + bool isReportAppExitStatusNeeded(); + + //! \brief Send application exit status to invoker + void reportAppExitStatus(int status); /*! \brief Initialize a file socket. * \param socketId Path to the socket file