Commit 47102172 authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Disable Me2Me host controls on unsupported Linux systems.

Currently a system is considered to be supported in three cases:
 1. ~/.chrome-remote-desktop-session file exists.
 2. ~/.config/chrome-remote-desktop directory exists.
 3. DISTRIB_ID=Ubuntu is set in /etc/lsb-release

BUG=149744
R=lambroslambrou@chromium.org

Review URL: https://codereview.chromium.org/159753008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251485 0039d316-1c4b-4281-b951-d872f2087c98
parent b197af86
...@@ -114,8 +114,7 @@ bool RunHostScriptWithTimeout( ...@@ -114,8 +114,7 @@ bool RunHostScriptWithTimeout(
return true; return true;
} }
bool RunHostScript(const std::vector<std::string>& args, bool RunHostScript(const std::vector<std::string>& args, int* exit_code) {
int* exit_code) {
return RunHostScriptWithTimeout( return RunHostScriptWithTimeout(
args, base::TimeDelta::FromMilliseconds(kDaemonTimeoutMs), exit_code); args, base::TimeDelta::FromMilliseconds(kDaemonTimeoutMs), exit_code);
} }
...@@ -129,20 +128,43 @@ DaemonControllerDelegateLinux::~DaemonControllerDelegateLinux() { ...@@ -129,20 +128,43 @@ DaemonControllerDelegateLinux::~DaemonControllerDelegateLinux() {
} }
DaemonController::State DaemonControllerDelegateLinux::GetState() { DaemonController::State DaemonControllerDelegateLinux::GetState() {
std::vector<std::string> args; base::FilePath script_path;
args.push_back("--check-running"); if (!GetScriptPath(&script_path)) {
return DaemonController::STATE_NOT_IMPLEMENTED;
}
CommandLine command_line(script_path);
command_line.AppendArg("--get-status");
std::string status;
int exit_code = 0; int exit_code = 0;
if (!RunHostScript(args, &exit_code)) { bool result =
base::GetAppOutputWithExitCode(command_line, &status, &exit_code);
if (!result) {
// TODO(jamiewalch): When we have a good story for installing, return // TODO(jamiewalch): When we have a good story for installing, return
// NOT_INSTALLED rather than NOT_IMPLEMENTED (the former suppresses // NOT_INSTALLED rather than NOT_IMPLEMENTED (the former suppresses
// the relevant UI in the web-app). // the relevant UI in the web-app).
return DaemonController::STATE_NOT_IMPLEMENTED; return DaemonController::STATE_NOT_IMPLEMENTED;
} }
if (exit_code == 0) { if (exit_code != 0) {
LOG(ERROR) << "Failed to run \"" << command_line.GetCommandLineString()
<< "\". Exit code: " << exit_code;
return DaemonController::STATE_UNKNOWN;
}
TrimWhitespaceASCII(status, TRIM_ALL, &status);
if (status == "STARTED") {
return DaemonController::STATE_STARTED; return DaemonController::STATE_STARTED;
} else { } else if (status == "STOPPED") {
return DaemonController::STATE_STOPPED; return DaemonController::STATE_STOPPED;
} else if (status == "NOT_IMPLEMENTED") {
return DaemonController::STATE_NOT_IMPLEMENTED;
} else {
LOG(ERROR) << "Unknown status string returned from \""
<< command_line.GetCommandLineString()
<< "\": " << status;
return DaemonController::STATE_UNKNOWN;
} }
} }
......
...@@ -21,6 +21,7 @@ import optparse ...@@ -21,6 +21,7 @@ import optparse
import os import os
import pipes import pipes
import psutil import psutil
import platform
import signal import signal
import socket import socket
import subprocess import subprocess
...@@ -52,8 +53,9 @@ else: ...@@ -52,8 +53,9 @@ else:
CHROME_REMOTING_GROUP_NAME = "chrome-remote-desktop" CHROME_REMOTING_GROUP_NAME = "chrome-remote-desktop"
CONFIG_DIR = os.path.expanduser("~/.config/chrome-remote-desktop")
HOME_DIR = os.environ["HOME"] HOME_DIR = os.environ["HOME"]
CONFIG_DIR = os.path.join(HOME_DIR, ".config/chrome-remote-desktop")
SESSION_FILE_PATH = os.path.join(HOME_DIR, ".chrome-remote-desktop-session")
X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock" X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock"
FIRST_X_DISPLAY_NUMBER = 20 FIRST_X_DISPLAY_NUMBER = 20
...@@ -75,6 +77,16 @@ MAX_LAUNCH_FAILURES = SHORT_BACKOFF_THRESHOLD + 10 ...@@ -75,6 +77,16 @@ MAX_LAUNCH_FAILURES = SHORT_BACKOFF_THRESHOLD + 10
g_desktops = [] g_desktops = []
g_host_hash = hashlib.md5(socket.gethostname()).hexdigest() g_host_hash = hashlib.md5(socket.gethostname()).hexdigest()
def is_supported_platform():
# Always assume that the system is supported if the config directory or
# session file exist.
if os.path.isdir(CONFIG_DIR) or os.path.isfile(SESSION_FILE_PATH):
return True
# The host has been tested only on Ubuntu.
distribution = platform.linux_distribution()
return (distribution[0]).lower() == 'ubuntu'
class Config: class Config:
def __init__(self, path): def __init__(self, path):
self.path = path self.path = path
...@@ -502,7 +514,7 @@ def choose_x_session(): ...@@ -502,7 +514,7 @@ def choose_x_session():
# session instead of looking for custom .xsession files in the home directory. # session instead of looking for custom .xsession files in the home directory.
# So it's necessary to test for these files here. # So it's necessary to test for these files here.
XSESSION_FILES = [ XSESSION_FILES = [
"~/.chrome-remote-desktop-session", SESSION_FILE_PATH,
"~/.xsession", "~/.xsession",
"~/.Xsession" ] "~/.Xsession" ]
for startup_file in XSESSION_FILES: for startup_file in XSESSION_FILES:
...@@ -902,6 +914,9 @@ Web Store: https://chrome.google.com/remotedesktop""" ...@@ -902,6 +914,9 @@ Web Store: https://chrome.google.com/remotedesktop"""
parser.add_option("-k", "--stop", dest="stop", default=False, parser.add_option("-k", "--stop", dest="stop", default=False,
action="store_true", action="store_true",
help="Stop the daemon currently running.") help="Stop the daemon currently running.")
parser.add_option("", "--get-status", dest="get_status", default=False,
action="store_true",
help="Prints host status")
parser.add_option("", "--check-running", dest="check_running", default=False, parser.add_option("", "--check-running", dest="check_running", default=False,
action="store_true", action="store_true",
help="Return 0 if the daemon is running, or 1 otherwise.") help="Return 0 if the daemon is running, or 1 otherwise.")
...@@ -923,6 +938,19 @@ Web Store: https://chrome.google.com/remotedesktop""" ...@@ -923,6 +938,19 @@ Web Store: https://chrome.google.com/remotedesktop"""
options.config = os.path.join(CONFIG_DIR, "host#%s.json" % g_host_hash) options.config = os.path.join(CONFIG_DIR, "host#%s.json" % g_host_hash)
# Check for a modal command-line option (start, stop, etc.) # Check for a modal command-line option (start, stop, etc.)
if options.get_status:
pid = get_daemon_pid()
if pid != 0:
print "STARTED"
elif is_supported_platform():
print "STOPPED"
else:
print "NOT_IMPLEMENTED"
return 0
# TODO(sergeyu): Remove --check-running once NPAPI plugin and NM host are
# updated to always use get-status flag instead.
if options.check_running: if options.check_running:
pid = get_daemon_pid() pid = get_daemon_pid()
return 0 if pid != 0 else 1 return 0 if pid != 0 else 1
......
...@@ -305,7 +305,8 @@ remoting.HostList.prototype.display = function() { ...@@ -305,7 +305,8 @@ remoting.HostList.prototype.display = function() {
var enabled = (state == remoting.HostController.State.STARTING) || var enabled = (state == remoting.HostController.State.STARTING) ||
(state == remoting.HostController.State.STARTED); (state == remoting.HostController.State.STARTED);
var canChangeLocalHostState = var canChangeLocalHostState =
(state != remoting.HostController.State.NOT_IMPLEMENTED) && (state != remoting.HostController.State.NOT_IMPLEMENTED &&
state != remoting.HostController.State.UNKNOWN) &&
(enabled || this.lastError_ == ''); (enabled || this.lastError_ == '');
remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment