From 9a016c9377ef400a4bb6692df8dc78985fc060df Mon Sep 17 00:00:00 2001 From: Philip Kovacs Date: Thu, 30 Nov 2006 20:46:34 +0000 Subject: [PATCH] added , , for crypto freaks git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@797 7f574dfc-610e-0410-a909-a81674777703 --- ChangeLog | 4 ++++ README | 12 ++++++++++++ doc/conky.1 | 12 ++++++++++++ doc/variables.xml | 29 +++++++++++++++++++++++++++++ src/common.c | 2 ++ src/conky.c | 29 +++++++++++++++++++++++++++++ src/conky.h | 8 ++++++++ src/freebsd.c | 5 +++++ src/linux.c | 21 +++++++++++++++++++++ src/netbsd.c | 4 ++++ 10 files changed, 126 insertions(+) diff --git a/ChangeLog b/ChangeLog index eb5cb49..973ba6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ # $Id$ +2006-11-30 + * Added $entropy_avail, $entropy_poolsize and $entropy_bar + for the crypto freaks. + 2006-11-28 * Rearrange retry attempts in pop3 and imap code, removing sleep() calls which cause the whole process to sleep, not just the thread. diff --git a/README b/README index 62d3e33..d894dff 100644 --- a/README +++ b/README @@ -551,6 +551,18 @@ VARIABLES else Text to show if any of the above are not true + entropy_avail + Current entropy available for crypto freaks + + + entropy_bar (height),(width) + Normalized bar of available entropy for crypto freaks + + + entropy_poolsize + Total size of system entropy pool for crypto freaks + + exec command Executes a shell command and displays the output in conky. warn- ing: this takes a lot more resources than other variables. I'd diff --git a/doc/conky.1 b/doc/conky.1 index 520135e..644d933 100644 --- a/doc/conky.1 +++ b/doc/conky.1 @@ -520,6 +520,18 @@ Download speed graph, colours defined in hex, minus the #. If scale is non-zero, Text to show if any of the above are not true .TP +\fB\*(T<\fBentropy_avail\fR\*(T>\fR +Current entropy available for crypto freaks + +.TP +\fB\*(T<\fBentropy_bar\fR\*(T>\fR \*(T<\fB(height),(width)\fR\*(T> +Normalized bar of available entropy for crypto freaks + +.TP +\fB\*(T<\fBentropy_poolsize\fR\*(T>\fR +Total size of system entropy pool for crypto freaks + +.TP \fB\*(T<\fBexec\fR\*(T>\fR \*(T<\fBcommand\fR\*(T> Executes a shell command and displays the output in conky. warning: this takes a lot more resources than other variables. I'd recommend coding wanted behaviour in C and posting a patch. diff --git a/doc/variables.xml b/doc/variables.xml index 93dd23d..9c5ab0d 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -411,6 +411,35 @@ + + + + Current entropy available for crypto freaks + + + + + + + + + + Normalized bar of available entropy for crypto freaks + + + + + + + + + Total size of system entropy pool for crypto freaks + + + + + + diff --git a/src/common.c b/src/common.c index e0d6365..6ac265a 100644 --- a/src/common.c +++ b/src/common.c @@ -257,6 +257,8 @@ void update_stuff() if (NEED(INFO_TCP_PORT_MONITOR)) update_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection ); #endif + if (NEED(INFO_ENTROPY)) + update_entropy(); } int round_to_int(float f) diff --git a/src/conky.c b/src/conky.c index 23ba263..ade1f8e 100644 --- a/src/conky.c +++ b/src/conky.c @@ -1081,6 +1081,9 @@ enum text_object_type { #ifdef HDDTEMP OBJ_hddtemp, #endif + OBJ_entropy_avail, + OBJ_entropy_poolsize, + OBJ_entropy_bar }; struct text_object { @@ -1947,6 +1950,10 @@ static void free_text_objects(unsigned int count, struct text_object *objs) free(objs[i].data.hddtemp.addr); break; #endif + case OBJ_entropy_avail: + case OBJ_entropy_poolsize: + case OBJ_entropy_bar: + break; } } free(objs); @@ -2966,6 +2973,12 @@ static struct text_object *construct_text_object(const char *s, const char *arg, } END #endif + OBJ(entropy_avail, INFO_ENTROPY) END + OBJ(entropy_poolsize, INFO_ENTROPY) END + OBJ(entropy_bar, INFO_ENTROPY) + (void) scan_bar(arg, &obj->a, &obj->b); + END + { char buf[256]; ERR("unknown variable %s", s); @@ -4687,6 +4700,22 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object * iconv_selected = 0; } #endif + OBJ(entropy_avail) + { + snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail); + } + OBJ(entropy_poolsize) + { + snprintf(p, p_max_size, "%d", cur->entropy.poolsize); + } + OBJ(entropy_bar) + { + double entropy_perc; + entropy_perc = (double)cur->entropy.entropy_avail / + (double)cur->entropy.poolsize; + new_bar(p,obj->a,obj->b,(int)(entropy_perc * 255.0f)); + } + break; } diff --git a/src/conky.h b/src/conky.h index 67f9c65..4693df7 100644 --- a/src/conky.h +++ b/src/conky.h @@ -186,6 +186,12 @@ struct bmpx_s { }; #endif +void update_entropy(); +struct entropy_s { + unsigned int entropy_avail; + unsigned int poolsize; +}; + #ifdef TCP_PORT_MONITOR #include "libtcp-portmon.h" #define MIN_PORT_MONITORS_DEFAULT 16 @@ -226,6 +232,7 @@ enum { #ifdef XMMS2 INFO_XMMS2 = 22, #endif + INFO_ENTROPY = 23, }; @@ -288,6 +295,7 @@ struct information { tcp_port_monitor_collection_t * p_tcp_port_monitor_collection; #endif short kflags; /* kernel settings, see enum KFLAG */ + struct entropy_s entropy; }; enum { diff --git a/src/freebsd.c b/src/freebsd.c index 4ffeb8a..1ddc2a1 100644 --- a/src/freebsd.c +++ b/src/freebsd.c @@ -876,6 +876,11 @@ char #endif +void update_entropy (void) +{ + /* mirrorbox: can you do anything equivalent in freebsd? -drphibes. */ +} + /* empty stub so conky links */ void free_all_processes(void) diff --git a/src/linux.c b/src/linux.c index 4a63514..8193a38 100644 --- a/src/linux.c +++ b/src/linux.c @@ -1756,3 +1756,24 @@ Peter Tarjan (ptarjan@citromail.hu) return; } + +void update_entropy (void) +{ + static int rep; + const char *entropy_avail = "/proc/sys/kernel/random/entropy_avail"; + const char *entropy_poolsize = "/proc/sys/kernel/random/poolsize"; + FILE *fp1, *fp2; + + info.entropy.entropy_avail=0; + info.entropy.poolsize=0; + + if ( ((fp1 = open_file (entropy_avail, &rep))==NULL) || + ((fp2 = open_file (entropy_poolsize, &rep))==NULL) ) + return; + + fscanf (fp1, "%u", &info.entropy.entropy_avail); + fscanf (fp2, "%u", &info.entropy.poolsize); + + fclose (fp1); + fclose (fp2); +} diff --git a/src/netbsd.c b/src/netbsd.c index 5a335f0..57b4ebb 100644 --- a/src/netbsd.c +++ b/src/netbsd.c @@ -366,3 +366,7 @@ void get_acpi_fan( char * p_client_buffer, size_t client_buffer_size ) return; } + +void update_entropy (void) +{ +} -- 1.7.9.5