]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Only attempt to use sudo if necessary
authorZack Cerza <zack@cerza.org>
Mon, 28 Apr 2014 16:12:29 +0000 (11:12 -0500)
committerZack Cerza <zack@cerza.org>
Mon, 28 Apr 2014 16:12:29 +0000 (11:12 -0500)
teuthology/kill.py

index 9f197dd8a6858ff7f7f6532905b438b18192d543..d090ff40c7c2ba2af2f619062d96e5c1cbd6b5aa 100755 (executable)
@@ -7,6 +7,7 @@ import psutil
 import subprocess
 import tempfile
 import logging
+import getpass
 
 from . import report
 from .config import config
@@ -158,7 +159,12 @@ def kill_processes(run_name, pids=None):
     else:
         log.info("Killing Pids: " + str(to_kill))
         for pid in to_kill:
-            subprocess.call(['sudo', 'kill', str(pid)])
+            args = ['kill', str(pid)]
+            # Don't attempt to use sudo if it's not necessary
+            proc_user = psutil.Process(int(pid)).username()
+            if proc_user != getpass.getuser():
+                args.insert(0, 'sudo')
+            subprocess.call(args)
 
 
 def process_matches_run(pid, run_name):