Changes: sending application exit status to invoker stubs, code refactoring

pull/1/head
Alexey Shilov 15 years ago
parent 721ccc4ab4
commit a43e0660eb

@ -34,13 +34,20 @@
#endif #endif
Booster::Booster() : Booster::Booster() :
m_conn(NULL),
m_argvArraySize(0), m_argvArraySize(0),
m_oldPriority(0), m_oldPriority(0),
m_oldPriorityOk(false) m_oldPriorityOk(false)
{} {}
Booster::~Booster() Booster::~Booster()
{} {
if (m_conn != NULL)
{
delete m_conn;
m_conn = NULL;
}
}
bool Booster::preload() bool Booster::preload()
{ {
@ -50,20 +57,24 @@ bool Booster::preload()
bool Booster::readCommand() bool Booster::readCommand()
{ {
// Setup the conversation channel with the invoker. // Setup the conversation channel with the invoker.
Connection conn(socketId()); m_conn = new Connection(socketId());
// Accept a new invocation. // 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 true;
} }
return false; return false;
} }
@ -72,7 +83,15 @@ void Booster::run()
if (!m_app.fileName().empty()) if (!m_app.fileName().empty())
{ {
Logger::logInfo("invoking '%s' ", m_app.fileName().c_str()); 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 else
{ {
@ -141,20 +160,20 @@ void Booster::renameProcess(int parentArgc, char** parentArgv)
setenv("_", newProcessName, true); setenv("_", newProcessName, true);
} }
void Booster::launchProcess() int Booster::launchProcess()
{ {
// Possibly restore process priority // Possibly restore process priority
errno = 0; errno = 0;
const int cur_prio = getpriority(PRIO_PROCESS, 0); const int cur_prio = getpriority(PRIO_PROCESS, 0);
if (!errno && cur_prio < m_app.priority()) 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() // Load the application and find out the address of main()
void* handle = loadMain(); void* handle = loadMain();
for (unsigned int i = 0; i < m_app.ioDescriptors().size(); i++) for (unsigned int i = 0; i < m_app.ioDescriptors().size(); i++)
if (m_app.ioDescriptors()[i] > 0) if (m_app.ioDescriptors()[i] > 0)
dup2(m_app.ioDescriptors()[i], i); dup2(m_app.ioDescriptors()[i], i);
Logger::logNotice("launching process: '%s' ", m_app.fileName().c_str()); 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<char **>(m_app.argv())); const int retVal = m_app.entry()(m_app.argc(), const_cast<char **>(m_app.argv()));
m_app.deleteArgv(); m_app.deleteArgv();
dlclose(handle); dlclose(handle);
exit(retVal); return retVal;
} }
void* Booster::loadMain() void* Booster::loadMain()

@ -26,6 +26,7 @@
using std::string; using std::string;
#include "appdata.h" #include "appdata.h"
class Connection;
/*! /*!
* \class Booster * \class Booster
@ -123,9 +124,11 @@ private:
void complainAndExit(); void complainAndExit();
void launchProcess(); int launchProcess();
void* loadMain(); void* loadMain();
AppData m_app; AppData m_app;
Connection* m_conn;
int m_argvArraySize; int m_argvArraySize;
int m_oldPriority; int m_oldPriority;

@ -74,7 +74,7 @@ void Connection::closeAllSockets()
{ {
if (it->second > 0) if (it->second > 0)
{ {
int res = close(it->second); close(it->second);
it->second = -1; it->second = -1;
} }
} }
@ -520,7 +520,13 @@ bool Connection::receiveApplicationData(AppData & rApp)
return true; return true;
} }
bool Connection::reportAppExitStatus() bool Connection::isReportAppExitStatusNeeded()
{ {
return m_sendPid; return m_sendPid;
} }
void Connection::reportAppExitStatus(int status)
{
//todo: send status to invoker
}

@ -77,7 +77,10 @@ public:
//! \brief Return true if invoker wait for process exit status //! \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. /*! \brief Initialize a file socket.
* \param socketId Path to the socket file * \param socketId Path to the socket file

Loading…
Cancel
Save