diff options
author | he <he@pkgsrc.org> | 2015-12-12 21:39:25 +0000 |
---|---|---|
committer | he <he@pkgsrc.org> | 2015-12-12 21:39:25 +0000 |
commit | cb09855a476db649cdc2667bd5e4a0218dd11f34 (patch) | |
tree | 12326ea12de2437b20d69ad60bb3d32895e38032 /sysutils | |
parent | bb78adeb184352b31225751ebc39a983d0e8983e (diff) | |
download | pkgsrc-cb09855a476db649cdc2667bd5e4a0218dd11f34.tar.gz |
Improve the entropy plugin on NetBSD to keep /dev/urandom open between
polls, instead of re-opening and closing it for each round, since that
will needlessly reduce the kernel's entropy estimate.
Bump PKGREVISION.
Diffstat (limited to 'sysutils')
-rw-r--r-- | sysutils/collectd/Makefile | 4 | ||||
-rw-r--r-- | sysutils/collectd/distinfo | 4 | ||||
-rw-r--r-- | sysutils/collectd/patches/patch-src_entropy.c | 42 |
3 files changed, 32 insertions, 18 deletions
diff --git a/sysutils/collectd/Makefile b/sysutils/collectd/Makefile index 10232cd32b4..19bd82658a7 100644 --- a/sysutils/collectd/Makefile +++ b/sysutils/collectd/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.13 2015/09/12 19:04:56 he Exp $ +# $NetBSD: Makefile,v 1.14 2015/12/12 21:39:25 he Exp $ -PKGREVISION= 8 +PKGREVISION= 9 .include "../../sysutils/collectd/Makefile.common" COMMENT= Statistics collection daemon base diff --git a/sysutils/collectd/distinfo b/sysutils/collectd/distinfo index 93f5285a160..22a164d861d 100644 --- a/sysutils/collectd/distinfo +++ b/sysutils/collectd/distinfo @@ -1,4 +1,4 @@ -$NetBSD: distinfo,v 1.23 2015/11/04 01:32:08 agc Exp $ +$NetBSD: distinfo,v 1.24 2015/12/12 21:39:25 he Exp $ SHA1 (collectd-5.5.0.tar.gz) = d24e284c1eae20c5e75b846c8b2612ab65bd5565 RMD160 (collectd-5.5.0.tar.gz) = 2197758942a5fe56e4eabda3786f09d4138e943a @@ -16,7 +16,7 @@ SHA1 (patch-src_config.h.in) = be17db23b6ee7a90ba57e73f073ed5be11c369c5 SHA1 (patch-src_cpu.c) = 55b5cfc69bf0df279d1a12003eb6a8e681155e18 SHA1 (patch-src_df.c) = 7e75dfbc72ecad48eb0eb7427a19329daf6b9a60 SHA1 (patch-src_disk.c) = 159862e8ca1e841e3c4013c03ba03f059fdbbab5 -SHA1 (patch-src_entropy.c) = 46d5357d8407584943e9259325989e64a8710cc0 +SHA1 (patch-src_entropy.c) = 2847de5df6014a7f31384a2a84096d9fb4547503 SHA1 (patch-src_irq.c) = 6b621474de35a5879105025d1a2848e4896b8479 SHA1 (patch-src_libcollectclient_network__buffer.c) = e07d403d299613fa0885a0e7285849eb85510253 SHA1 (patch-src_memory.c) = f48d50245176426e26af7fa1b1f4ff6fbf0b1d95 diff --git a/sysutils/collectd/patches/patch-src_entropy.c b/sysutils/collectd/patches/patch-src_entropy.c index 026ee0e61b7..348298bb238 100644 --- a/sysutils/collectd/patches/patch-src_entropy.c +++ b/sysutils/collectd/patches/patch-src_entropy.c @@ -1,6 +1,9 @@ -$NetBSD: patch-src_entropy.c,v 1.4 2015/09/01 09:31:46 he Exp $ +$NetBSD: patch-src_entropy.c,v 1.5 2015/12/12 21:39:25 he Exp $ Provide a NetBSD implementation for graphing available entropy. +This version tries to keep /dev/urandom open (for repeated use), +instead of constantly re-opening/closing it, since the latter will +needlessly reduce the kernel's entropy estimate. --- src/entropy.c.orig 2015-03-10 14:14:45.000000000 +0000 +++ src/entropy.c @@ -13,33 +16,33 @@ Provide a NetBSD implementation for graphing available entropy. -#endif - -#define ENTROPY_FILE "/proc/sys/kernel/random/entropy_avail" -+static void entropy_submit (double); -+static int entropy_read (void); - +- -static void entropy_submit (double entropy) -{ - value_t values[1]; - value_list_t vl = VALUE_LIST_INIT; ++static void entropy_submit (double); ++static int entropy_read (void); + +- values[0].gauge = entropy; +#if !KERNEL_LINUX && !KERNEL_NETBSD +# error "No applicable input method." +#endif -- values[0].gauge = entropy; -+#if KERNEL_LINUX - - vl.values = values; - vl.values_len = 1; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); - sstrncpy (vl.plugin, "entropy", sizeof (vl.plugin)); - sstrncpy (vl.type, "entropy", sizeof (vl.type)); -- ++#if KERNEL_LINUX + - plugin_dispatch_values (&vl); -} +#define ENTROPY_FILE "/proc/sys/kernel/random/entropy_avail" static int entropy_read (void) { -@@ -74,6 +63,56 @@ static int entropy_read (void) +@@ -74,6 +63,67 @@ static int entropy_read (void) return (0); } @@ -48,6 +51,12 @@ Provide a NetBSD implementation for graphing available entropy. +#if KERNEL_NETBSD +/* Provide a NetBSD implementation, partial from rndctl.c */ + ++/* ++ * Improved to keep the /dev/urandom open, since there's a consumption ++ * of entropy from /dev/random for every open of /dev/urandom, and this ++ * will end up opening /dev/urandom lots of times. ++ */ ++ +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/param.h> @@ -61,14 +70,19 @@ Provide a NetBSD implementation for graphing available entropy. +entropy_read (void) +{ + rndpoolstat_t rs; -+ int fd; ++ static int fd; + -+ fd = open(_PATH_URANDOM, O_RDONLY, 0644); -+ if (fd < 0) -+ return -1; ++ if (fd == 0) { ++ fd = open(_PATH_URANDOM, O_RDONLY, 0644); ++ if (fd < 0) ++ return -1; ++ } + -+ if (ioctl(fd, RNDGETPOOLSTAT, &rs) < 0) ++ if (ioctl(fd, RNDGETPOOLSTAT, &rs) < 0) { ++ (void) close(fd); ++ fd = 0; /* signal a reopening on next attempt */ + return -1; ++ } + + entropy_submit (rs.curentropy); + |