Skip to content

Commit

Permalink
further kernel config checks, related to #65
Browse files Browse the repository at this point in the history
  • Loading branch information
erpalma committed Nov 6, 2018
1 parent c1f5f95 commit 76e0976
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions lenovo_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dbus
import glob
import os
import re
import struct
import subprocess
import sys
Expand All @@ -15,6 +16,7 @@
from gi.repository import GLib
from mmio import MMIO, MMIOError
from multiprocessing import cpu_count
from platform import uname
from threading import Event, Thread

DEFAULT_SYSFS_POWER_PATH = '/sys/class/power_supply/AC*/online'
Expand Down Expand Up @@ -450,13 +452,36 @@ def power_thread(config, regs, exit_event):
exit_event.wait(wait_t)


def main():
global args

def check_kernel():
if os.geteuid() != 0:
print('[E] No root no party. Try again with sudo.')
sys.exit(1)

kernel_config = None
try:
with open(os.path.join('/boot', 'config-{:s}'.format(uname()[2]))) as f:
kernel_config = f.read()
except IOError:
try:
with open(os.path.join('/proc', 'config.gz')) as f:
kernel_config = f.read()
except IOError:
pass
if kernel_config is None:
print('[W] Unable to obtain and validate kernel config.')
elif not re.search('CONFIG_DEVMEM=y', kernel_config):
print('[E] Bad kernel config: you need CONFIG_DEVMEM=y.')
sys.exit(1)
elif not re.search('CONFIG_X86_MSR=(y|m)', kernel_config):
print('[E] Bad kernel config: you need CONFIG_X86_MSR builtin or as module.')
sys.exit(1)


def main():
global args

check_kernel()

parser = argparse.ArgumentParser()
parser.add_argument('--debug', action='store_true', help='add some debug info and additional checks')
parser.add_argument('--config', default='/etc/lenovo_fix.conf', help='override default config file path')
Expand Down

0 comments on commit 76e0976

Please sign in to comment.