From cd11dc096c36852fc0d00dc30c238bf7c1b59012 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 2 Apr 2015 13:27:49 +0200 Subject: add random plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/plugins/random.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/plugins/random.py (limited to 'src') diff --git a/src/plugins/random.py b/src/plugins/random.py new file mode 100644 index 0000000..c942f35 --- /dev/null +++ b/src/plugins/random.py @@ -0,0 +1,59 @@ +# -*- python -*- +''' +xpybar – xmobar replacement written in python +Copyright © 2014, 2015 Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +''' + + +class Random: + ''' + Entropy pool status + + @variable poolsize:int The size of the entropy pool, see `man 4 random` for more information + @variable read_wakeup_threshold:int The number of bits of entropy required for waking up processes + that sleep waiting for entropy from `/dev/random` + @variable write_wakeup_threshold:int The number of bits of entropy below which we wake up processes + that do a `select` or `poll` for write access to `/dev/random` + @variable urandom_min_reseed_secs:int The minimum number of seconds between urandom pool reseeding + @variable boot_id:int Random UUID generated when the system is booted + ''' + + + def __init__(self): + ''' + Constructor + ''' + def read(filename): + with open('/proc/sys/kernel/random/' + filename, 'rb') as file: + return file.read().decode('utf-8', 'replace').rstrip('\n') + + self.poolsize = int(read('poolsize')) + self.read_wakeup_threshold = int(read('read_wakeup_threshold')) + self.write_wakeup_threshold = int(read('write_wakeup_threshold')) + self.urandom_min_reseed_secs = int(read('urandom_min_reseed_secs')) + self.boot_id = read('boot_id') + + + def entropy_avail(self): + ''' + Get the number of bits available in the entropy pool. + Note that `poolsize` is in bytes on Linux<2.6. + + @return :int The number of bits available in the entropy pool + ''' + with open('/proc/sys/kernel/random/entropy_avail', 'rb') as file: + return int(file.read().decode('utf-8', 'replace').rstrip('\n')) + -- cgit v1.2.3-70-g09d2