optimize-random-device-open.patch
Signed-off-by: Andy Green <andy.green@linaro.org>
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index afb0f07..d4bfe75 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -249,15 +249,16 @@
break;
}
+ close(this->fd_random);
+
#ifdef LWS_OPENSSL_SUPPORT
- if (this && this->ssl_ctx)
+ if (this->ssl_ctx)
SSL_CTX_free(this->ssl_ctx);
- if (this && this->ssl_client_ctx)
+ if (this->ssl_client_ctx)
SSL_CTX_free(this->ssl_client_ctx);
#endif
- if (this)
- free(this);
+ free(this);
}
/**
@@ -675,6 +676,13 @@
this->http_proxy_address[0] = '\0';
this->options = options;
+ this->fd_random = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY);
+ if (this->fd_random < 0) {
+ fprintf(stderr, "Unable to open random device %s %d\n",
+ SYSTEM_RANDOM_FILEPATH, this->fd_random);
+ return NULL;
+ }
+
/* find canonical hostname */
hostname[(sizeof hostname) - 1] = '\0';