kit-in-process: pure re-factor to a run-time function to flag this.

Avoids a number of compile time conditionals and adds flexibility.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Iff6b294b504526e70715e436ad33d47c8df4752c
pull/7706/head
Darshan-upadhyay1110 2023-11-20 21:00:37 +00:00 committed by Michael Meeks
parent e9f5f04dad
commit 3f46c1db44
4 changed files with 30 additions and 27 deletions

View File

@ -325,6 +325,16 @@ namespace Util
return std::getenv("DISPLAY") != nullptr;
}
bool isKitInProcess()
{
#ifdef KIT_IN_PROCESS
return true;
#else
return false;
#endif
}
#if !MOBILEAPP
static const char *startsWith(const char *line, const char *tag, std::size_t tagLen)

View File

@ -1316,6 +1316,8 @@ int main(int argc, char**argv)
*/
bool isFuzzing();
bool isKitInProcess();
/**
* Splits string into vector<string>. Does not accept referenced variables for easy
* usage like (splitString("test", ..)) or (splitString(getStringOnTheFly(), ..))

View File

@ -470,12 +470,8 @@ void forkLibreOfficeKit(const std::string& childRoot,
// Cleanup first, to reduce disk load.
cleanupChildren();
#ifndef KIT_IN_PROCESS
(void) limit;
#else
if (limit > 0)
if (Util::isKitInProcess() && limit > 0)
ForkCounter = limit;
#endif
if (ForkCounter > 0)
{

View File

@ -3214,9 +3214,8 @@ void COOLWSD::displayHelp()
bool COOLWSD::checkAndRestoreForKit()
{
#ifdef KIT_IN_PROCESS
return false;
#else
if (Util::isKitInProcess())
return false;
// clang issues warning for WIF*() macro usages below:
// "equality comparison with extraneous parentheses [-Werror,-Wparentheses-equality]"
@ -3307,8 +3306,6 @@ bool COOLWSD::checkAndRestoreForKit()
#if defined __clang__
#pragma clang diagnostic pop
#endif
#endif
}
@ -3765,8 +3762,9 @@ private:
LOG_TRC("Child connection with URI [" << COOLWSD::anonymizeUrl(request.getUrl())
<< ']');
Poco::URI requestURI(request.getUrl());
#ifndef KIT_IN_PROCESS
if (requestURI.getPath() == FORKIT_URI)
if (Util::isKitInProcess())
LOG_TRC("Avoid spawning forkit for kit-in-process");
else if (requestURI.getPath() == FORKIT_URI)
{
if (socket->getPid() != COOLWSD::ForKitProcId)
{
@ -3780,8 +3778,7 @@ private:
PrisonerPoll->setForKitProcess(COOLWSD::ForKitProc);
return;
}
#endif
if (requestURI.getPath() != NEW_CHILD_URI)
else if (requestURI.getPath() != NEW_CHILD_URI)
{
LOG_ERR("Invalid incoming child URI [" << requestURI.getPath() << ']');
return;
@ -5942,7 +5939,7 @@ int COOLWSD::innerMain()
// No need to "have at least one child" beforehand on mobile
#if !MOBILEAPP
#ifndef KIT_IN_PROCESS
if (!Util::isKitInProcess())
{
// Make sure we have at least one child before moving forward.
std::unique_lock<std::mutex> lock(NewChildrenMutex);
@ -5981,7 +5978,6 @@ int COOLWSD::innerMain()
assert(NewChildren.size() > 0);
}
#endif
if (LogLevel != "trace")
{
@ -6240,14 +6236,15 @@ int COOLWSD::innerMain()
NewChildren.clear();
#if !MOBILEAPP
#ifndef KIT_IN_PROCESS
// Wait for forkit process finish.
LOG_INF("Waiting for forkit process to exit");
int status = 0;
waitpid(ForKitProcId, &status, WUNTRACED);
ForKitProcId = -1;
ForKitProc.reset();
#endif
if (!Util::isKitInProcess())
{
// Wait for forkit process finish.
LOG_INF("Waiting for forkit process to exit");
int status = 0;
waitpid(ForKitProcId, &status, WUNTRACED);
ForKitProcId = -1;
ForKitProc.reset();
}
JailUtil::cleanupJails(CleanupChildRoot);
#endif // !MOBILEAPP
@ -6427,13 +6424,11 @@ void forwardSigUsr2()
std::lock_guard<std::mutex> newChildLock(NewChildrenMutex);
#if !MOBILEAPP
#ifndef KIT_IN_PROCESS
if (COOLWSD::ForKitProcId > 0)
if (!Util::isKitInProcess() && COOLWSD::ForKitProcId > 0)
{
LOG_INF("Sending SIGUSR2 to forkit " << COOLWSD::ForKitProcId);
::kill(COOLWSD::ForKitProcId, SIGUSR2);
}
#endif
#endif
for (const auto& child : NewChildren)