summaryrefslogtreecommitdiffstats
path: root/remoting/tools
diff options
context:
space:
mode:
authorlambroslambrou@google.com <lambroslambrou@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-11 02:26:12 +0000
committerlambroslambrou@google.com <lambroslambrou@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-11 02:26:12 +0000
commit31036040888bf17e2d0c5a4bc9c977b501cfb93a (patch)
tree20c4eb2cdadba09a165888ed793c1d3b251459e8 /remoting/tools
parent4636c837d247f6fa7d4982160643f39d752c2ed5 (diff)
downloadchromium_src-31036040888bf17e2d0c5a4bc9c977b501cfb93a.zip
chromium_src-31036040888bf17e2d0c5a4bc9c977b501cfb93a.tar.gz
chromium_src-31036040888bf17e2d0c5a4bc9c977b501cfb93a.tar.bz2
Improve error log when failed to load config
This replaces the undefined "config_filename" error with a better message indicating the cause of the error when loading the config. BUG=167817 NOTRY=true Review URL: https://codereview.chromium.org/11711004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/tools')
-rwxr-xr-xremoting/tools/me2me_virtual_host.py59
1 files changed, 38 insertions, 21 deletions
diff --git a/remoting/tools/me2me_virtual_host.py b/remoting/tools/me2me_virtual_host.py
index b941e81..291509f 100755
--- a/remoting/tools/me2me_virtual_host.py
+++ b/remoting/tools/me2me_virtual_host.py
@@ -73,29 +73,41 @@ class Config:
self.changed = False
def load(self):
- try:
- settings_file = open(self.path, 'r')
- self.data = json.load(settings_file)
- self.changed = False
- settings_file.close()
- except Exception:
- return False
- return True
+ """Loads the config from file.
+
+ Raises:
+ IOError: Error reading data
+ ValueError: Error parsing JSON
+ """
+ settings_file = open(self.path, 'r')
+ self.data = json.load(settings_file)
+ self.changed = False
+ settings_file.close()
def save(self):
+ """Saves the config to file.
+
+ Raises:
+ IOError: Error writing data
+ TypeError: Error serialising JSON
+ """
if not self.changed:
- return True
+ return
old_umask = os.umask(0066)
try:
settings_file = open(self.path, 'w')
settings_file.write(json.dumps(self.data, indent=2))
settings_file.close()
- except Exception:
- return False
+ self.changed = False
finally:
os.umask(old_umask)
- self.changed = False
- return True
+
+ def save_and_log_errors(self):
+ """Calls save(self), trapping and logging any errors."""
+ try:
+ save(self)
+ except (IOError, TypeError) as e:
+ logging.error("Failed to save config: " + str(e))
def get(self, key):
return self.data.get(key)
@@ -625,7 +637,10 @@ class SignalHandler:
def __call__(self, signum, _stackframe):
if signum == signal.SIGHUP:
logging.info("SIGHUP caught, restarting host.")
- self.host_config.load()
+ try:
+ self.host_config.load()
+ except (IOError, ValueError) as e:
+ logging.error("Failed to load config: " + str(e))
for desktop in g_desktops:
if desktop.host_proc:
desktop.host_proc.send_signal(signal.SIGTERM)
@@ -867,8 +882,10 @@ Web Store: https://chrome.google.com/remotedesktop"""
# Load the initial host configuration.
host_config = Config(options.config)
- if (not host_config.load()):
- print >> sys.stderr, "Failed to load " + config_filename
+ try:
+ host_config.load()
+ except (IOError, ValueError) as e:
+ print >> sys.stderr, "Failed to load config: " + str(e)
return 1
# Register handler to re-load the configuration in response to signals.
@@ -1008,30 +1025,30 @@ Web Store: https://chrome.google.com/remotedesktop"""
logging.info("Host configuration is invalid - exiting.")
host_config.clear_auth()
host_config.clear_host_info()
- host_config.save()
+ host_config.save_and_log_errors()
return 0
elif os.WEXITSTATUS(status) == 101:
logging.info("Host ID has been deleted - exiting.")
host_config.clear_host_info()
- host_config.save()
+ host_config.save_and_log_errors()
return 0
elif os.WEXITSTATUS(status) == 102:
logging.info("OAuth credentials are invalid - exiting.")
host_config.clear_auth()
- host_config.save()
+ host_config.save_and_log_errors()
return 0
elif os.WEXITSTATUS(status) == 103:
logging.info("Host domain is blocked by policy - exiting.")
host_config.clear_auth()
host_config.clear_host_info()
- host_config.save()
+ host_config.save_and_log_errors()
return 0
# Nothing to do for Mac-only status 104 (login screen unsupported)
elif os.WEXITSTATUS(status) == 105:
logging.info("Username is blocked by policy - exiting.")
host_config.clear_auth()
host_config.clear_host_info()
- host_config.save()
+ host_config.save_and_log_errors()
return 0