From: Michael Tremer Date: Tue, 11 May 2010 21:54:54 +0000 (+0200) Subject: Set names of threads for better debugging. X-Git-Url: http://git.ipfire.org/?p=oddments%2Fcappie.git;a=commitdiff_plain;h=64e40ed09d56387130e212f563644c8e23ff672e Set names of threads for better debugging. --- diff --git a/cappie/__init__.py b/cappie/__init__.py index 2fea5e0..e760f4a 100644 --- a/cappie/__init__.py +++ b/cappie/__init__.py @@ -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) diff --git a/cappie/queue.py b/cappie/queue.py index e2d0dd6..0db7006 100644 --- a/cappie/queue.py +++ b/cappie/queue.py @@ -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 index 0000000..107b1b2 --- /dev/null +++ b/cappie/util.py @@ -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 . # +# # +############################################################################### + +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)