added entropy
authorAaron Marcher <info@nulltime.net>
Fri, 3 Jun 2016 11:04:15 +0000 (13:04 +0200)
committerAaron Marcher (drkhsh) <info@nulltime.net>
Fri, 3 Jun 2016 11:04:15 +0000 (13:04 +0200)
config.def.h
slstatus.c
slstatus.h

index 38af2b911e72f24265b321df2d5f2490d5167a6e..813bded504d1705b425fe21e12afbe180da2a146 100644 (file)
@@ -16,6 +16,7 @@ static unsigned int update_interval = 1;
 - cpu_perc (cpu usage in percent) [argument: NULL]
 - datetime (date and time) [argument: format]
 - disk_perc (disk usage in percent) [argument: mountpoint]
+- entropy (available entropy) [argument: NULL]
 - ram_perc (ram usage in percent) [argument: NULL]
 - temp (temperature in degrees) [argument: temperature file]
 - vol_perc (alsa volume and mute status in percent) [argument: soundcard]
@@ -29,5 +30,6 @@ static const struct arg args[] = {
     { ram_perc,     "ram %3s | ",   NULL },
     { vol_perc,     "vol %4s | ",   "default" },
     { disk_perc,    "ssd %3s | ",   "/" },
+    { entropy,      "crypt %s | ",  NULL },
     { datetime,     "%s",           "%y-%m-%d %H:%M:%S" },
 };
index ee6b16080cb01724aeeae0060359ca9a45661c29..357446810aaa70f2395767b9647b3ece2f571c89 100644 (file)
@@ -181,6 +181,29 @@ disk_perc(const char *mountpoint)
     return smprintf("%d%%", perc);
 }
 
+/* entropy available */
+char *
+entropy(const char *null)
+{
+    int entropy = 0;
+    FILE *fp;
+
+    /* open entropy file */
+    if (!(fp = fopen("/proc/sys/kernel/random/entropy_avail", "r"))) {
+        fprintf(stderr, "Could not open entropy file.\n");
+        return smprintf("n/a");
+    }
+
+    /* extract entropy */
+    fscanf(fp, "%d", &entropy);
+
+    /* close entropy file */
+    fclose(fp);
+
+    /* return entropy */
+    return smprintf("%d", entropy);
+}
+
 /* ram percentage */
 char *
 ram_perc(const char *null)
index fb358dc898782a71b7fd0fd3323647d036e7942c..12c03c761014e305e0e3d2b41b58427fe00e9e52 100644 (file)
@@ -18,6 +18,7 @@ char *battery_perc(const char *);
 char *cpu_perc(const char *);
 char *datetime(const char *);
 char *disk_perc(const char *);
+char *entropy(const char*);
 char *ram_perc(const char *);
 char *temp(const char *);
 char *vol_perc(const char *);