Skip to content

Commit

Permalink
WIP : Add KIT in process mode
Browse files Browse the repository at this point in the history
 - have a mode KITINPROCESS (limited to --enable-debug) where everything is running as a single process
 - global function that will know if we're in kit-in-process mode,=> Util::isKitInProcess()
Signed-off-by: Darshan-upadhyay1110 <[email protected]>

Change-Id: I153bdeed50e86c9a97a60591f2644eb6b4c51f00
Signed-off-by: Darshan-upadhyay1110 <[email protected]>
  • Loading branch information
Darshan-upadhyay1110 committed Sep 29, 2023
1 parent 5520965 commit 54ad034
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 10 deletions.
8 changes: 8 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
9 changes: 9 additions & 0 deletions common/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,15 @@ namespace Util
#endif
}

bool isKitInProcess()
{
#if KITINPROCESS
return true;
#else
return false;
#endif
}

std::map<std::string, std::string> stringVectorToMap(const std::vector<std::string>& strvector, const char delimiter)
{
std::map<std::string, std::string> result;
Expand Down
2 changes: 2 additions & 0 deletions common/Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,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(), ..))
Expand Down
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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.]))
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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])
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion kit/ForKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions kit/Kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
16 changes: 9 additions & 7 deletions wsd/DocumentBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,13 +1121,15 @@ bool DocumentBroker::download(const std::shared_ptr<ClientSession>& 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);
Expand Down

0 comments on commit 54ad034

Please sign in to comment.