Commit 72f96f04 authored by segfault's avatar segfault
Browse files

tails-screen-locker: Improve logging

- log to journal
- log uncaught exceptions
parent 76c2c393
...@@ -11,7 +11,11 @@ from pam import pam ...@@ -11,7 +11,11 @@ from pam import pam
import time import time
import pwd import pwd
UI_FILE = "/usr/share/tails/screenlocker.ui" try:
from systemd.journal import JournaldLogHandler
except ImportError:
# JournaldLogHandler is called JournalHandler in Python 3.5 and earlier
from systemd.journal import JournalHandler as JournaldLogHandler
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
...@@ -19,23 +23,48 @@ from gi.repository import Gtk, GLib ...@@ -19,23 +23,48 @@ from gi.repository import Gtk, GLib
gi.require_version('Gdk', '3.0') gi.require_version('Gdk', '3.0')
from gi.repository import Gdk from gi.repository import Gdk
UI_FILE = "/usr/share/tails/screenlocker.ui"
_ = gettext.gettext _ = gettext.gettext
gettext.install("Tails") gettext.install("Tails")
logging.basicConfig(level=logging.DEBUG)
mainloop = GLib.MainLoop() mainloop = GLib.MainLoop()
# Set up logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter("%(name)s:%(levelname)s: %(message)s"))
logger.addHandler(console_handler)
journal_handler = JournaldLogHandler()
journal_handler.setLevel(logging.WARNING)
logger.addHandler(journal_handler)
# Set up exception handler
# Source: https://stackoverflow.com/a/16993115/2804197
def handle_exception(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
sys.excepthook = handle_exception
def lock_screen(): def lock_screen():
# org.gnome.ScreenSaver.Lock() sometimes does not return, so we set a timeout of 5 seconds # org.gnome.ScreenSaver.Lock() sometimes does not return, so we set a timeout of 5 seconds
try: try:
SessionBus().get("org.gnome.ScreenSaver").Lock(timeout=5) SessionBus().get("org.gnome.ScreenSaver").Lock(timeout=5)
except Exception as e: except GLib.Error as e:
logging.exception(e) if e.message == "Timeout was reached":
finally: logger.warning("Timeout was reached during call to org.gnome.ScreenSaver.Lock()")
sys.exit() else:
raise
sys.exit()
class PasswordDialog(object): class PasswordDialog(object):
...@@ -75,9 +104,9 @@ class PasswordDialog(object): ...@@ -75,9 +104,9 @@ class PasswordDialog(object):
p.stdin.flush() p.stdin.flush()
out, err = p.communicate() out, err = p.communicate()
if p.returncode != 0: if p.returncode != 0:
print("passwd stdout: %s" % out) logger.info("passwd stdout: %s", out)
print("passwd stderr: %s" % err) logger.info("passwd stderr: %s", err)
raise RuntimeError("passwd returned %r" % p.returncode) raise RuntimeError("passwd exited with return code %s. stderr: %s " % (p.returncode, err))
# We close the window here for the case that lock_screen does not return immediately, # We close the window here for the case that lock_screen does not return immediately,
# otherwise it would look like the app is unresponsive # otherwise it would look like the app is unresponsive
...@@ -94,7 +123,7 @@ class PasswordDialog(object): ...@@ -94,7 +123,7 @@ class PasswordDialog(object):
# TODO: Remove this once this is fixed: https://bugzilla.gnome.org/show_bug.cgi?id=761969 # TODO: Remove this once this is fixed: https://bugzilla.gnome.org/show_bug.cgi?id=761969
p = pam() p = pam()
while not p.authenticate(pwd.getpwuid(os.getuid()).pw_name, self.pw): while not p.authenticate(pwd.getpwuid(os.getuid()).pw_name, self.pw):
logging.debug("PAM not updated yet...") logger.debug("PAM not updated yet...")
time.sleep(0.01) time.sleep(0.01)
# We close the window here for the case that lock_screen does not return immediately, # We close the window here for the case that lock_screen does not return immediately,
# otherwise it would look like the app is unresponsive # otherwise it would look like the app is unresponsive
......
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