From 83fe340b98cefdc441c213d8704575a29db05285 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 19 Jun 2015 22:56:10 +0800 Subject: [PATCH] Make process.argv work with zygote --- atom/app/atom_main_args.cc | 11 ++++++++++- atom/app/atom_main_args.h | 8 +++++++- atom/common/node_bindings.cc | 6 ++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/atom/app/atom_main_args.cc b/atom/app/atom_main_args.cc index b9ef7c43a34b..ac1c96c1bcaf 100644 --- a/atom/app/atom_main_args.cc +++ b/atom/app/atom_main_args.cc @@ -3,7 +3,9 @@ // found in the LICENSE file. #include "atom/app/atom_main_args.h" -#include "vendor/node/deps/uv/include/uv.h" + +#include "base/command_line.h" +#include "node/deps/uv/include/uv.h" namespace atom { @@ -19,4 +21,11 @@ void AtomCommandLine::Init(int argc, const char* const* argv) { } } +#if defined(OS_LINUX) +// static +void AtomCommandLine::InitializeFromCommandLine() { + argv_ = base::CommandLine::ForCurrentProcess()->argv(); +} +#endif + } // namespace atom diff --git a/atom/app/atom_main_args.h b/atom/app/atom_main_args.h index c3bc0a9823dc..5dd42713c65a 100644 --- a/atom/app/atom_main_args.h +++ b/atom/app/atom_main_args.h @@ -8,7 +8,7 @@ #include #include -#include "base/macros.h" +#include "base/basictypes.h" namespace atom { @@ -18,6 +18,12 @@ class AtomCommandLine { static void Init(int argc, const char* const* argv); static std::vector argv() { return argv_; } +#if defined(OS_LINUX) + // On Linux the command line has to be read from base::CommandLine since + // it is using zygote. + static void InitializeFromCommandLine(); +#endif + private: static std::vector argv_; diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index eb627d06b757..ff1d646c4d34 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -128,6 +128,12 @@ void NodeBindings::Initialize() { node::g_standalone_mode = is_browser_; node::g_upstream_node_mode = false; +#if defined(OS_LINUX) + // Get real command line in renderer process forked by zygote. + if (!is_browser_) + AtomCommandLine::InitializeFromCommandLine(); +#endif + // Parse the debug args. auto args = AtomCommandLine::argv(); for (const std::string& arg : args)