X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=contrib%2Fgnunet_janitor.py.in;h=74fc70886490cc059b1b2d611dc3aeb8bcca4c70;hb=1732154b8c021e7ee0e34c28cf3b1a843454727a;hp=c23cc28588fcaf39733ded062be3b38c747ea353;hpb=cf5f71ba15c897cd5768ea0dd644d1c9a6a4d4e2;p=oweals%2Fgnunet.git diff --git a/contrib/gnunet_janitor.py.in b/contrib/gnunet_janitor.py.in index c23cc2858..74fc70886 100644 --- a/contrib/gnunet_janitor.py.in +++ b/contrib/gnunet_janitor.py.in @@ -14,10 +14,14 @@ # # You should have received a copy of the GNU General Public License # along with GNUnet; see the file COPYING. If not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. # # Finds any gnunet processes still running in the system and kills them +# +# gnunet janitor can be used by invoking `make' like this: +# TESTS_ENVIRONMENT='${top_srcdir}/contrib/gnunet_janitor.py &&' make check + from __future__ import print_function import os import re @@ -26,6 +30,7 @@ import sys import shutil import time import signal +import terminate if os.name == 'nt': from win32com.client import GetObject @@ -40,7 +45,10 @@ def get_process_list (): else: pids = [pid for pid in os.listdir('/proc') if pid.isdigit ()] for pid in pids: - result.append ((pid, open (os.path.join ('/proc', pid, 'comm'), 'rb').read () + with open (os.path.join ('/proc', pid, 'cmdline'), 'rb') as p: + cmdline = p.read ().split ('\x00') + if len (cmdline) > 0: + result.append ((pid, cmdline[0])) return result def main (): @@ -51,12 +59,20 @@ def main (): gnunet_procs.append (p) for p in gnunet_procs: if re.match (r'gnunet-service-arm', p[1]): - print ("killing arm {0:5} {1}".format (p[0], p[1])) - os.kill (p[0], signal.SIGTERM) + print ("killing arm process {0:5} {1}".format (p[0], p[1])) + try: + terminate.safe_terminate_process_by_pid (int (p[0]), 1) + except OSError as e: + print ("failed: {0}".format (e)) + pass for p in gnunet_procs: if not re.match (r'gnunet-service-arm', p[1]): - print ("killing arm {0:5} {1}".format (p[0], p[1])) - os.kill (p[0], signal.SIGTERM) + print ("killing non-arm process {0:5} {1}".format (p[0], p[1])) + try: + terminate.safe_terminate_process_by_pid (int (p[0]), 1) + except OSError as e: + print ("failed: {0}".format (e)) + pass if __name__ == '__main__': - sys.exit (main ()) \ No newline at end of file + sys.exit (main ())