From 313360e6e6aa6bc56e1bc3661b68df5279b6b4bc Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Tue, 5 Dec 2017 00:17:09 +0100 Subject: [PATCH 1/2] Make errno error log more useful for getrandom() 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 --- changes/ticket24500 | 3 +++ src/common/crypto.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 changes/ticket24500 diff --git a/changes/ticket24500 b/changes/ticket24500 new file mode 100644 index 000000000..0f1778d46 --- /dev/null +++ b/changes/ticket24500 @@ -0,0 +1,3 @@ + o Code simplification and refactoring: + - Making more useful log messages for errno errors on getrandom() call. + Closes ticket 24500. diff --git a/src/common/crypto.c b/src/common/crypto.c index 80137b0d8..7f034ee94 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -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 */ From 779e4b9dcf850770a7c30104f714f4a59c2955a8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 5 Dec 2017 12:09:57 -0500 Subject: [PATCH 2/2] Tweaks to strings in 24500 --- changes/ticket24500 | 4 ++-- src/common/crypto.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/changes/ticket24500 b/changes/ticket24500 index 0f1778d46..b49b7a555 100644 --- a/changes/ticket24500 +++ b/changes/ticket24500 @@ -1,3 +1,3 @@ - o Code simplification and refactoring: - - Making more useful log messages for errno errors on getrandom() call. + o Minor features (logging): + - Provide better warnings when the getrandom() syscall fails. Closes ticket 24500. diff --git a/src/common/crypto.c b/src/common/crypto.c index 7f034ee94..380f038f4 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -2877,12 +2877,12 @@ crypto_strongest_rand_syscall(uint8_t *out, size_t out_len) /* Useful log message for errno. */ if (errno == ENOSYS) { - log_warn(LD_CRYPTO, "This warning is caused by ENOSYS error." + log_warn(LD_CRYPTO, "Can't get entropy from getrandom(). " " You are running a version of Tor built to support" - " getrandom(), but the kernel is too old and doesn't" - " implement this function."); + " getrandom(), but the kernel doesn't implement this" + " implement this function--probably because it is too old?"); } else { - log_warn(LD_CRYPTO, "Can't get entropy from getrandom(). %s error.", + log_warn(LD_CRYPTO, "Can't get entropy from getrandom(): %s.", strerror(errno)); }