]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Make errno error log more useful for getrandom()
authorFernando Fernandez Mancera <ffernandezmancera@gmail.com>
Mon, 4 Dec 2017 23:17:09 +0000 (00:17 +0100)
committerNick Mathewson <nickm@torproject.org>
Tue, 5 Dec 2017 17:05:09 +0000 (12:05 -0500)
Making errno error log more useful for getrandom() call. Adding if statement to
make difference between ENOSYS and other errors.

Fixes #24500

Signed-off-by: Fernando Fernandez Mancera <ffernandezmancera@gmail.com>
changes/ticket24500 [new file with mode: 0644]
src/common/crypto.c

diff --git a/changes/ticket24500 b/changes/ticket24500
new file mode 100644 (file)
index 0000000..0f1778d
--- /dev/null
@@ -0,0 +1,3 @@
+  o Code simplification and refactoring: 
+    - Making more useful log messages for errno errors on getrandom() call.
+      Closes ticket 24500.
index 80137b0d886e9b37ef1dd0c3f5862b16a3db2be0..7f034ee949189e0001b7683b337ec6287d987722 100644 (file)
@@ -2875,8 +2875,17 @@ crypto_strongest_rand_syscall(uint8_t *out, size_t out_len)
       tor_assert(errno != EAGAIN);
       tor_assert(errno != EINTR);
 
-      /* Probably ENOSYS. */
-      log_warn(LD_CRYPTO, "Can't get entropy from getrandom().");
+      /* Useful log message for errno. */
+      if (errno == ENOSYS) {
+        log_warn(LD_CRYPTO, "This warning is caused by ENOSYS error."
+                 " You are running a version of Tor built to support"
+                 " getrandom(), but the kernel is too old and doesn't"
+                 " implement this function.");
+      } else {
+        log_warn(LD_CRYPTO, "Can't get entropy from getrandom(). %s error.",
+                 strerror(errno));
+      }
+
       getrandom_works = 0; /* Don't bother trying again. */
       return -1;
       /* LCOV_EXCL_STOP */