GNUnet  0.10.x
gnunet_janitor.py
Go to the documentation of this file.
1 #!/usr/bin/python3
2 # This file is part of GNUnet.
3 # (C) 2011, 2018 Christian Grothoff (and other contributing authors)
4 #
5 # GNUnet is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Affero General Public License as published
7 # by the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # GNUnet is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Affero General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # SPDX-License-Identifier: AGPL3.0-or-later
19 #
20 # Finds any gnunet processes still running in the system and kills them
21 #
22 # gnunet janitor can be used by invoking `make' like this:
23 # TESTS_ENVIRONMENT='${top_srcdir}/contrib/scripts/gnunet_janitor.py &&' make check
24 
25 import os
26 import re
27 import subprocess
28 import sys
29 import shutil
30 import time
31 import signal
32 import terminate
33 
34 if os.name == 'nt':
35  from win32com.client import GetObject
36  WMI = GetObject('winmgmts:')
37 
38 
40  result = []
41  if os.name == 'nt':
42  processes = WMI.InstancesOf('Win32_Process')
43  for p in processes:
44  result.append((p.Properties_('ProcessId').Value, re.sub(r'(.+)\.exe', r'\1', p.Properties_('Name').Value)))
45  else:
46  pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
47  for pid in pids:
48  with open(os.path.join('/proc', pid, 'cmdline'), 'rb') as p:
49  cmdline = p.read().split('\x00')
50  if len(cmdline) > 0:
51  result.append((pid, cmdline[0]))
52  return result
53 
54 
55 def main():
56  procs = get_process_list()
57  gnunet_procs = []
58  for p in procs:
59  if re.match(r'gnunet-.+', p[1]):
60  gnunet_procs.append(p)
61  for p in gnunet_procs:
62  if re.match(r'gnunet-service-arm', p[1]):
63  print("killing arm process {0:5} {1}".format(p[0], p[1]))
64  try:
66  except OSError as e:
67  print("failed: {0}".format(e))
68  pass
69  for p in gnunet_procs:
70  if not re.match(r'gnunet-service-arm', p[1]):
71  print("killing non-arm process {0:5} {1}".format(p[0], p[1]))
72  try:
74  except OSError as e:
75  print("failed: {0}".format(e))
76  pass
77 
78 
79 if __name__ == '__main__':
80  sys.exit(main())
def get_process_list()
def safe_terminate_process_by_pid(pid, code)
Definition: terminate.py:36
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...