Skip to contentSkip to conversation

master - lvmdbusd: thread stacks dump support

PATCH Tony Asleson 1 participant 1 message Sep 27, 2017

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=32c87d56b12e9b6b8e6e1e7e85178abacf19811a
Commit:        32c87d56b12e9b6b8e6e1e7e85178abacf19811a
Parent:        60e3dbd6d50ce2c28206c96f824a5afc9bb287e6
Author:        Tony Asleson <[email protected]>
AuthorDate:    Mon Sep 25 15:20:03 2017 -0500
Committer:     Tony Asleson <[email protected]>
CommitterDate: Wed Sep 27 07:45:00 2017 -0500

lvmdbusd: thread stacks dump support

If you send a SIGUSR1 (10) to the daemon it will dump all the threads current stacks to stdout. This will be useful when the daemon is apparently hung and not processing requests.

eg.

$ sudo kill -10 <daemon pid>
---
 daemons/lvmdbusd/main.py  |   29 ++++++++++++++++++++------
 daemons/lvmdbusd/utils.py |   48 +++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 64 insertions(+), 13 deletions(-)
daemons/lvmdbusd/main.py +22 -7
index dc31b6f..7f0a028 100644
@@ -63,6 +63,24 @@ def check_bb_size(value):
 	return v
 
 
+def install_signal_handlers():
+	# Because of the glib main loop stuff the python signal handler code is
+	# apparently not usable and we need to use the glib calls instead
+	signal_add = None
+
+	if hasattr(GLib, 'unix_signal_add'):
+		signal_add = GLib.unix_signal_add
+	elif hasattr(GLib, 'unix_signal_add_full'):
+		signal_add = GLib.unix_signal_add_full
+
+	if signal_add:
+		signal_add(GLib.PRIORITY_HIGH, signal.SIGHUP, utils.handler, signal.SIGHUP)
+		signal_add(GLib.PRIORITY_HIGH, signal.SIGINT, utils.handler, signal.SIGINT)
+		signal_add(GLib.PRIORITY_HIGH, signal.SIGUSR1, utils.handler, signal.SIGUSR1)
+	else:
+		log_error("GLib.unix_signal_[add|add_full] are NOT available!")
+
+
 def main():
 	start = time.time()
 	# Add simple command line handling
@@ -112,12 +130,7 @@ def main():
 	# List of threads that we start up
 	thread_list = []
 
-	# Install signal handlers
-	for s in [signal.SIGHUP, signal.SIGINT]:
-		try:
-			signal.signal(s, utils.handler)
-		except RuntimeError:
-			pass
+	install_signal_handlers()
 
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 	dbus.mainloop.glib.threads_init()
@@ -177,5 +190,7 @@ def main():
 			for thread in thread_list:
 				thread.join()
 	except KeyboardInterrupt:
-		utils.handler(signal.SIGINT, None)
+		# If we are unable to register signal handler, we will end up here when
+		# the service gets a ^C or a kill -2 <parent pid>
+		utils.handler(signal.SIGINT)
 	return 0
daemons/lvmdbusd/utils.py +42 -6

67 lines not on this page · raw message