From 892a7dcf57306312b76d2ece77da0b19098dcb10 Mon Sep 17 00:00:00 2001 From: Berat Postalcioglu Date: Fri, 22 May 2020 00:03:10 +0300 Subject: [PATCH 1/5] create assert_root function that checks whether the user has root privileges to run the script with --read and --cache arguments --- undervolt.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/undervolt.py b/undervolt.py index 3cfb2bc..d539dca 100755 --- a/undervolt.py +++ b/undervolt.py @@ -69,6 +69,8 @@ def write_msr(val, addr): values from register addr. Writes to all msr node on all CPUs available. """ + assert_root() + for i in valid_cpus(): c = '/dev/cpu/%d/msr' % i if not os.path.exists(c): @@ -84,6 +86,8 @@ def read_msr(addr, cpu=0): """ Read a value from single msr node on given CPU (defaults to first) """ + assert_root() + n = '/dev/cpu/%d/msr' % (cpu,) f = os.open(n, os.O_RDONLY) os.lseek(f, addr, os.SEEK_SET) @@ -348,6 +352,12 @@ def read_ac_state(): # Assume no battery if the /sys entry is missing. return True +def assert_root(): + """ + Checks whether the user has root priviliges, exit otherwise + """ + if os.geteuid() != 0: + exit("You need to have root privileges to run this script these options.\nRerun with 'sudo'.") def main(): parser = argparse.ArgumentParser() From c36a2ca42e2c4cd70c55ac45927165b9342816ff Mon Sep 17 00:00:00 2001 From: Berat Postalcioglu Date: Fri, 22 May 2020 00:05:47 +0300 Subject: [PATCH 2/5] fix typo in assert_root function's comment --- undervolt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/undervolt.py b/undervolt.py index d539dca..1a857d1 100755 --- a/undervolt.py +++ b/undervolt.py @@ -354,7 +354,7 @@ def read_ac_state(): def assert_root(): """ - Checks whether the user has root priviliges, exit otherwise + Checks whether the user has root privileges, exit otherwise """ if os.geteuid() != 0: exit("You need to have root privileges to run this script these options.\nRerun with 'sudo'.") From 9fec9d269d866c24561e4d21d6cd491ac86ae748 Mon Sep 17 00:00:00 2001 From: Berat Postalcioglu Date: Fri, 22 May 2020 00:07:36 +0300 Subject: [PATCH 3/5] change logging.warn to logging.warning to remove depreciation warning --- undervolt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/undervolt.py b/undervolt.py index 1a857d1..24080f5 100755 --- a/undervolt.py +++ b/undervolt.py @@ -396,7 +396,7 @@ def main(): subprocess.check_call(['modprobe', 'msr']) if (args.core or args.cache) and args.core != args.cache: - logging.warn( + logging.warning( "You have supplied different offsets for Core and Cache. " "The smaller of the two (or none if you only supplied one) will be applied to both planes." ) From 876e793211d01b29306dd40592c3a3d5166bc88b Mon Sep 17 00:00:00 2001 From: Berat Postalcioglu Date: Fri, 22 May 2020 00:34:37 +0300 Subject: [PATCH 4/5] fix typo in assert_root function's comment --- undervolt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/undervolt.py b/undervolt.py index 24080f5..6206f71 100755 --- a/undervolt.py +++ b/undervolt.py @@ -357,7 +357,7 @@ def assert_root(): Checks whether the user has root privileges, exit otherwise """ if os.geteuid() != 0: - exit("You need to have root privileges to run this script these options.\nRerun with 'sudo'.") + exit("You need to have root privileges to run this script with these options.\nRerun with 'sudo'.") def main(): parser = argparse.ArgumentParser() From 82bf6fb252299469da3b9b4b4ff8d758c36ea65a Mon Sep 17 00:00:00 2001 From: Berat Postalcioglu Date: Tue, 9 Jun 2020 16:21:35 +0300 Subject: [PATCH 5/5] use assert_root to check whether user is root when '-r' option is used --- undervolt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/undervolt.py b/undervolt.py index 6206f71..62b4e68 100755 --- a/undervolt.py +++ b/undervolt.py @@ -393,6 +393,7 @@ def main(): msr = ADDRESSES if not glob('/dev/cpu/*/msr'): + assert_root() subprocess.check_call(['modprobe', 'msr']) if (args.core or args.cache) and args.core != args.cache: