diff --git a/Makefile.am b/Makefile.am index 3eee237c02691..c91b5ebdf5620 100644 --- a/Makefile.am +++ b/Makefile.am @@ -506,6 +506,14 @@ run-trace: setup-wsd --o:trace[@enable]=true --o:trace.path=${builddir}/trace.txt.gz \ --o:trace.outgoing.record=false +if ENABLE_KITINPROCESS +run-valgrind-kitinprocess: setup-wsd + @echo "Launching coolwsd under valgrind (but not forkit/coolkit, yet)" + valgrind --tool=memcheck --tool=massif --trace-children=no -v --read-var-info=yes \ + ./coolwsd $(COMMON_PARAMS) \ + --o:logging.file[@enable]=false --o:logging.level=error +endif + run-valgrind: setup-wsd @echo "Launching coolwsd under valgrind (but not forkit/coolkit, yet)" valgrind --tool=memcheck --trace-children=no -v --read-var-info=yes \ diff --git a/common/Util.cpp b/common/Util.cpp index 1afb88bfbccb0..844d928480c62 100644 --- a/common/Util.cpp +++ b/common/Util.cpp @@ -1006,6 +1006,15 @@ namespace Util #endif } + bool isKitInProcess() + { +#if KITINPROCESS + return true; +#else + return false; +#endif + } + std::map stringVectorToMap(const std::vector& strvector, const char delimiter) { std::map result; diff --git a/common/Util.hpp b/common/Util.hpp index 4c0295318daa0..0e0798c3247fa 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -1300,6 +1300,8 @@ int main(int argc, char**argv) */ bool isFuzzing(); + bool isKitInProcess(); + /** * Splits string into vector. Does not accept referenced variables for easy * usage like (splitString("test", ..)) or (splitString(getStringOnTheFly(), ..)) diff --git a/config.h.in b/config.h.in index 131346513cb4a..a20c5e3b77155 100644 --- a/config.h.in +++ b/config.h.in @@ -73,6 +73,8 @@ /* Define to 1 if this is a libfuzzer build. */ #undef LIBFUZZER +#undef KITINPROCESS + /* Default value of feature_lock.locked_commands */ #undef LOCKED_COMMANDS diff --git a/configure.ac b/configure.ac index 727278ac9aaa5..4fc54d0297d89 100644 --- a/configure.ac +++ b/configure.ac @@ -192,6 +192,10 @@ AC_ARG_ENABLE([androidapp], to work similarly to the iOS app, from the JavaScript and the pseudo WebSocket message plumbing point of view.])) +AC_ARG_ENABLE([kitinprocess], + AS_HELP_STRING([--enable-kitinprocess], + [Enable kit in process])) + AC_ARG_ENABLE([android-google-play], AS_HELP_STRING([--enable-android-google-play], [When enabled, the app encourages the user periodically to rate the app on Google Play Store.])) @@ -408,6 +412,7 @@ AS_IF([test "$enable_debug" = yes -a -n "$with_poco_libs"], [POCO_DEBUG_SUFFIX=]) ENABLE_DEBUG=false +ENABLE_KITINPROCESS=false ENABLE_DEBUG_PROTOCOL=false ENABLE_BUNDLE=true COOLWSD_LOGLEVEL="warning" @@ -454,6 +459,16 @@ if test "$enable_debug" = "yes"; then else AC_MSG_RESULT([no (to enable --enable-logging-test-asserts)]) fi + + AC_MSG_CHECKING([whether to enable kit in process (default)]) + if test "$enable_kitinprocess" = "yes"; then + KITINPROCESS=true + AC_DEFINE([KITINPROCESS],1,[Kit in process is enabled]) + else + KITINPROCESS=false + AC_DEFINE([ENABLE_DEBUG],0,[Kit in process is disabled]) + + fi else AC_MSG_RESULT([no (Release build)]) AC_DEFINE([ENABLE_DEBUG],0,[Whether to compile in some extra debugging support code and disable some security pieces]) @@ -464,6 +479,8 @@ AC_SUBST(COOLWSD_LOGLEVEL) AC_SUBST(COOLWSD_LOG_TO_FILE) AC_SUBST(BROWSER_LOGGING) +AM_CONDITIONAL([ENABLE_KITINPROCESS], [test "$KITINPROCESS" = "true"]) + if test "$enable_debug_protocol" = no; then ENABLE_DEBUG_PROTOCOL=false fi diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp index ca8eabe6ebd92..014a956df7fe6 100644 --- a/kit/ForKit.cpp +++ b/kit/ForKit.cpp @@ -548,7 +548,9 @@ int main(int argc, char** argv) } } - SigUtil::setFatalSignals("forkit startup of " COOLWSD_VERSION " " COOLWSD_VERSION_HASH); + if (!Util::isKitInProcess()) { + SigUtil::setFatalSignals("forkit startup of " COOLWSD_VERSION " " COOLWSD_VERSION_HASH); + } if (simd::init()) simd_deltaInit(); diff --git a/kit/Kit.cpp b/kit/Kit.cpp index ebd703d32a74c..caccb8041cf70 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -2784,8 +2784,9 @@ void lokit_main( ) { #if !MOBILEAPP - - SigUtil::setFatalSignals("kit startup of " COOLWSD_VERSION " " COOLWSD_VERSION_HASH); + if (!Util::isKitInProcess()) { + SigUtil::setFatalSignals("kit startup of " COOLWSD_VERSION " " COOLWSD_VERSION_HASH); + } SigUtil::setUserSignals(); Util::setThreadName("kit_spare_" + Util::encodeId(numericIdentifier, 3)); diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 65aa3b2c51eae..b729694c16ca8 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -1121,13 +1121,15 @@ bool DocumentBroker::download(const std::shared_ptr& session, con if (inputs != 1 || outputs != 1) throw std::exception(); - int process = Util::spawnProcess(command, args); - int status = -1; - const int rc = ::waitpid(process, &status, 0); - if (rc != 0) - { - LOG_ERR("Conversion from " << extension << " to " << newExtension << " failed (" << rc << ")."); - return false; + if (!Util::isKitInProcess()) { + int process = Util::spawnProcess(command, args); + int status = -1; + const int rc = ::waitpid(process, &status, 0); + if (rc != 0) + { + LOG_ERR("Conversion from " << extension << " to " << newExtension << " failed (" << rc << ")."); + return false; + } } _storage->setRootFilePath(newRootPath);