Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MXS-2597: Log libmicrohttpd errors on startup
By enabling the debug messages only at startup, we'll get log messages for
any daemon startup failures and we exlude the verbose parsing errors that
malformed requests cause.
  • Loading branch information
markus456 committed Jul 16, 2019
1 parent 797069d commit bc2f7f4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion server/core/admin.cc
Expand Up @@ -372,6 +372,19 @@ static bool load_ssl_certificates()
return rval;
}

static bool log_daemon_errors = true;

void admin_log_error(void* arg, const char* fmt, va_list ap)
{
if (log_daemon_errors)
{
char buf[1024];
vsnprintf(buf, sizeof(buf), fmt, ap);
trim(buf);
MXS_ERROR("HTTP daemon error: %s\n", buf);
}
}

bool mxs_admin_init()
{
struct sockaddr_storage addr;
Expand All @@ -380,7 +393,7 @@ bool mxs_admin_init()
config_get_global_options()->admin_port,
&addr))
{
int options = MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY;
int options = MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY | MHD_USE_DEBUG;

if (addr.ss_family == AF_INET6)
{
Expand All @@ -395,6 +408,7 @@ bool mxs_admin_init()

// The port argument is ignored and the port in the struct sockaddr is used instead
http_daemon = MHD_start_daemon(options, 0, NULL, NULL, handle_client, NULL,
MHD_OPTION_EXTERNAL_LOGGER, admin_log_error, NULL,
MHD_OPTION_NOTIFY_COMPLETED, close_client, NULL,
MHD_OPTION_SOCK_ADDR, &addr,
!using_ssl ? MHD_OPTION_END :
Expand All @@ -404,6 +418,9 @@ bool mxs_admin_init()
MHD_OPTION_END);
}

// Silence all other errors to prevent malformed requests from flooding the log
log_daemon_errors = false;

return http_daemon != NULL;
}

Expand Down

0 comments on commit bc2f7f4

Please sign in to comment.