Skip to content

Commit

Permalink
Only require sudo for setting SMI values
Browse files Browse the repository at this point in the history
Since reading values doesn't require sudo, only relaunch the application
as sudo if it calls a function that requires sudo privileges.

Change-Id: Icbdafd860edb6f887a7dcb0dfaa3d8a29696d3aa
  • Loading branch information
kentrussell authored and Gerrit Code Review committed May 27, 2016
1 parent e81066d commit 937a880
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rocm-smi
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ JSON_VERSION = 1

# To write to sysfs, we need to run this script as root. If the script is not run as
# root, re-launch it via execvp to give the script sudo privileges.
if os.geteuid() != 0:
os.execvp('sudo', ['sudo'] + sys.argv)
def relaunchAsSudo():
if os.geteuid() != 0:
os.execvp('sudo', ['sudo'] + sys.argv)

parser = argparse.ArgumentParser(description='AMD ROCm System Management Interface',
formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=90, width=110))
Expand Down Expand Up @@ -728,6 +729,10 @@ if args.showallinfo:
args.showclkfrq = True
args.showperflevel = True
args.showoverdrive = True

if args.setsclk or args.setmclk or args.setfan or args.setperflevel or args.resetclocks or args.loadclocks or args.setoverdrive:
relaunchAsSudo()

if args.showid:
showId(deviceList)
if args.resetclocks:
Expand Down

0 comments on commit 937a880

Please sign in to comment.