Changes: Access Booster::m_connection and Booster::m_appData through setter/getter in derived classes.

RevBy: TrustMe
pull/1/head
Jussi Lind 15 years ago
parent b7eb646a33
commit 27762f316d

@ -42,9 +42,9 @@
};
#endif
Booster::Booster() :
m_conn(NULL),
m_appData(new AppData),
m_connection(NULL),
m_argvArraySize(0),
m_oldPriority(0),
m_oldPriorityOk(false)
@ -52,8 +52,11 @@ Booster::Booster() :
Booster::~Booster()
{
delete m_conn;
m_conn = NULL;
delete m_connection;
m_connection = NULL;
delete m_appData;
m_appData = NULL;
}
bool Booster::preload()
@ -120,7 +123,7 @@ void Booster::sendDataToParent()
}
// Send to the parent process booster respawn delay value
int delay = m_app.delay();
int delay = m_appData->delay();
if (write(pipeFd(1), reinterpret_cast<const void *>(&delay), sizeof(int)) == -1) {
Logger::logError("Booster: Couldn't send respawn delay value to launcher process\n");
}
@ -129,46 +132,47 @@ void Booster::sendDataToParent()
bool Booster::readCommand()
{
// Setup the conversation channel with the invoker.
m_conn = new Connection(socketId());
m_connection = new Connection(socketId());
// Accept a new invocation.
if (m_conn->accept(m_app))
if (m_connection->accept(m_appData))
{
// Receive application data from the invoker
if(!m_conn->receiveApplicationData(m_app))
if(!m_connection->receiveApplicationData(m_appData))
{
m_conn->close();
m_connection->close();
return false;
}
// Close the connection if exit status doesn't need
// to be sent back to invoker
if (!m_conn->isReportAppExitStatusNeeded())
if (!m_connection->isReportAppExitStatusNeeded())
{
m_conn->close();
m_connection->close();
}
return true;
}
return false;
}
void Booster::run()
{
if (!m_app.fileName().empty())
if (!m_appData->fileName().empty())
{
//check if can close sockets here
if (!m_conn->isReportAppExitStatusNeeded())
if (!m_connection->isReportAppExitStatusNeeded())
{
Connection::closeAllSockets();
}
Logger::logInfo("Booster: invoking '%s' ", m_app.fileName().c_str());
Logger::logInfo("Booster: invoking '%s' ", m_appData->fileName().c_str());
int ret_val = launchProcess();
if (m_conn->isReportAppExitStatusNeeded())
if (m_connection->isReportAppExitStatusNeeded())
{
m_conn->sendAppExitStatus(ret_val);
m_conn->close();
m_connection->sendAppExitStatus(ret_val);
m_connection->close();
Connection::closeAllSockets();
}
}
@ -191,14 +195,14 @@ void Booster::renameProcess(int parentArgc, char** parentArgv)
m_argvArraySize--;
}
if (m_app.appName().empty())
if (m_appData->appName().empty())
{
// application name isn't known yet, let's give to the process
// temporary booster name
m_app.setAppName(boosterTemporaryProcessName());
m_appData->setAppName(boosterTemporaryProcessName());
}
const char* newProcessName = m_app.appName().c_str();
const char* newProcessName = m_appData->appName().c_str();
Logger::logNotice("Booster: set new name for process: %s", newProcessName);
// This code copies all the new arguments to the space reserved
@ -213,13 +217,13 @@ void Booster::renameProcess(int parentArgc, char** parentArgv)
spaceAvailable -= strlen(parentArgv[0]);
for (int i = 1; i < m_app.argc(); i++)
for (int i = 1; i < m_appData->argc(); i++)
{
if (spaceAvailable > static_cast<int>(strlen(m_app.argv()[i])) + 1)
if (spaceAvailable > static_cast<int>(strlen(m_appData->argv()[i])) + 1)
{
strncat(parentArgv[0], " ", 1);
strncat(parentArgv[0], m_app.argv()[i], spaceAvailable);
spaceAvailable -= strlen(m_app.argv()[i] + 1);
strncat(parentArgv[0], m_appData->argv()[i], spaceAvailable);
spaceAvailable -= strlen(m_appData->argv()[i] + 1);
}
else
{
@ -240,28 +244,28 @@ 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());
if (!errno && cur_prio < m_appData->priority())
setpriority(PRIO_PROCESS, 0, m_appData->priority());
// Set user ID and group ID of calling process if differing
// from the ones we got from invoker
if (getuid() != m_app.userId())
setuid(m_app.userId());
if (getuid() != m_appData->userId())
setuid(m_appData->userId());
if (getgid() != m_app.groupId())
setgid(m_app.groupId());
if (getgid() != m_appData->groupId())
setgid(m_appData->groupId());
// Load the application and find out the address of main()
void* handle = loadMain();
// Duplicate I/O descriptors
for (unsigned int i = 0; i < m_app.ioDescriptors().size(); i++)
for (unsigned int i = 0; i < m_appData->ioDescriptors().size(); i++)
{
if (m_app.ioDescriptors()[i] > 0)
if (m_appData->ioDescriptors()[i] > 0)
{
dup2(m_app.ioDescriptors()[i], i);
close(m_app.ioDescriptors()[i]);
dup2(m_appData->ioDescriptors()[i], i);
close(m_appData->ioDescriptors()[i]);
}
}
@ -269,12 +273,12 @@ int Booster::launchProcess()
const char * pwd = getenv("PWD");
if (pwd) chdir(pwd);
Logger::logNotice("Booster: launching process: '%s' ", m_app.fileName().c_str());
Logger::logNotice("Booster: launching process: '%s' ", m_appData->fileName().c_str());
Logger::closeLog();
// Jump to main()
const int retVal = m_app.entry()(m_app.argc(), const_cast<char **>(m_app.argv()));
m_app.deleteArgv();
const int retVal = m_appData->entry()(m_appData->argc(), const_cast<char **>(m_appData->argv()));
m_appData->deleteArgv();
dlclose(handle);
return retVal;
}
@ -283,13 +287,13 @@ void* Booster::loadMain()
{
#ifdef HAVE_CREDS
// filter out invoker-specific credentials
Booster::filterOutCreds(m_app.peerCreds());
Booster::filterOutCreds(m_appData->peerCreds());
// Set application's platform security credentials.
// creds_confine2() tries first to use application-specific credentials, but if they are missing
// from the system, it uses credentials inherited from the invoker.
int err = creds_confine2(m_app.fileName().c_str(), credp_str2flags("set", NULL), m_app.peerCreds());
m_app.deletePeerCreds();
int err = creds_confine2(m_appData->fileName().c_str(), credp_str2flags("set", NULL), m_appData->peerCreds());
m_appData->deletePeerCreds();
if (err < 0)
{
@ -302,18 +306,18 @@ void* Booster::loadMain()
int dlopenFlags = RTLD_LAZY;
if (m_app.dlopenGlobal())
if (m_appData->dlopenGlobal())
dlopenFlags |= RTLD_GLOBAL;
else
dlopenFlags |= RTLD_LOCAL;
#if (PLATFORM_ID == Linux)
if (m_app.dlopenDeep())
if (m_appData->dlopenDeep())
dlopenFlags |= RTLD_DEEPBIND;
#endif
// Load the application as a library
void * module = dlopen(m_app.fileName().c_str(), dlopenFlags);
void * module = dlopen(m_appData->fileName().c_str(), dlopenFlags);
if (!module)
Logger::logErrorAndDie(EXIT_FAILURE, "Booster: Loading invoked application failed: '%s'\n", dlerror());
@ -323,7 +327,7 @@ void* Booster::loadMain()
// in dlsym()'s man page.
dlerror();
m_app.setEntry(reinterpret_cast<entry_t>(dlsym(module, "main")));
m_appData->setEntry(reinterpret_cast<entry_t>(dlsym(module, "main")));
const char * error_s = dlerror();
if (error_s != NULL)
@ -362,9 +366,9 @@ bool Booster::popPriority()
pid_t Booster::invokersPid()
{
if (m_conn->isReportAppExitStatusNeeded())
if (m_connection->isReportAppExitStatusNeeded())
{
return m_conn->peerPid();
return m_connection->peerPid();
}
else
{
@ -383,6 +387,22 @@ int Booster::pipeFd(bool whichEnd) const
return m_pipeFd[whichEnd];
}
Connection* Booster::connection() const
{
return m_connection;
}
void Booster::setConnection(Connection * newConnection)
{
delete m_connection;
m_connection = newConnection;
}
AppData* Booster::appData() const
{
return m_appData;
}
#ifdef HAVE_CREDS
void Booster::initExtraCreds()
@ -410,4 +430,3 @@ void Booster::filterOutCreds(creds_t creds)
}
#endif //HAVE_CREDS

@ -115,6 +115,15 @@ public:
//! Get invoker's pid
pid_t invokersPid();
//! Get the connection object
Connection* connection() const;
//! Set connection object. Booster takes the ownership.
void setConnection(Connection * connectio);
//! Get application data object
AppData* appData() const;
#ifdef HAVE_CREDS
//! initialize invoker-specific credentials to be filtered out by filterOutCreds()
static void initExtraCreds();
@ -151,12 +160,6 @@ protected:
//! Returns the given pipe fd (0 = read end, 1 = write end)
int pipeFd(bool whichEnd) const;
//! Data structure representing the application to be invoked
AppData m_app;
//! Socket connection to invoker
Connection* m_conn;
private:
//! Disable copy-constructor
@ -175,6 +178,12 @@ private:
//! Helper method: load the library and find out address for "main".
void* loadMain();
//! Data structure representing the application to be invoked
AppData* m_appData;
//! Socket connection to invoker
Connection* m_connection;
//! Size (length) of the argument vector
int m_argvArraySize;

@ -127,7 +127,7 @@ void Connection::initSocket(const string socketId)
}
}
bool Connection::accept(AppData & rApp)
bool Connection::accept(AppData* appData)
{
if (!m_testMode)
{
@ -144,8 +144,8 @@ bool Connection::accept(AppData & rApp)
// Get credentials of assumed invoker
creds_t ccreds = creds_getpeer(m_fd);
// Fetched peer creds will be free'd with rApp.deletePeerCreds
rApp.setPeerCreds(ccreds);
// Fetched peer creds will be free'd with appData->deletePeerCreds
appData->setPeerCreds(ccreds);
#if ! defined (DISABLE_VERIFICATION)
@ -566,19 +566,19 @@ bool Connection::receiveActions()
}
}
bool Connection::receiveApplicationData(AppData & rApp)
bool Connection::receiveApplicationData(AppData* appData)
{
// Read magic number
rApp.setOptions(receiveMagic());
if (rApp.options() == -1)
appData->setOptions(receiveMagic());
if (appData->options() == -1)
{
Logger::logError("Connection: receiving magic failed\n");
return false;
}
// Read application name
rApp.setAppName(receiveAppName());
if (rApp.appName().empty())
appData->setAppName(receiveAppName());
if (appData->appName().empty())
{
Logger::logError("Connection: receiving application name failed\n");
return false;
@ -587,13 +587,13 @@ bool Connection::receiveApplicationData(AppData & rApp)
// Read application parameters
if (receiveActions())
{
rApp.setFileName(m_fileName);
rApp.setPriority(m_priority);
rApp.setDelay(m_delay);
rApp.setArgc(m_argc);
rApp.setArgv(m_argv);
rApp.setIODescriptors(vector<int>(m_io, m_io + IO_DESCRIPTOR_COUNT));
rApp.setIDs(m_uid, m_gid);
appData->setFileName(m_fileName);
appData->setPriority(m_priority);
appData->setDelay(m_delay);
appData->setArgc(m_argc);
appData->setArgv(m_argv);
appData->setIODescriptors(vector<int>(m_io, m_io + IO_DESCRIPTOR_COUNT));
appData->setIDs(m_uid, m_gid);
}
else
{
@ -622,4 +622,3 @@ pid_t Connection::peerPid()
return cr.pid;
}

@ -65,17 +65,17 @@ public:
/*! \brief Accept connection.
* Accept a socket connection from the invoker.
* Stores security credentials of the connected
* peer to rApp, if security is enabled. The credentials
* in rApp must be released by the caller.
* peer to appData, if security is enabled. The credentials
* in appData must be released by the caller.
* \return true on success.
*/
bool accept(AppData & rApp);
bool accept(AppData* appData);
//! \brief Close the socket connection.
void close();
//! \brief Receive application data to rApp.
bool receiveApplicationData(AppData & rApp);
//! \brief Receive application data to appData.
bool receiveApplicationData(AppData* appData);
//! \brief Return true if invoker wait for process exit status
bool isReportAppExitStatusNeeded() const;

@ -144,7 +144,7 @@ int MBooster::processId()
bool MBooster::readCommand()
{
// Setup the conversation channel with the invoker.
m_conn = new Connection(socketId());
setConnection(new Connection(socketId()));
// exit from event loop when invoker is ready to connect
connect(this, SIGNAL(connectionAccepted()), MApplication::instance() , SLOT(quit()));
@ -164,23 +164,23 @@ bool MBooster::readCommand()
delete m_item;
m_item = NULL;
// Restore signal handlers to previous values
restoreUnixSignalHandlers();
// Receive application data from the invoker
if(!m_conn->receiveApplicationData(m_app))
if(!connection()->receiveApplicationData(appData()))
{
m_conn->close();
connection()->close();
return false;
}
// Close the connection if exit status doesn't need
// to be sent back to invoker
if (!m_conn->isReportAppExitStatusNeeded())
if (!connection()->isReportAppExitStatusNeeded())
{
m_conn->close();
connection()->close();
}
return true;
}
@ -190,10 +190,9 @@ void MBooster::notifyThemeChange()
::_exit(EXIT_SUCCESS);
}
void MBooster::accept()
{
if (m_conn->accept(m_app))
if (connection()->accept(appData()))
{
emit connectionAccepted();
}

@ -151,43 +151,43 @@ int WRTBooster::processId()
bool WRTBooster::readCommand()
{
// Setup the conversation channel with the invoker.
m_conn = new Connection(socketId());
setConnection(new Connection(socketId()));
// exit from event loop when invoker is ready to connect
// Exit from event loop when invoker is ready to connect
connect(this, SIGNAL(connectionAccepted()), MApplication::instance() , SLOT(quit()));
// enable theme change handler
// Enable theme change handler
m_item = new MGConfItem(MEEGOTOUCH_THEME_GCONF_KEY, 0);
connect(m_item, SIGNAL(valueChanged()), this, SLOT(notifyThemeChange()));
// start another thread to listen connection from invoker
// Start another thread to listen connection from invoker
QtConcurrent::run(this, &WRTBooster::accept);
// Run event loop so MApplication and MApplicationWindow objects can receive notifications
MApplication::exec();
// disable theme change handler
// Disable theme change handler
disconnect(m_item, 0, this, 0);
delete m_item;
m_item = NULL;
// Restore signal handlers to previous values
restoreUnixSignalHandlers();
// Receive application data from the invoker
if(!m_conn->receiveApplicationData(m_app))
if(!connection()->receiveApplicationData(appData()))
{
m_conn->close();
connection()->close();
return false;
}
// Close the connection if exit status doesn't need
// to be sent back to invoker
if (!m_conn->isReportAppExitStatusNeeded())
if (!connection()->isReportAppExitStatusNeeded())
{
m_conn->close();
connection()->close();
}
return true;
}
@ -197,10 +197,9 @@ void WRTBooster::notifyThemeChange()
::_exit(EXIT_SUCCESS);
}
void WRTBooster::accept()
{
if (m_conn->accept(m_app))
if (connection()->accept(appData()))
{
emit connectionAccepted();
}

@ -83,7 +83,7 @@ void Ut_Booster::testRenameBoosterProcess()
{
m_subject.reset(new MyBooster);
// if m_app.appName isn't initialized, new process name is booster_x
// if appData()->appName isn't initialized, new process name is booster_x
// 20 chars dummy buffer used to fool ps to show correct process name with args
const int INIT_ARGS = 2;
char ** initialArgv = packTwoArgs("oldName", " ");
@ -95,14 +95,14 @@ void Ut_Booster::testRenameBoosterProcess()
// Define and copy args because it's assumed that they are allocated in the heap
// (AppData deletes the argv on exit)
const int ARGS = 3;
m_subject->m_app.setArgc(ARGS);
m_subject->appData()->setArgc(ARGS);
char ** argv = new char * [ARGS];
argv[0] = strdup("newName");
argv[1] = strdup("--foo");
argv[2] = strdup("--bar");
m_subject->m_app.setArgv(const_cast<const char **>(argv));
m_subject->m_app.setAppName("newName");
m_subject->appData()->setArgv(const_cast<const char **>(argv));
m_subject->appData()->setAppName("newName");
m_subject->renameProcess(INIT_ARGS, const_cast<char **>(initialArgv));
// New name and arguments fit and are correct
@ -119,13 +119,13 @@ void Ut_Booster::testRenameProcess()
// Define and copy args because it's assumed that they are allocated in the heap
// (AppData deletes the argv on exit)
const int ARGS = 3;
m_subject->m_app.setArgc(ARGS);
m_subject->appData()->setArgc(ARGS);
char ** argv = new char * [ARGS];
argv[0] = strdup("newName");
argv[1] = strdup("--foo");
argv[2] = strdup("--bar");
m_subject->m_app.setArgv(const_cast<const char **>(argv));
m_subject->m_app.setAppName(m_subject->m_app.argv()[0]);
m_subject->appData()->setArgv(const_cast<const char **>(argv));
m_subject->appData()->setAppName(m_subject->appData()->argv()[0]);
// 20 chars dummy buffer used to fool ps to show correct process name with args
const int INIT_ARGS = 2;
@ -144,13 +144,13 @@ void Ut_Booster::testRenameProcessNotEnoughSpace()
m_subject.reset(new MyBooster);
const int ARGS = 3;
m_subject->m_app.setArgc(ARGS);
m_subject->appData()->setArgc(ARGS);
char ** argv = new char * [ARGS];
argv[0] = strdup("newNameLong");
argv[1] = strdup("--foo");
argv[2] = strdup("--bar");
m_subject->m_app.setArgv(const_cast<const char **>(argv));
m_subject->m_app.setAppName(m_subject->m_app.argv()[0]);
m_subject->appData()->setArgv(const_cast<const char **>(argv));
m_subject->appData()->setAppName(m_subject->appData()->argv()[0]);
const int INIT_ARGS = 2;
char ** initialArgv = packTwoArgs("oldName", " ");
@ -159,7 +159,7 @@ void Ut_Booster::testRenameProcessNotEnoughSpace()
// Not enough space for the new name nor the arguments:
// name should be cut
QVERIFY(strncmp(initialArgv[0], m_subject->m_app.argv()[0], initLen - 1) == 0);
QVERIFY(strncmp(initialArgv[0], m_subject->appData()->argv()[0], initLen - 1) == 0);
delete [] initialArgv[0];
delete [] initialArgv;
@ -170,13 +170,13 @@ void Ut_Booster::testRenameProcessNotEnoughSpace2()
m_subject.reset(new MyBooster);
const int ARGS = 3;
m_subject->m_app.setArgc(ARGS);
m_subject->appData()->setArgc(ARGS);
char ** argv = new char * [ARGS];
argv[0] = strdup("newName");
argv[1] = strdup("--foo");
argv[2] = strdup("--bar");
m_subject->m_app.setArgv(const_cast<const char **>(argv));
m_subject->m_app.setAppName(m_subject->m_app.argv()[0]);
m_subject->appData()->setArgv(const_cast<const char **>(argv));
m_subject->appData()->setAppName(m_subject->appData()->argv()[0]);
const int INIT_ARGS = 2;
char ** initialArgv = packTwoArgs("oldName", " ");
@ -195,13 +195,13 @@ void Ut_Booster::testRenameProcessNotEnoughSpace3()
m_subject.reset(new MyBooster);
const int ARGS = 3;
m_subject->m_app.setArgc(ARGS);
m_subject->appData()->setArgc(ARGS);
char ** argv = new char * [ARGS];
argv[0] = strdup("newName");
argv[1] = strdup("--foo");
argv[2] = strdup("--bar");
m_subject->m_app.setArgv(const_cast<const char **>(argv));
m_subject->m_app.setAppName(m_subject->m_app.argv()[0]);
m_subject->appData()->setArgv(const_cast<const char **>(argv));
m_subject->appData()->setAppName(m_subject->appData()->argv()[0]);
const int INIT_ARGS = 2;
char ** initialArgv = packTwoArgs("app", " ");
@ -221,13 +221,13 @@ void Ut_Booster::testRenameProcessNotEnoughSpace4()
m_subject.reset(new MyBooster);
const int ARGS = 3;
m_subject->m_app.setArgc(ARGS);
m_subject->appData()->setArgc(ARGS);
char ** argv = new char * [ARGS];
argv[0] = strdup("newNameLongLong");
argv[1] = strdup("--foo");
argv[2] = strdup("--bar");
m_subject->m_app.setArgv(const_cast<const char **>(argv));
m_subject->m_app.setAppName(m_subject->m_app.argv()[0]);
m_subject->appData()->setArgv(const_cast<const char **>(argv));
m_subject->appData()->setAppName(m_subject->appData()->argv()[0]);
const int INIT_ARGS = 2;
char ** initialArgv = packTwoArgs("app", " ");
@ -245,12 +245,12 @@ void Ut_Booster::testRenameProcessNoArgs()
m_subject.reset(new MyBooster);
const int ARGS = 2;
m_subject->m_app.setArgc(ARGS);
m_subject->appData()->setArgc(ARGS);
char ** argv = new char * [ARGS];
argv[0] = strdup("newName");
argv[1] = strdup("--foo");
m_subject->m_app.setArgv(const_cast<const char **>(argv));
m_subject->m_app.setAppName(m_subject->m_app.argv()[0]);
m_subject->appData()->setArgv(const_cast<const char **>(argv));
m_subject->appData()->setAppName(m_subject->appData()->argv()[0]);
const int INIT_ARGS = 1;
char ** initialArgv = new char * [INIT_ARGS];
@ -258,7 +258,7 @@ void Ut_Booster::testRenameProcessNoArgs()
m_subject->renameProcess(INIT_ARGS, initialArgv);
// No dummy space argument at all, only name fits
QVERIFY(strcmp(initialArgv[0], m_subject->m_app.argv()[0]) == 0);
QVERIFY(strcmp(initialArgv[0], m_subject->appData()->argv()[0]) == 0);
delete initialArgv[0];
delete [] initialArgv;

Loading…
Cancel
Save