Set names of threads for better debugging.
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 May 2010 21:54:54 +0000 (23:54 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 May 2010 21:54:54 +0000 (23:54 +0200)
cappie/__init__.py
cappie/queue.py
cappie/util.py [new file with mode: 0644]

index 2fea5e0..e760f4a 100644 (file)
@@ -29,6 +29,7 @@ from threading import Thread
 
 import protocol
 import queue
+import util
 
 from errors import *
 
@@ -166,6 +167,8 @@ class Interface(Thread):
        def run(self):
                self.log.info("Starting interface %s" % self.dev)
 
+               util.setprocname("interface %s" % self.dev)
+
                self.db.open()
 
                p = pcapy.open_live(self.dev, self.mtu, self.promisc, 0)
index e2d0dd6..0db7006 100644 (file)
@@ -23,6 +23,8 @@ import time
 
 from threading import Thread
 
+import util
+
 from errors import *
 
 class Queue(Thread):
@@ -53,6 +55,8 @@ class Queue(Thread):
        def run(self):
                self.log.debug("Started event queue")
 
+               util.setprocname("queue")
+
                while self.__running or self.__queue:
                        if not self.__queue:
                                #self.log.debug("Queue sleeping for %s seconds" % self.heartbeat)
diff --git a/cappie/util.py b/cappie/util.py
new file mode 100644 (file)
index 0000000..107b1b2
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# Cappie                                                                      #
+# Copyright (C) 2010 Michael Tremer                                           #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import ctypes
+
+def setprocname(name):
+       libc = ctypes.cdll.LoadLibrary(None)
+
+       buff = ctypes.create_string_buffer(len(name)+1)
+       buff.value = name
+
+       libc.prctl(15, ctypes.byref(buff), 0, 0, 0)