From: Arran Cudbard-Bell Date: Fri, 5 Jun 2015 02:38:31 +0000 (-0600) Subject: More logging fixes X-Git-Tag: release_3_0_9~256 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b10168d95dcc6481f2a89c2fde1214c7d391cea5;p=thirdparty%2Ffreeradius-server.git More logging fixes --- diff --git a/src/include/log.h b/src/include/log.h index 0612a5af089..974b3cb2081 100644 --- a/src/include/log.h +++ b/src/include/log.h @@ -329,7 +329,7 @@ void fr_canonicalize_error(TALLOC_CTX *ctx, char **spaces, char **text, ssize_t * @param fmt printf style format string. * @param ... printf arguments. */ - #define ROPTIONAL(_l_request, _l_global, fmt, ...) \ + #define MOD_ROPTIONAL(_l_request, _l_global, fmt, ...) \ do {\ if (request) {\ _l_request(fmt, ## __VA_ARGS__);\ @@ -338,6 +338,26 @@ do {\ }\ } while (0) +/** Use different logging functions depending on whether request is NULL or not. + * + * This is useful for areas of code which are run on server startup, and when + * processing requests. + * + * @param _l_prefix added to global messages. + * @param _l_request The name of a R* logging macro e.g. RDEBUG3. + * @param _l_global The name of a global logging macro e.g. DEBUG3. + * @param fmt printf style format string. + * @param ... printf arguments. + */ + #define ROPTIONAL(_l_request, _l_global, _l_prefix, fmt, ...) \ +do {\ + if (request) {\ + _l_request(fmt, ## __VA_ARGS__);\ + } else {\ + _l_global(_l_prefix ": " fmt, ## __VA_ARGS__);\ + }\ +} while (0) + #define RATE_LIMIT_ENABLED rate_limit_enabled() //!< True if rate limiting is enabled. /** Rate limit messages * diff --git a/src/main/tls.c b/src/main/tls.c index d4f38f9c825..3c0d3119a66 100644 --- a/src/main/tls.c +++ b/src/main/tls.c @@ -56,7 +56,7 @@ USES_APPLE_DEPRECATED_API /* OpenSSL API has been deprecated by Apple */ # endif # include -#define MOD_PREFIX "tls" +#define LOG_PREFIX "tls" #ifdef ENABLE_OPENSSL_VERSION_CHECK typedef struct libssl_defect { @@ -454,7 +454,7 @@ static int int_ssl_check(REQUEST *request, SSL *s, int ret, char const *text) if ((l = ERR_get_error()) != 0) { char const *p = ERR_error_string(l, NULL); - if (p) ROPTIONAL(REDEBUG, ERROR, "SSL says: %s", p); + if (p) ROPTIONAL(REDEBUG, ERROR, LOG_PREFIX, "SSL says: %s", p); } e = SSL_get_error(s, ret); @@ -484,11 +484,11 @@ static int int_ssl_check(REQUEST *request, SSL *s, int ret, char const *text) * being regarded as "dead". */ case SSL_ERROR_SYSCALL: - ROPTIONAL(REDEBUG, ERROR, "%s failed in a system call (%d), TLS session failed", text, ret); + ROPTIONAL(REDEBUG, ERROR, LOG_PREFIX, "%s failed in a system call (%d), TLS session failed", text, ret); return 0; case SSL_ERROR_SSL: - ROPTIONAL(REDEBUG, ERROR, "%s failed inside of TLS (%d), TLS session failed", text, ret); + ROPTIONAL(REDEBUG, ERROR, LOG_PREFIX, "%s failed inside of TLS (%d), TLS session failed", text, ret); return 0; default: @@ -498,7 +498,7 @@ static int int_ssl_check(REQUEST *request, SSL *s, int ret, char const *text) * them - so "politely inform" the caller that * the code needs updating here. */ - ROPTIONAL(REDEBUG, ERROR, "FATAL SSL error: %d", e); + ROPTIONAL(REDEBUG, ERROR, LOG_PREFIX, "FATAL SSL error: %d", e); return 0; } @@ -539,9 +539,7 @@ int tls_handshake_recv(REQUEST *request, tls_session_t *ssn) return 1; } - if (!int_ssl_check(request, ssn->ssl, err, "SSL_read")) { - return 0; - } + if (!int_ssl_check(request, ssn->ssl, err, "SSL_read")) return 0; /* Some Extra STATE information for easy debugging */ if (SSL_is_init_finished(ssn->ssl)) RDEBUG2("SSL Connection Established"); diff --git a/src/modules/rlm_sql/sql.c b/src/modules/rlm_sql/sql.c index 0d362d59e14..2e79ab3a073 100644 --- a/src/modules/rlm_sql/sql.c +++ b/src/modules/rlm_sql/sql.c @@ -256,7 +256,7 @@ sql_rcode_t rlm_sql_fetch_row(rlm_sql_t *inst, REQUEST *request, rlm_sql_handle_ */ ret = (inst->module->sql_fetch_row)(*handle, inst->config); if (ret < 0) { - ROPTIONAL(RERROR, ERROR, "Error fetching row"); + MOD_ROPTIONAL(RERROR, ERROR, "Error fetching row"); rlm_sql_print_error(inst, request, *handle, false); } @@ -282,7 +282,7 @@ void rlm_sql_print_error(rlm_sql_t *inst, REQUEST *request, rlm_sql_handle_t *ha num = (inst->module->sql_error)(handle->log_ctx, log, (sizeof(log) / sizeof(*log)), handle, inst->config); if (num == 0) { - ROPTIONAL(RERROR, ERROR, "Unknown error"); + MOD_ROPTIONAL(RERROR, ERROR, "Unknown error"); return; } @@ -293,21 +293,21 @@ void rlm_sql_print_error(rlm_sql_t *inst, REQUEST *request, rlm_sql_handle_t *ha switch (log[i].type) { case L_ERR: - ROPTIONAL(RERROR, ERROR, "%s: %s", driver, log[i].msg); + MOD_ROPTIONAL(RERROR, ERROR, "%s: %s", driver, log[i].msg); break; case L_WARN: - ROPTIONAL(RWARN, WARN, "%s: %s", driver, log[i].msg); + MOD_ROPTIONAL(RWARN, WARN, "%s: %s", driver, log[i].msg); break; case L_INFO: - ROPTIONAL(RINFO, INFO, "%s: %s", driver, log[i].msg); + MOD_ROPTIONAL(RINFO, INFO, "%s: %s", driver, log[i].msg); break; case L_DBG: default: debug: - ROPTIONAL(RDEBUG, DEBUG, "%s: %s", driver, log[i].msg); + MOD_ROPTIONAL(RDEBUG, DEBUG, "%s: %s", driver, log[i].msg); break; } } @@ -353,7 +353,7 @@ sql_rcode_t rlm_sql_query(rlm_sql_t *inst, REQUEST *request, rlm_sql_handle_t ** * a new connection, then give up. */ for (i = 0; i < (count + 1); i++) { - ROPTIONAL(RDEBUG2, DEBUG2, "Executing query: %s", query); + MOD_ROPTIONAL(RDEBUG2, DEBUG2, "Executing query: %s", query); ret = (inst->module->sql_query)(*handle, inst->config, query); switch (ret) { @@ -410,7 +410,7 @@ sql_rcode_t rlm_sql_query(rlm_sql_t *inst, REQUEST *request, rlm_sql_handle_t ** return ret; } - ROPTIONAL(RERROR, ERROR, "Hit reconnection limit"); + MOD_ROPTIONAL(RERROR, ERROR, "Hit reconnection limit"); return RLM_SQL_ERROR; } @@ -452,7 +452,7 @@ sql_rcode_t rlm_sql_select_query(rlm_sql_t *inst, REQUEST *request, rlm_sql_hand * For sanity, for when no connections are viable, and we can't make a new one */ for (i = 0; i < (count + 1); i++) { - ROPTIONAL(RDEBUG2, DEBUG2, "Executing select query: %s", query); + MOD_ROPTIONAL(RDEBUG2, DEBUG2, "Executing select query: %s", query); ret = (inst->module->sql_select_query)(*handle, inst->config, query); switch (ret) { @@ -481,7 +481,7 @@ sql_rcode_t rlm_sql_select_query(rlm_sql_t *inst, REQUEST *request, rlm_sql_hand return ret; } - ROPTIONAL(RERROR, ERROR, "Hit reconnection limit"); + MOD_ROPTIONAL(RERROR, ERROR, "Hit reconnection limit"); return RLM_SQL_ERROR; }