From 191251d200b14ee50a7f7ac53885e63b459f7c9e Mon Sep 17 00:00:00 2001 From: Jussi Lind Date: Wed, 15 Dec 2010 12:52:26 +0200 Subject: [PATCH] Fixes: NB#211510 - boosters should update oom_adj to 0 before calling main RevBy: Antti Kervinen --- src/launcherlib/booster.cpp | 59 ++++++++++++++++++++++++++----------- src/launcherlib/booster.h | 3 ++ 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/launcherlib/booster.cpp b/src/launcherlib/booster.cpp index 63dc362..b6a33b3 100644 --- a/src/launcherlib/booster.cpp +++ b/src/launcherlib/booster.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #ifdef HAVE_CREDS #include @@ -255,6 +256,26 @@ int Booster::launchProcess() if (getgid() != m_appData->groupId()) setgid(m_appData->groupId()); + // Reset out-of-memory killer adjustment + resetOomAdj(); + +#ifdef HAVE_CREDS + // filter out invoker-specific credentials + 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_appData->fileName().c_str(), credp_str2flags("set", NULL), m_appData->peerCreds()); + m_appData->deletePeerCreds(); + + if (err < 0) + { + // Credential setup has failed, abort. + Logger::logErrorAndDie(EXIT_FAILURE, "Booster: Failed to setup credentials for launching application: %d\n", err); + } +#endif + // Load the application and find out the address of main() void* handle = loadMain(); @@ -284,23 +305,6 @@ int Booster::launchProcess() void* Booster::loadMain() { -#ifdef HAVE_CREDS - // filter out invoker-specific credentials - 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_appData->fileName().c_str(), credp_str2flags("set", NULL), m_appData->peerCreds()); - m_appData->deletePeerCreds(); - - if (err < 0) - { - // Credential setup has failed, abort. - Logger::logErrorAndDie(EXIT_FAILURE, "Booster: Failed to setup credentials for launching application: %d\n", err); - } -#endif - // Setup flags for dlopen int dlopenFlags = RTLD_LAZY; @@ -429,3 +433,24 @@ void Booster::filterOutCreds(creds_t creds) } #endif //HAVE_CREDS + +void Booster::resetOomAdj() +{ + const char * PROC_OOM_ADJ_FILE = "/proc/self/oom_adj"; + int fd = open(PROC_OOM_ADJ_FILE, O_WRONLY); + if (fd != -1) + { + if (write(fd, "0", sizeof(char)) == -1) + { + Logger::logError("Couldn't write to '%s': %s", PROC_OOM_ADJ_FILE, + strerror(errno)); + } + + close(fd); + } + else + { + Logger::logError("Couldn't open '%s' for write: %s", PROC_OOM_ADJ_FILE, + strerror(errno)); + } +} diff --git a/src/launcherlib/booster.h b/src/launcherlib/booster.h index 3022303..357001e 100644 --- a/src/launcherlib/booster.h +++ b/src/launcherlib/booster.h @@ -160,6 +160,9 @@ protected: //! Returns the given pipe fd (0 = read end, 1 = write end) int pipeFd(bool whichEnd) const; + //! Reset out-of-memory killer adjustment + void resetOomAdj(); + private: //! Disable copy-constructor