diff options
author | Nils Gillmann <ng0@n0.is> | 2018-05-19 14:43:13 +0000 |
---|---|---|
committer | Nils Gillmann <ng0@n0.is> | 2018-05-19 14:43:13 +0000 |
commit | 6ab60d4920bb3199aee8cd872b930e9e3e808ba7 (patch) | |
tree | 3d761dbf8793a1d2422fbd14667255c7e0292ea4 /contrib/scripts/gnunet_janitor.py.in | |
parent | c2f27dfe8218545c327ab49d225a49910347c5c6 (diff) | |
download | gnunet-6ab60d4920bb3199aee8cd872b930e9e3e808ba7.tar.gz gnunet-6ab60d4920bb3199aee8cd872b930e9e3e808ba7.zip |
Restructure contrib folder.
contrib/pogen.sh -> bin/pogen.sh
bootstrap: Use new pogen location and execute it.
contrib/openvpn-tap32: Move to contrib/3rdparty/Windows/openvpn-tap32.
contrib/gnunet-logo*: Move to contrib/branding/logo/
Delete old patches in contrib, predating git.
Move buildbot data to contrib/ci/buildbot,
move docker data to contrib/ci/docker.
Create contrib/conf and populate it with config files found in contrib and bin.
Move gns related data to contrib/gns.
delete contrib/repeat.sh
Move contrib/log.php into contrib/web/log.php.
Create folder contrib/scripts and use it for most scripts in contrib.
Remove trailing whitespace in doc/Makefile.am
Signed-off-by: Nils Gillmann <ng0@n0.is>
Diffstat (limited to 'contrib/scripts/gnunet_janitor.py.in')
-rw-r--r-- | contrib/scripts/gnunet_janitor.py.in | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/contrib/scripts/gnunet_janitor.py.in b/contrib/scripts/gnunet_janitor.py.in new file mode 100644 index 000000000..74fc70886 --- /dev/null +++ b/contrib/scripts/gnunet_janitor.py.in | |||
@@ -0,0 +1,78 @@ | |||
1 | #!@PYTHON@ | ||
2 | # This file is part of GNUnet. | ||
3 | # (C) 2011 Christian Grothoff (and other contributing authors) | ||
4 | # | ||
5 | # GNUnet is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published | ||
7 | # by the Free Software Foundation; either version 2, or (at your | ||
8 | # 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 | # General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with GNUnet; see the file COPYING. If not, write to the | ||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | # Boston, MA 02110-1301, USA. | ||
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/gnunet_janitor.py &&' make check | ||
24 | |||
25 | from __future__ import print_function | ||
26 | import os | ||
27 | import re | ||
28 | import subprocess | ||
29 | import sys | ||
30 | import shutil | ||
31 | import time | ||
32 | import signal | ||
33 | import terminate | ||
34 | |||
35 | if os.name == 'nt': | ||
36 | from win32com.client import GetObject | ||
37 | WMI = GetObject('winmgmts:') | ||
38 | |||
39 | def get_process_list (): | ||
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 | def main (): | ||
55 | procs = get_process_list () | ||
56 | gnunet_procs = [] | ||
57 | for p in procs: | ||
58 | if re.match (r'gnunet-.+', p[1]): | ||
59 | gnunet_procs.append (p) | ||
60 | for p in gnunet_procs: | ||
61 | if re.match (r'gnunet-service-arm', p[1]): | ||
62 | print ("killing arm process {0:5} {1}".format (p[0], p[1])) | ||
63 | try: | ||
64 | terminate.safe_terminate_process_by_pid (int (p[0]), 1) | ||
65 | except OSError as e: | ||
66 | print ("failed: {0}".format (e)) | ||
67 | pass | ||
68 | for p in gnunet_procs: | ||
69 | if not re.match (r'gnunet-service-arm', p[1]): | ||
70 | print ("killing non-arm process {0:5} {1}".format (p[0], p[1])) | ||
71 | try: | ||
72 | terminate.safe_terminate_process_by_pid (int (p[0]), 1) | ||
73 | except OSError as e: | ||
74 | print ("failed: {0}".format (e)) | ||
75 | pass | ||
76 | |||
77 | if __name__ == '__main__': | ||
78 | sys.exit (main ()) | ||