Index: remoting/host/host_service_win.cc |
diff --git a/remoting/host/host_service_win.cc b/remoting/host/host_service_win.cc |
index ef42a7d3237437de9f31dd8ac301a479e274f003..70b9de4acd99c95c1d53a0ccc1d7e90067f3bfd3 100644 |
--- a/remoting/host/host_service_win.cc |
+++ b/remoting/host/host_service_win.cc |
@@ -15,7 +15,7 @@ |
#include "base/base_paths.h" |
#include "base/bind.h" |
#include "base/command_line.h" |
-#include "base/file_path.h" |
+#include "base/file_util.h" |
#include "base/logging.h" |
#include "base/message_loop.h" |
#include "base/path_service.h" |
@@ -38,6 +38,8 @@ const char kServiceName[] = "chromoting"; |
const char kMuiStringFormat[] = "@%ls,-%d"; |
const char kServiceDependencies[] = ""; |
+const char kServiceCommandLineFormat[] = "\"%ls\" --host-binary=\"%ls\""; |
+ |
const DWORD kServiceStopTimeoutMs = 30 * 1000; |
// Session id that does not represent any session. |
@@ -60,6 +62,9 @@ const char kRemoveActionName[] = "remove"; |
// "--console" runs the service interactively for debugging purposes. |
const char kConsoleSwitchName[] = "console"; |
+// "--host-binary" specifies the host bonary to run in console session. |
Wez
2012/02/28 00:22:07
typo: binary
alexeypa (please no reviews)
2012/02/28 01:14:04
Done.
|
+const char kHostBinarySwitchName[] = "host-binary"; |
+ |
// "--help" or "--?" prints the usage message. |
const char kHelpSwitchName[] = "help"; |
const char kQuestionSwitchName[] = "?"; |
@@ -69,13 +74,14 @@ const char kUsageMessage[] = |
"Usage: %s [action] [options]\n" |
"\n" |
"Actions:\n" |
- " run - Run the service. If no action specified 'run' is assumed.\n" |
- " install - Install the service.\n" |
- " remove - Uninstall the service.\n" |
+ " run - Run the service (default if no action was specified).\n" |
+ " install - Install the service.\n" |
+ " remove - Uninstall the service.\n" |
"\n" |
"Options:\n" |
- " --console - Run the service interactively for debugging purposes.\n" |
- " --help, --? - Print this message.\n"; |
+ " --console - Run the service interactively for debugging purposes.\n" |
+ " --host-binary - Specifies the host binary to run in the console session.\n" |
+ " --help, --? - Print this message.\n"; |
// Exit codes: |
const int kSuccessExitCode = 0; |
@@ -163,6 +169,7 @@ bool HostService::InitWithCommandLine(const CommandLine* command_line) { |
CommandLine::StringVector args = command_line->GetArgs(); |
// Choose the action to perform. |
+ bool host_binary_required = true; |
if (!args.empty()) { |
if (args.size() > 1) { |
LOG(ERROR) << "Invalid command line: more than one action requested."; |
@@ -172,6 +179,7 @@ bool HostService::InitWithCommandLine(const CommandLine* command_line) { |
run_routine_ = &HostService::Install; |
} else if (args[0] == ASCIIToUTF16(kRemoveActionName)) { |
run_routine_ = &HostService::Remove; |
+ host_binary_required = false; |
} else if (args[0] != ASCIIToUTF16(kRunActionName)) { |
LOG(ERROR) << "Invalid command line: invalid action specified: " |
<< args[0]; |
@@ -179,6 +187,14 @@ bool HostService::InitWithCommandLine(const CommandLine* command_line) { |
} |
} |
+ if (command_line->HasSwitch(kHostBinarySwitchName)) { |
+ host_binary_ = command_line->GetSwitchValuePath(kHostBinarySwitchName); |
+ } else if (host_binary_required) { |
Wez
2012/02/28 00:22:07
nit: I think this would be clearer as:
if (host_b
alexeypa (please no reviews)
2012/02/28 01:14:04
Done.
|
+ LOG(ERROR) << "Invalid command line: --" << kHostBinarySwitchName |
+ << " is required."; |
Wez
2012/02/28 00:22:07
nit: Indentation.
alexeypa (please no reviews)
2012/02/28 01:14:04
This is how C++ style guide recommends to indent '
Wez
2012/02/28 22:55:36
Yes, but LOG() is mis-indented.
alexeypa (please no reviews)
2012/02/29 04:17:56
Oh, I see. My autopilot fixed it, apparently. :-)
|
+ return false; |
+ } |
+ |
// Run interactively if needed. |
if (run_routine_ == &HostService::RunAsService && |
command_line->HasSwitch(kConsoleSwitchName)) { |
@@ -207,6 +223,17 @@ int HostService::Install() { |
string16 name = StringPrintf(ASCIIToUTF16(kMuiStringFormat).c_str(), |
exe.value().c_str(), |
IDS_DISPLAY_SERVICE_NAME); |
+ |
+ if (!file_util::AbsolutePath(&host_binary_) || |
+ !file_util::PathExists(host_binary_)) { |
+ LOG(ERROR) << "Invalid host binary name: " << host_binary_.value(); |
+ return kErrorExitCode; |
+ } |
+ |
+ string16 command_line = StringPrintf( |
+ ASCIIToUTF16(kServiceCommandLineFormat).c_str(), |
+ exe.value().c_str(), |
+ host_binary_.value().c_str()); |
ScopedScHandle service( |
CreateServiceW(scmanager, |
service_name_.c_str(), |
@@ -214,7 +241,7 @@ int HostService::Install() { |
SERVICE_QUERY_STATUS | SERVICE_CHANGE_CONFIG, |
SERVICE_WIN32_OWN_PROCESS, |
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, |
- exe.value().c_str(), |
+ command_line.c_str(), |
NULL, |
NULL, |
ASCIIToUTF16(kServiceDependencies).c_str(), |
@@ -322,7 +349,7 @@ int HostService::Run() { |
} |
void HostService::RunMessageLoop() { |
- WtsSessionProcessLauncher launcher(this); |
+ WtsSessionProcessLauncher launcher(this, host_binary_); |
// Run the service. |
message_loop_->Run(); |