1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lvmdbusd: Use common function for traceback

We were using a number of different ways to achieve the same result.  Use
a common function to make this consistent.
This commit is contained in:
Tony Asleson 2022-08-31 11:18:55 -05:00
parent 22942f4916
commit cb32b0a87f
7 changed files with 28 additions and 29 deletions

View File

@ -13,12 +13,11 @@ import time
import threading import threading
from itertools import chain from itertools import chain
import collections import collections
import traceback
import os import os
from lvmdbusd import cfg from lvmdbusd import cfg
from lvmdbusd.utils import pv_dest_ranges, log_debug, log_error, add_no_notify,\ from lvmdbusd.utils import pv_dest_ranges, log_debug, log_error, add_no_notify,\
make_non_block, read_decoded make_non_block, read_decoded, extract_stack_trace
from lvmdbusd.lvm_shell_proxy import LVMShellProxy from lvmdbusd.lvm_shell_proxy import LVMShellProxy
try: try:
@ -149,8 +148,8 @@ def call_lvm(command, debug=False, line_cb=None,
if i != -1: if i != -1:
try: try:
line_cb(cb_data, stdout_text[stdout_index:i]) line_cb(cb_data, stdout_text[stdout_index:i])
except: except BaseException as be:
st = traceback.format_exc() st = extract_stack_trace(be)
log_error("call_lvm: line_cb exception: \n %s" % st) log_error("call_lvm: line_cb exception: \n %s" % st)
stdout_index = i + 1 stdout_index = i + 1
else: else:
@ -189,11 +188,11 @@ def _shell_cfg():
_t_call = lvm_shell.call_lvm _t_call = lvm_shell.call_lvm
cfg.SHELL_IN_USE = lvm_shell cfg.SHELL_IN_USE = lvm_shell
return True return True
except Exception: except Exception as e:
_t_call = call_lvm _t_call = call_lvm
cfg.SHELL_IN_USE = None cfg.SHELL_IN_USE = None
log_error(traceback.format_exc()) log_error("Unable to utilize lvm shell, dropping "
log_error("Unable to utilize lvm shell, dropping back to fork & exec") "back to fork & exec\n%s" % extract_stack_trace(e))
return False return False

View File

@ -24,8 +24,6 @@ from . import background
from .utils import round_size, mt_remove_dbus_objects from .utils import round_size, mt_remove_dbus_objects
from .job import JobState from .job import JobState
import traceback
# Try and build a key for a LV, so that we sort the LVs with least dependencies # Try and build a key for a LV, so that we sort the LVs with least dependencies
# first. This may be error prone because of the flexibility LVM # first. This may be error prone because of the flexibility LVM
@ -371,8 +369,8 @@ class LvCommon(AutomatedProperties):
return dbus.Struct((self.state.Attr[index], return dbus.Struct((self.state.Attr[index],
type_map.get(self.state.Attr[index], default)), type_map.get(self.state.Attr[index], default)),
signature="(ss)") signature="(ss)")
except BaseException: except BaseException as b:
st = traceback.format_exc() st = utils.extract_stack_trace(b)
log_error("attr_struct: \n%s" % st) log_error("attr_struct: \n%s" % st)
return dbus.Struct(('?', 'Unavailable'), signature="(ss)") return dbus.Struct(('?', 'Unavailable'), signature="(ss)")

View File

@ -14,11 +14,11 @@
import subprocess import subprocess
import shlex import shlex
import os import os
import traceback
import sys import sys
import tempfile import tempfile
import time import time
import select import select
from .utils import extract_stack_trace
try: try:
import simplejson as json import simplejson as json
@ -279,8 +279,8 @@ if __name__ == "__main__":
pass pass
except EOFError: except EOFError:
pass pass
except Exception: except Exception as e:
traceback.print_exc(file=sys.stdout) log_error("main process exiting on exception!\n%s", extract_stack_trace(e))
sys.exit(1) sys.exit(1)
sys.exit(0) sys.exit(0)

View File

@ -22,7 +22,6 @@ from . import lvmdb
from gi.repository import GLib from gi.repository import GLib
from .fetch import StateUpdate from .fetch import StateUpdate
from .manager import Manager from .manager import Manager
import traceback
import queue import queue
from . import udevwatch from . import udevwatch
from .utils import log_debug, log_error, log_msg, DebugMessages from .utils import log_debug, log_error, log_msg, DebugMessages
@ -52,8 +51,8 @@ def process_request():
pass pass
except SystemExit: except SystemExit:
break break
except Exception: except Exception as e:
st = traceback.format_exc() st = utils.extract_stack_trace(e)
utils.log_error("process_request exception: \n%s" % st) utils.log_error("process_request exception: \n%s" % st)
log_debug("process_request thread exiting!") log_debug("process_request thread exiting!")

View File

@ -9,12 +9,11 @@
import sys import sys
import threading import threading
import traceback
import dbus import dbus
import os import os
import copy import copy
from . import cfg from . import cfg
from .utils import log_debug, pv_obj_path_generate, log_error from .utils import log_debug, pv_obj_path_generate, log_error, extract_stack_trace
from .automatedproperties import AutomatedProperties from .automatedproperties import AutomatedProperties
@ -40,8 +39,8 @@ class ObjectManager(AutomatedProperties):
for k, v in list(obj._objects.items()): for k, v in list(obj._objects.items()):
path, props = v[0].emit_data() path, props = v[0].emit_data()
rc[path] = props rc[path] = props
except Exception: except Exception as e:
traceback.print_exc(file=sys.stdout) log_error("_get_managed_objects exception, bailing: \n%s" % extract_stack_trace(e))
sys.exit(1) sys.exit(1)
return rc return rc

View File

@ -13,8 +13,7 @@ import threading
from gi.repository import GLib from gi.repository import GLib
from .job import Job from .job import Job
from . import cfg from . import cfg
import traceback from .utils import log_error, mt_async_call, extract_stack_trace
from .utils import log_error, mt_async_call
class RequestEntry(object): class RequestEntry(object):
@ -86,7 +85,7 @@ class RequestEntry(object):
# exception in the journal for figuring out what went wrong. # exception in the journal for figuring out what went wrong.
cfg.debug.dump() cfg.debug.dump()
cfg.flightrecorder.dump() cfg.flightrecorder.dump()
tb = ''.join(traceback.format_tb(e.__traceback__)) tb = extract_stack_trace(e)
log_error("While processing %s: we encountered\n%s" % (str(self.method), tb)) log_error("While processing %s: we encountered\n%s" % (str(self.method), tb))
log_error("Error returned to client: %s" % str(e)) log_error("Error returned to client: %s" % str(e))
self.register_error(-1, str(e), e) self.register_error(-1, str(e), e)

View File

@ -389,8 +389,8 @@ def handler(signum):
log_error('Exiting daemon with signal %d' % signum) log_error('Exiting daemon with signal %d' % signum)
if cfg.loop is not None: if cfg.loop is not None:
cfg.loop.quit() cfg.loop.quit()
except: except BaseException as be:
st = traceback.format_exc() st = extract_stack_trace(be)
log_error("signal handler: exception (logged, not reported!) \n %s" % st) log_error("signal handler: exception (logged, not reported!) \n %s" % st)
# It's important we report that we handled the exception for the exception # It's important we report that we handled the exception for the exception
@ -659,9 +659,8 @@ def _async_handler(call_back, parameters):
call_back(*parameters) call_back(*parameters)
else: else:
call_back() call_back()
except: except BaseException as be:
st = traceback.format_exc() log_error("mt_async_call: exception (logged, not reported!) \n %s" % extract_stack_trace(be))
log_error("mt_async_call: exception (logged, not reported!) \n %s" % st)
# Execute the function on the main thread with the provided parameters, do # Execute the function on the main thread with the provided parameters, do
@ -763,3 +762,9 @@ class LockFile(object):
def __exit__(self, _type, _value, _traceback): def __exit__(self, _type, _value, _traceback):
os.close(self.fd) os.close(self.fd)
def extract_stack_trace(exception):
return ''.join(traceback.format_exception(None, exception, exception.__traceback__))