Skip to content

Commit

Permalink
qubesd: reduce verbosity
Browse files Browse the repository at this point in the history
Remove debug prints, log full traceback (of handled exception) only when
debug mode enabled (--debug, introduce in this commit too).
--debug option also enables sending tracebacks to the API clients.

QubesOS/qubes-issues#853
  • Loading branch information
marmarek committed May 23, 2017
1 parent 64b83fa commit 74689dd
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions qubes/tools/qubesd.py
Expand Up @@ -37,19 +37,16 @@ def __init__(self, handler, *args, app, debug=False, **kwargs):
self.mgmt = None

def connection_made(self, transport):
print('connection_made()')
self.transport = transport

def connection_lost(self, exc):
print('connection_lost(exc={!r})'.format(exc))
self.untrusted_buffer.close()
# for cancellable operation, interrupt it, otherwise it will do nothing
if self.mgmt is not None:
self.mgmt.cancel()
self.transport = None

def data_received(self, untrusted_data): # pylint: disable=arguments-differ
print('data_received(untrusted_data={!r})'.format(untrusted_data))
if self.len_untrusted_buffer + len(untrusted_data) > self.buffer_size:
self.app.log.warning('request too long')
self.transport.abort()
Expand All @@ -60,7 +57,6 @@ def data_received(self, untrusted_data): # pylint: disable=arguments-differ
self.untrusted_buffer.write(untrusted_data)

def eof_received(self):
print('eof_received()')
try:
src, method, dest, arg, untrusted_payload = \
self.untrusted_buffer.getvalue().split(b'\0', 4)
Expand Down Expand Up @@ -102,10 +98,15 @@ def respond(self, src, method, dest, arg, *, untrusted_payload):
method, arg, src, dest, len(untrusted_payload))

except qubes.exc.QubesException as err:
self.app.log.exception(
'error while calling '
'src=%r method=%r dest=%r arg=%r len(untrusted_payload)=%d',
src, method, dest, arg, len(untrusted_payload))
msg = ('%r while calling '
'src=%r method=%r dest=%r arg=%r len(untrusted_payload)=%d')

if self.debug:
self.app.log.exception(msg,
err, src, method, dest, arg, len(untrusted_payload))
else:
self.app.log.info(msg,
err, src, method, dest, arg, len(untrusted_payload))
if self.transport is not None:
self.send_exception(err)
self.transport.write_eof()
Expand Down Expand Up @@ -176,6 +177,9 @@ def sighandler(loop, signame, server, server_internal):
loop.stop()

parser = qubes.tools.QubesArgumentParser(description='Qubes OS daemon')
parser.add_argument('--debug', action='store_true', default=False,
help='Enable verbose error logging (all exceptions with full '
'tracebacks) and also send tracebacks to Admin API clients')


def main(args=None):
Expand All @@ -196,7 +200,7 @@ def main(args=None):
old_umask = os.umask(0o007)
server = loop.run_until_complete(loop.create_unix_server(
functools.partial(QubesDaemonProtocol, qubes.api.admin.QubesAdminAPI,
app=args.app), QUBESD_SOCK))
app=args.app, debug=args.debug), QUBESD_SOCK))
shutil.chown(QUBESD_SOCK, group='qubes')

try:
Expand All @@ -206,7 +210,7 @@ def main(args=None):
server_internal = loop.run_until_complete(loop.create_unix_server(
functools.partial(QubesDaemonProtocol,
qubes.api.internal.QubesInternalAPI,
app=args.app), QUBESD_INTERNAL_SOCK))
app=args.app, debug=args.debug), QUBESD_INTERNAL_SOCK))
shutil.chown(QUBESD_INTERNAL_SOCK, group='qubes')

os.umask(old_umask)
Expand Down

0 comments on commit 74689dd

Please sign in to comment.