-modifying tests to use new service MQ API, implementing more of service MQ API
[oweals/gnunet.git] / contrib / gnunet_janitor.py.in
index 52de8f9e91cc7fcb65f43139e419875b824b4fa6..74fc70886490cc059b1b2d611dc3aeb8bcca4c70 100644 (file)
@@ -14,8 +14,8 @@
 #
 #    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
 #
@@ -30,6 +30,7 @@ import sys
 import shutil
 import time
 import signal
+import terminate
 
 if os.name == 'nt':
   from win32com.client import GetObject
@@ -44,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 ():
@@ -55,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 ())