urngd: fix busy loop in case of ioctl cause high cpu usage

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
This commit is contained in:
lean 2021-06-21 11:52:55 +08:00 committed by Tianling Shen
parent 6229fcb233
commit 562227aa9b
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
2 changed files with 24 additions and 5 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=urngd
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/urngd.git
@ -15,14 +15,14 @@ PKG_LICENSE_FILES:=
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk
define Package/$(PKG_NAME)
define Package/urngd
SECTION:=utils
CATEGORY:=Base system
TITLE:=OpenWrt non-physical true random number generator based on timing jitter
DEPENDS:=+libubox
endef
define Package/$(PKG_NAME)/description
define Package/urngd/description
urngd is OpenWrt's micro non-physical true random number generator based on
timing jitter.
@ -36,11 +36,11 @@ define Package/$(PKG_NAME)/description
Jitter RNGd provides a source of sufficient entropy.
endef
define Package/$(PKG_NAME)/install
define Package/urngd/install
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/$(PKG_NAME).init $(1)/etc/init.d/$(PKG_NAME)
$(INSTALL_DIR) $(1)/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/sbin/$(PKG_NAME)
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
$(eval $(call BuildPackage,urngd))

View File

@ -0,0 +1,19 @@
diff --git a/urngd.c b/urngd.c
index 35ccdec..410d300 100644
--- a/urngd.c
+++ b/urngd.c
@@ -129,9 +129,14 @@ static size_t gather_entropy(struct urngd *u)
static void low_entropy_cb(struct uloop_fd *ufd, unsigned int events)
{
struct urngd *u = container_of(ufd, struct urngd, rnd_fd);
+ size_t res;
DEBUG(2, DEV_RANDOM " signals low entropy\n");
- gather_entropy(u);
+ res = gather_entropy(u);
+ if (!res) {
+ DEBUG(2, "gather_entropy failed, delaying further attempts\n");
+ sleep(60);
+ }
}