add a warning when running dangerously old Linux kernels

This commit is contained in:
Martinez 2015-12-26 22:33:19 +01:00
parent ebc54aa7c1
commit d37e481acb

View file

@ -38,6 +38,8 @@ COLOR_GIT_STAGED = 10
COLOR_PROMPT_OK = 14 COLOR_PROMPT_OK = 14
COLOR_PROMPT_ERROR = 1 COLOR_PROMPT_ERROR = 1
COLOR_ERROR = 196
MOUNT_IGNORE_FS = ["iso9660", "tmpfs"] MOUNT_IGNORE_FS = ["iso9660", "tmpfs"]
MOUNT_IGNORE_DIR = ["/dev", "/proc", "/sys"] MOUNT_IGNORE_DIR = ["/dev", "/proc", "/sys"]
@ -430,25 +432,33 @@ class StatsPart(Part):
swap_total = 0 swap_total = 0
swap_free = 0 swap_free = 0
# MemAvailable is not available on <linux-3.14 and we'll bitch about that
old_linux = True
with open("/proc/meminfo") as f: with open("/proc/meminfo") as f:
for line in f: for line in f:
if line.startswith("MemTotal"): if line.startswith("MemTotal"):
mem_total = int(line.split()[1]) * 1024 mem_total = int(line.split()[1]) * 1024
elif line.startswith("MemFree"): # MemAvailable is not available on some systems, but folllows MemFree
mem_free = int(line.split()[1]) * 1024
elif line.startswith("MemAvailable"): elif line.startswith("MemAvailable"):
mem_free = int(line.split()[1]) * 1024 mem_free = int(line.split()[1]) * 1024
old_linux = False
elif line.startswith("SwapTotal"): elif line.startswith("SwapTotal"):
swap_total = int(line.split()[1]) * 1024 swap_total = int(line.split()[1]) * 1024
elif line.startswith("SwapFree"): elif line.startswith("SwapFree"):
swap_free = int(line.split()[1]) * 1024 swap_free = int(line.split()[1]) * 1024
if old_linux or True:
self.fragments.append(style_color(COLOR_ERROR))
self.fragments.append(style_bold())
self.fragments.append("❌ <linux-3.14 ❌")
else:
self.fragments.append(style_color(COLOR_MEMSWAP)) self.fragments.append(style_color(COLOR_MEMSWAP))
self.fragments.append("m") self.fragments.append("m")
self.fragments.append(style_bold()) self.fragments.append(style_bold())
self.fragments.append(style_color(settings.get_space_color(mem_free, mem_total))) self.fragments.append(style_color(settings.get_space_color(mem_free, mem_total)))
mem_free_si = si_number(mem_free) mem_free_si = si_number(mem_free)
self.fragments.append(space_string(mem_free) %(mem_free_si[0], mem_free_si[1])) self.fragments.append(space_string(mem_free) %(mem_free_si[0], mem_free_si[1]))
self.fragments.append(style_reset()) self.fragments.append(style_reset())
if swap_total - swap_free > 2**20: if swap_total - swap_free > 2**20: