Skip to content

Commit

Permalink
Only attempt to use sudo if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
zmc committed Apr 28, 2014
1 parent f102e49 commit 2cbe1dc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion teuthology/kill.py
Expand Up @@ -7,6 +7,7 @@
import subprocess
import tempfile
import logging
import getpass

from . import report
from .config import config
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2cbe1dc

Please sign in to comment.