extract some functions to extra files for in process mode
Extract some functions from ForKit.cpp and COOLWSD.cpp to new files so we can do a kit in process mode without using ifdef directives. Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com> Change-Id: I7529f8f46a8026318244666b27d1ce72ed5ad4capull/7850/head
parent
a1e08c1aab
commit
8f178ef6cd
|
@ -100,6 +100,7 @@ loadtest
|
||||||
unittest
|
unittest
|
||||||
clientnb
|
clientnb
|
||||||
libsimd.a
|
libsimd.a
|
||||||
|
coolwsd-inproc
|
||||||
|
|
||||||
# Fuzzer
|
# Fuzzer
|
||||||
*_fuzzer
|
*_fuzzer
|
||||||
|
|
|
@ -147,7 +147,8 @@ coolwsd_sources = common/Crypto.cpp \
|
||||||
wsd/WopiProxy.cpp
|
wsd/WopiProxy.cpp
|
||||||
|
|
||||||
coolwsd_SOURCES = $(coolwsd_sources) \
|
coolwsd_SOURCES = $(coolwsd_sources) \
|
||||||
$(shared_sources)
|
$(shared_sources) \
|
||||||
|
wsd/coolwsd-fork.cpp
|
||||||
|
|
||||||
EXTRA_coolwsd_DEPENDENCIES = browser/node_modules
|
EXTRA_coolwsd_DEPENDENCIES = browser/node_modules
|
||||||
|
|
||||||
|
@ -189,7 +190,8 @@ coolforkit_sources = kit/ChildSession.cpp \
|
||||||
kit/Kit.cpp
|
kit/Kit.cpp
|
||||||
|
|
||||||
coolforkit_SOURCES = $(coolforkit_sources) \
|
coolforkit_SOURCES = $(coolforkit_sources) \
|
||||||
$(shared_sources)
|
$(shared_sources) \
|
||||||
|
kit/forkit-main.cpp
|
||||||
|
|
||||||
coolforkit_LDADD = libsimd.a
|
coolforkit_LDADD = libsimd.a
|
||||||
|
|
||||||
|
@ -200,6 +202,7 @@ coolforkit_SOURCES += \
|
||||||
common_fuzzer_sources = \
|
common_fuzzer_sources = \
|
||||||
common/DummyTraceEventEmitter.cpp \
|
common/DummyTraceEventEmitter.cpp \
|
||||||
$(coolwsd_sources) \
|
$(coolwsd_sources) \
|
||||||
|
wsd/coolwsd-inproc.cpp \
|
||||||
$(coolforkit_sources) \
|
$(coolforkit_sources) \
|
||||||
$(shared_sources)
|
$(shared_sources)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ add_library(androidapp SHARED
|
||||||
../../../../../wsd/COOLWSD.cpp
|
../../../../../wsd/COOLWSD.cpp
|
||||||
../../../../../wsd/RequestDetails.cpp
|
../../../../../wsd/RequestDetails.cpp
|
||||||
../../../../../wsd/Storage.cpp
|
../../../../../wsd/Storage.cpp
|
||||||
../../../../../wsd/TileCache.cpp)
|
../../../../../wsd/TileCache.cpp
|
||||||
|
../../../../../wsd/coolwsd-fork.cpp)
|
||||||
|
|
||||||
target_compile_definitions(androidapp PRIVATE COOLWSD_CONFIGDIR="/assets/etc/coolwsd")
|
target_compile_definitions(androidapp PRIVATE COOLWSD_CONFIGDIR="/assets/etc/coolwsd")
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ wsd_sources = ../wsd/ClientSession.cpp \
|
||||||
../wsd/COOLWSD.cpp \
|
../wsd/COOLWSD.cpp \
|
||||||
../wsd/RequestDetails.cpp \
|
../wsd/RequestDetails.cpp \
|
||||||
../wsd/Storage.cpp \
|
../wsd/Storage.cpp \
|
||||||
../wsd/TileCache.cpp
|
../wsd/TileCache.cpp \
|
||||||
|
../wsd/coolwsd-fork.cpp
|
||||||
|
|
||||||
mobile_SOURCES = mobile.cpp $(common_sources) $(kit_sources) $(net_sources) $(wsd_sources)
|
mobile_SOURCES = mobile.cpp $(common_sources) $(kit_sources) $(net_sources) $(wsd_sources)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
1FCFA28A2B2AF13F007EE2DF /* coolwsd-fork.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FCFA2892B2AF13C007EE2DF /* coolwsd-fork.cpp */; };
|
||||||
3F3B54DD2A3928D100063C01 /* HttpRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F3B54DB2A39288500063C01 /* HttpRequest.cpp */; };
|
3F3B54DD2A3928D100063C01 /* HttpRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F3B54DB2A39288500063C01 /* HttpRequest.cpp */; };
|
||||||
3F3B54E02A392CCB00063C01 /* NetUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F3B54DE2A392C9C00063C01 /* NetUtil.cpp */; };
|
3F3B54E02A392CCB00063C01 /* NetUtil.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3F3B54DE2A392C9C00063C01 /* NetUtil.cpp */; };
|
||||||
A5C2FA5A2AC1BB3900265946 /* Simd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5C2FA592AC1BB3800265946 /* Simd.cpp */; };
|
A5C2FA5A2AC1BB3900265946 /* Simd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5C2FA592AC1BB3800265946 /* Simd.cpp */; };
|
||||||
|
@ -80,6 +81,7 @@
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
1FCFA2892B2AF13C007EE2DF /* coolwsd-fork.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "coolwsd-fork.cpp"; sourceTree = "<group>"; };
|
||||||
3F3B54DB2A39288500063C01 /* HttpRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HttpRequest.cpp; sourceTree = "<group>"; };
|
3F3B54DB2A39288500063C01 /* HttpRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HttpRequest.cpp; sourceTree = "<group>"; };
|
||||||
3F3B54DC2A39288500063C01 /* HttpRequest.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = HttpRequest.hpp; sourceTree = "<group>"; };
|
3F3B54DC2A39288500063C01 /* HttpRequest.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = HttpRequest.hpp; sourceTree = "<group>"; };
|
||||||
3F3B54DE2A392C9C00063C01 /* NetUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetUtil.cpp; sourceTree = "<group>"; };
|
3F3B54DE2A392C9C00063C01 /* NetUtil.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetUtil.cpp; sourceTree = "<group>"; };
|
||||||
|
@ -2203,6 +2205,7 @@
|
||||||
BE5EB5B7213FE21600E0826C /* wsd */ = {
|
BE5EB5B7213FE21600E0826C /* wsd */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
1FCFA2892B2AF13C007EE2DF /* coolwsd-fork.cpp */,
|
||||||
BEBF3EAF246EB1C800415E87 /* RequestDetails.cpp */,
|
BEBF3EAF246EB1C800415E87 /* RequestDetails.cpp */,
|
||||||
BEBF3EAE246EB1C800415E87 /* RequestDetails.hpp */,
|
BEBF3EAE246EB1C800415E87 /* RequestDetails.hpp */,
|
||||||
BE5EB5CC213FE2D000E0826C /* ClientSession.cpp */,
|
BE5EB5CC213FE2D000E0826C /* ClientSession.cpp */,
|
||||||
|
@ -3653,6 +3656,7 @@
|
||||||
BEA28360214ACA8500848631 /* FakeSocket.cpp in Sources */,
|
BEA28360214ACA8500848631 /* FakeSocket.cpp in Sources */,
|
||||||
BE80E45821B68F5700859C97 /* TemplateCollectionViewController.mm in Sources */,
|
BE80E45821B68F5700859C97 /* TemplateCollectionViewController.mm in Sources */,
|
||||||
BE8D77352136762500AC58EA /* CODocument.mm in Sources */,
|
BE8D77352136762500AC58EA /* CODocument.mm in Sources */,
|
||||||
|
1FCFA28A2B2AF13F007EE2DF /* coolwsd-fork.cpp in Sources */,
|
||||||
BE5EB5C7213FE29900E0826C /* Protocol.cpp in Sources */,
|
BE5EB5C7213FE29900E0826C /* Protocol.cpp in Sources */,
|
||||||
BE8D772F2136762500AC58EA /* DocumentBrowserViewController.mm in Sources */,
|
BE8D772F2136762500AC58EA /* DocumentBrowserViewController.mm in Sources */,
|
||||||
BE9ADE3F265D046600BC034A /* TraceEvent.cpp in Sources */,
|
BE9ADE3F265D046600BC034A /* TraceEvent.cpp in Sources */,
|
||||||
|
|
|
@ -77,11 +77,6 @@ static std::map<pid_t, std::string> childJails;
|
||||||
/// The jails that need cleaning up. This should be small.
|
/// The jails that need cleaning up. This should be small.
|
||||||
static std::vector<std::string> cleanupJailPaths;
|
static std::vector<std::string> cleanupJailPaths;
|
||||||
|
|
||||||
#ifndef KIT_IN_PROCESS
|
|
||||||
int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
|
|
||||||
std::string MasterLocation;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern "C" { void dump_forkit_state(void); /* easy for gdb */ }
|
extern "C" { void dump_forkit_state(void); /* easy for gdb */ }
|
||||||
|
|
||||||
void dump_forkit_state()
|
void dump_forkit_state()
|
||||||
|
@ -490,7 +485,6 @@ void forkLibreOfficeKit(const std::string& childRoot,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KIT_IN_PROCESS
|
|
||||||
static void printArgumentHelp()
|
static void printArgumentHelp()
|
||||||
{
|
{
|
||||||
std::cout << "Usage: coolforkit [OPTION]..." << std::endl;
|
std::cout << "Usage: coolforkit [OPTION]..." << std::endl;
|
||||||
|
@ -500,7 +494,7 @@ static void printArgumentHelp()
|
||||||
std::cout << "" << std::endl;
|
std::cout << "" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int forkit_main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
/*WARNING: PRIVILEGED CODE CHECKING START */
|
/*WARNING: PRIVILEGED CODE CHECKING START */
|
||||||
|
|
||||||
|
@ -808,6 +802,5 @@ int main(int argc, char** argv)
|
||||||
LOG_INF("ForKit process finished.");
|
LOG_INF("ForKit process finished.");
|
||||||
Util::forcedExit(returnValue);
|
Util::forcedExit(returnValue);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
|
|
@ -151,6 +151,9 @@ void forkLibreOfficeKit(const std::string& childRoot,
|
||||||
const std::string& loTemplate,
|
const std::string& loTemplate,
|
||||||
int limit = 0);
|
int limit = 0);
|
||||||
|
|
||||||
|
/// main function of the forkit process or thread
|
||||||
|
int forkit_main(int argc, char** argv);
|
||||||
|
|
||||||
/// Anonymize the basename of filenames, preserving the path and extension.
|
/// Anonymize the basename of filenames, preserving the path and extension.
|
||||||
std::string anonymizeUrl(const std::string& url);
|
std::string anonymizeUrl(const std::string& url);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Copyright the Collabora Online contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
#include "Common.hpp"
|
||||||
|
#include "Kit.hpp"
|
||||||
|
|
||||||
|
int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
|
||||||
|
std::string MasterLocation;
|
||||||
|
|
||||||
|
int main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
return forkit_main(argc, argv);
|
||||||
|
}
|
|
@ -46,7 +46,8 @@ online_SOURCES = \
|
||||||
../wsd/COOLWSD.cpp \
|
../wsd/COOLWSD.cpp \
|
||||||
../wsd/RequestDetails.cpp \
|
../wsd/RequestDetails.cpp \
|
||||||
../wsd/Storage.cpp \
|
../wsd/Storage.cpp \
|
||||||
../wsd/TileCache.cpp
|
../wsd/TileCache.cpp \
|
||||||
|
../wsd/coolwsd-fork.cpp
|
||||||
|
|
||||||
online_DEPENDENCIES = \
|
online_DEPENDENCIES = \
|
||||||
@LOBUILDDIR@/instdir/program/soffice.html.linkdeps \
|
@LOBUILDDIR@/instdir/program/soffice.html.linkdeps \
|
||||||
|
|
|
@ -136,7 +136,7 @@ using Poco::Net::PartHandler;
|
||||||
#include <common/JsonUtil.hpp>
|
#include <common/JsonUtil.hpp>
|
||||||
#include <common/FileUtil.hpp>
|
#include <common/FileUtil.hpp>
|
||||||
#include <common/JailUtil.hpp>
|
#include <common/JailUtil.hpp>
|
||||||
#if defined KIT_IN_PROCESS || MOBILEAPP
|
#if MOBILEAPP
|
||||||
# include <Kit.hpp>
|
# include <Kit.hpp>
|
||||||
#endif
|
#endif
|
||||||
#include <Log.hpp>
|
#include <Log.hpp>
|
||||||
|
@ -398,31 +398,6 @@ void COOLWSD::writeTraceEventRecording(const std::string &recording)
|
||||||
writeTraceEventRecording(recording.data(), recording.length());
|
writeTraceEventRecording(recording.data(), recording.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !LIBFUZZER
|
|
||||||
// FIXME: Somewhat idiotically, the parameter to emitOneRecordingIfEnabled() should end with a
|
|
||||||
// newline, while the paramter to emitOneRecording() should not.
|
|
||||||
|
|
||||||
void TraceEvent::emitOneRecordingIfEnabled(const std::string &recording)
|
|
||||||
{
|
|
||||||
if (COOLWSD::TraceEventFile == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
COOLWSD::writeTraceEventRecording(recording);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TraceEvent::emitOneRecording(const std::string &recording)
|
|
||||||
{
|
|
||||||
if (COOLWSD::TraceEventFile == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!TraceEvent::isRecordingOn())
|
|
||||||
return;
|
|
||||||
|
|
||||||
COOLWSD::writeTraceEventRecording(recording + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //!LIBFUZZER
|
|
||||||
|
|
||||||
void COOLWSD::checkSessionLimitsAndWarnClients()
|
void COOLWSD::checkSessionLimitsAndWarnClients()
|
||||||
{
|
{
|
||||||
#if !ENABLE_SUPPORT_KEY
|
#if !ENABLE_SUPPORT_KEY
|
||||||
|
@ -3484,9 +3459,6 @@ void PrisonPoll::wakeupHook()
|
||||||
|
|
||||||
bool COOLWSD::createForKit()
|
bool COOLWSD::createForKit()
|
||||||
{
|
{
|
||||||
#if defined KIT_IN_PROCESS
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
LOG_INF("Creating new forkit process.");
|
LOG_INF("Creating new forkit process.");
|
||||||
|
|
||||||
// Creating a new forkit is always a slow process.
|
// Creating a new forkit is always a slow process.
|
||||||
|
@ -3574,6 +3546,8 @@ bool COOLWSD::createForKit()
|
||||||
// Always reap first, in case we haven't done so yet.
|
// Always reap first, in case we haven't done so yet.
|
||||||
if (ForKitProcId != -1)
|
if (ForKitProcId != -1)
|
||||||
{
|
{
|
||||||
|
if (Util::isKitInProcess())
|
||||||
|
return true;
|
||||||
int status;
|
int status;
|
||||||
waitpid(ForKitProcId, &status, WUNTRACED | WNOHANG);
|
waitpid(ForKitProcId, &status, WUNTRACED | WNOHANG);
|
||||||
ForKitProcId = -1;
|
ForKitProcId = -1;
|
||||||
|
@ -3590,7 +3564,7 @@ bool COOLWSD::createForKit()
|
||||||
LOG_INF("Launching forkit process: " << forKitPath << ' ' << args.cat(' ', 0));
|
LOG_INF("Launching forkit process: " << forKitPath << ' ' << args.cat(' ', 0));
|
||||||
|
|
||||||
LastForkRequestTime = std::chrono::steady_clock::now();
|
LastForkRequestTime = std::chrono::steady_clock::now();
|
||||||
int child = Util::spawnProcess(forKitPath, args);
|
int child = createForkit(forKitPath, args);
|
||||||
ForKitProcId = child;
|
ForKitProcId = child;
|
||||||
|
|
||||||
LOG_INF("Forkit process launched: " << ForKitProcId);
|
LOG_INF("Forkit process launched: " << ForKitProcId);
|
||||||
|
@ -3603,7 +3577,6 @@ bool COOLWSD::createForKit()
|
||||||
rebalanceChildren(balance);
|
rebalanceChildren(balance);
|
||||||
|
|
||||||
return ForKitProcId != -1;
|
return ForKitProcId != -1;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void COOLWSD::sendMessageToForKit(const std::string& message)
|
void COOLWSD::sendMessageToForKit(const std::string& message)
|
||||||
|
|
|
@ -656,4 +656,8 @@ public:
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !MOBILEAPP
|
||||||
|
int createForkit(const std::string& forKitPath, const StringVector& args);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright the Collabora Online contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
#include "StringVector.hpp"
|
||||||
|
#include "Util.hpp"
|
||||||
|
#include "TraceEvent.hpp"
|
||||||
|
#include "COOLWSD.hpp"
|
||||||
|
|
||||||
|
#if !MOBILEAPP
|
||||||
|
int createForkit(const std::string& forKitPath, const StringVector& args)
|
||||||
|
{
|
||||||
|
// create forkit in a process
|
||||||
|
return Util::spawnProcess(forKitPath, args);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// FIXME: Somewhat idiotically, the parameter to emitOneRecordingIfEnabled() should end with a
|
||||||
|
// newline, while the paramter to emitOneRecording() should not.
|
||||||
|
|
||||||
|
void TraceEvent::emitOneRecordingIfEnabled(const std::string& recording)
|
||||||
|
{
|
||||||
|
if (COOLWSD::TraceEventFile == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
COOLWSD::writeTraceEventRecording(recording);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TraceEvent::emitOneRecording(const std::string& recording)
|
||||||
|
{
|
||||||
|
if (COOLWSD::TraceEventFile == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!TraceEvent::isRecordingOn())
|
||||||
|
return;
|
||||||
|
|
||||||
|
COOLWSD::writeTraceEventRecording(recording + "\n");
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright the Collabora Online contributors.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
#include "StringVector.hpp"
|
||||||
|
#include "Util.hpp"
|
||||||
|
#include "COOLWSD.hpp"
|
||||||
|
#include "Kit.hpp"
|
||||||
|
|
||||||
|
int createForkit(const std::string& forKitPath, const StringVector& args)
|
||||||
|
{
|
||||||
|
// create forkit in a thread
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue