[Libreoffice-commits] online.git: Branch 'private/hcvcastro/forking' - loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/Makefile.am
Michael Meeks
michael.meeks at collabora.com
Mon Aug 17 09:11:05 PDT 2015
loolwsd/LOOLBroker.cpp | 32 ++++++++------------------------
loolwsd/LOOLKit.cpp | 21 +++++----------------
loolwsd/Makefile.am | 6 ++++--
3 files changed, 17 insertions(+), 42 deletions(-)
New commits:
commit d5d779408875fa4ade641b5cd5d35dff82ae71bf
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Mon Aug 17 17:20:27 2015 +0100
Cleanup arg. parsing, kill code duplication.
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 809bc9a..616b95a 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -38,7 +38,7 @@
// we can avoid execve and share lots of memory here. We
// can't link to a non-PIC translation unit though, so
// include to share.
-#define LOOKIT_NO_MAIN 1
+#define LOOLKIT_NO_MAIN 1
#include "LOOLKit.cpp"
#define INTERVAL_PROBES 10
@@ -219,16 +219,6 @@ namespace
static std::map<Poco::Process::PID, Poco::UInt64> _childProcesses;
-
-static int prefixcmp(const char *str, const char *prefix)
-{
- for (; ; str++, prefix++)
- if (!*prefix)
- return 0;
- else if (*str != *prefix)
- return (unsigned char)*prefix - (unsigned char)*str;
-}
-
/// Initializes LibreOfficeKit for cross-fork re-use.
static bool globalPreinit()
{
@@ -276,46 +266,40 @@ int main(int argc, char** argv)
int _numPreSpawnedChildren = 0;
Poco::SharedMemory _sharedForkChild("loolwsd", sizeof(bool), Poco::SharedMemory::AM_WRITE);
- while (argc > 0)
+ for (int i = 0; i < argc; ++i)
{
- char *cmd = argv[0];
+ char *cmd = argv[i];
char *eq = NULL;
- if (strstr(cmd, "loolbroker"))
- {
- }
- if (!prefixcmp(cmd, "--losubpath="))
+ if (strstr(cmd, "--losubpath=") == cmd)
{
eq = strchrnul(cmd, '=');
if (*eq)
loSubPath = std::string(++eq);
}
- else if (!prefixcmp(cmd, "--systemplate="))
+ else if (strstr(cmd, "--systemplate=") == cmd)
{
eq = strchrnul(cmd, '=');
if (*eq)
sysTemplate = std::string(++eq);
}
- else if (!prefixcmp(cmd, "--lotemplate="))
+ else if (strstr(cmd, "--lotemplate=") == cmd)
{
eq = strchrnul(cmd, '=');
if (*eq)
loTemplate = std::string(++eq);
}
- else if (!prefixcmp(cmd, "--childroot="))
+ else if (strstr(cmd, "--childroot=") == cmd)
{
eq = strchrnul(cmd, '=');
if (*eq)
childRoot = std::string(++eq);
}
- else if (!prefixcmp(cmd, "--numprespawns="))
+ else if (strstr(cmd, "--numprespawns=") == cmd)
{
eq = strchrnul(cmd, '=');
if (*eq)
_numPreSpawnedChildren = std::stoi(std::string(++eq));
}
-
- argv++;
- argc--;
}
if (loSubPath.empty())
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 8315440..a4c9a0c 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -80,15 +80,6 @@ private:
tsqueue<std::string>& _queue;
};
-static int prefixcmp(const char *str, const char *prefix)
-{
- for (; ; str++, prefix++)
- if (!*prefix)
- return 0;
- else if (*str != *prefix)
- return (unsigned char)*prefix - (unsigned char)*str;
-}
-
const int MASTER_PORT_NUMBER = 9981;
const std::string CHILD_URI = "/loolws/child/";
@@ -184,7 +175,7 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId)
std::cout << Util::logPrefix() << "loolkit finished OK!" << std::endl;
}
-#ifdef LOOLKIT_NO_MAIN
+#ifndef LOOLKIT_NO_MAIN
/// Simple argument parsing wrapper / helper for the above.
int main(int argc, char** argv)
@@ -192,24 +183,22 @@ int main(int argc, char** argv)
std::string loSubPath;
Poco::UInt64 _childId = 0;
- while (argc > 0)
+ for (int i = 1; i < argc; ++i)
{
- char *cmd = argv[0];
+ char *cmd = argv[i];
char *eq = NULL;
- if (!prefixcmp(cmd, "--losubpath="))
+ if (strstr(cmd, "--losubpath=") == cmd)
{
eq = strchrnul(cmd, '=');
if (*eq)
loSubPath = std::string(++eq);
}
- else if (!prefixcmp(cmd, "--child="))
+ else if (strstr(cmd, "--child=") == cmd)
{
eq = strchrnul(cmd, '=');
if (*eq)
_childId = std::stoll(std::string(++eq));
}
- argv++;
- argc--;
}
if (loSubPath.empty())
diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am
index e15962a..d17ba39 100644
--- a/loolwsd/Makefile.am
+++ b/loolwsd/Makefile.am
@@ -4,9 +4,11 @@ dist_bin_SCRIPTS = loolwsd-systemplate-setup
loolwsd_SOURCES = LOOLWSD.cpp LOOLSession.cpp MasterProcessSession.cpp TileCache.cpp Util.cpp LOOLProtocol.cpp
-loolkit_SOURCES = LOOLKit.cpp LOOLSession.cpp ChildProcessSession.cpp Util.cpp LOOLProtocol.cpp
+broker_shared_sources = ChildProcessSession.cpp Util.cpp LOOLProtocol.cpp LOOLSession.cpp
-loolbroker_SOURCES = LOOLBroker.cpp Util.cpp
+loolkit_SOURCES = LOOLKit.cpp $(broker_shared_sources)
+
+loolbroker_SOURCES = LOOLBroker.cpp $(broker_shared_sources)
loolmap_SOURCES = loolmap.c
More information about the Libreoffice-commits
mailing list