Skip to content

Commit

Permalink
Added new verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jirka Hladky committed Jan 5, 2022
1 parent 1af265d commit 1f3e530
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions man/haveged.8
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Set diagnostic bitmap as sum of following options:

32=Show all online test completion detail

64=Show info on RNDADDENTROPY operation

Default is 0. Use -1 for all diagnostics.
.TP
-w nnn, --write=nnn
Expand Down
2 changes: 2 additions & 0 deletions src/havege.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ typedef int (*pRawIn)(volatile H_UINT *pData, H_UINT szData);
#define H_DEBUG_LOOP 0x008 /* Show loop parameters */
#define H_DEBUG_COMPILE 0x010 /* Show assembly info */
#define H_DEBUG_OLT 0x020 /* Show all test info */
#define H_RNDADDENTROPY_INFO 0x040 /* RNDADDENTROPY info */

#define H_DEBUG_RAW_OUT 0x100 /* diagnostic output */
#define H_DEBUG_RAW_IN 0x200 /* diagnostic input */
#define H_DEBUG_TEST_IN 0x400 /* input test data */

/**
* Initialization parameters. Use non-zero values to override default values.
* Notes:
Expand Down
16 changes: 14 additions & 2 deletions src/haveged.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int main(int argc, char **argv)
#if NUMBER_CORES>1
"t", "threads", "1", "Number of threads",
#endif
"v", "verbose", "1", "Verbose mask 0=none,1=summary,2=retries,4=timing,8=loop,16=code,32=test",
"v", "verbose", "1", "Verbose mask 0=none,1=summary,2=retries,4=timing,8=loop,16=code,32=test,64=RNDADDENTROPY",
"w", "write", "1", "Set write_wakeup_threshold [bits]",
"V", "version", "0", "Print version information and exit",
"h", "help", "0", "This help"
Expand Down Expand Up @@ -636,6 +636,8 @@ static void run_daemon( /* RETURN: nothing */
t[0] = 0;
for(;;) {
int current,nbytes,r,max=0;
H_UINT fills;
char buf[120];
fd_set write_fd;
#ifndef NO_COMMAND_MODE
fd_set read_fd;
Expand All @@ -649,6 +651,7 @@ static void run_daemon( /* RETURN: nothing */
/* add entropy on daemon start and then every 60 seconds unconditionally */
nbytes = poolSize / 2;
r = (nbytes+sizeof(H_UINT)-1)/sizeof(H_UINT);
fills = h->n_fills;
if (havege_rng(h, (H_UINT *)output->buf, r)<1)
error_exit("RNG failed! %d", h->error);
output->buf_size = nbytes;
Expand All @@ -661,6 +664,10 @@ static void run_daemon( /* RETURN: nothing */
params->exit_code = 0;
error_exit("Entropy refilled once (%d bytes), exiting.", nbytes);
}
if (0 != (params->verbose & H_RNDADDENTROPY_INFO) && h->n_fills > fills) {
if (havege_status_dump(h, H_SD_TOPIC_SUM, buf, sizeof(buf))>0)
print_msg("%s\n", buf);
}
t[0] = t[1];
continue;
}
Expand Down Expand Up @@ -738,6 +745,7 @@ static void run_daemon( /* RETURN: nothing */
if(nbytes<1) continue;
/* get that many random bytes */
r = (nbytes+sizeof(H_UINT)-1)/sizeof(H_UINT);
fills = h->n_fills;
if (havege_rng(h, (H_UINT *)output->buf, r)<1)
error_exit("RNG failed! %d", h->error);
output->buf_size = nbytes;
Expand All @@ -747,6 +755,10 @@ static void run_daemon( /* RETURN: nothing */
if (ioctl(random_fd, RNDADDENTROPY, output) == -1)
error_exit("RNDADDENTROPY failed!");
h->n_entropy_bytes += nbytes;
if (0 != (params->verbose & H_RNDADDENTROPY_INFO) && h->n_fills > fills) {
if (havege_status_dump(h, H_SD_TOPIC_SUM, buf, sizeof(buf))>0)
print_msg("%s\n", buf);
}
}
}
/**
Expand Down Expand Up @@ -909,7 +921,7 @@ void print_msg( /* RETURN: nothing */
...) /* IN: args */
{
char buffer[128];

va_list ap;
va_start(ap, format);
snprintf(buffer, sizeof(buffer), "%s: %s", params->daemon, format);
Expand Down

0 comments on commit 1f3e530

Please sign in to comment.