GUAC-911: Simplify guacd logging. Log to appropriate log levels.
This commit is contained in:
parent
24aa865ce2
commit
3b266b9f05
@ -72,7 +72,7 @@ void* __guacd_client_output_thread(void* data) {
|
|||||||
|
|
||||||
int retval = client->handle_messages(client);
|
int retval = client->handle_messages(client);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
guacd_client_log_guac_error(client,
|
guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
|
||||||
"Error handling server messages");
|
"Error handling server messages");
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -81,7 +81,7 @@ void* __guacd_client_output_thread(void* data) {
|
|||||||
/* Send sync instruction */
|
/* Send sync instruction */
|
||||||
client->last_sent_timestamp = guac_timestamp_current();
|
client->last_sent_timestamp = guac_timestamp_current();
|
||||||
if (guac_protocol_send_sync(socket, client->last_sent_timestamp)) {
|
if (guac_protocol_send_sync(socket, client->last_sent_timestamp)) {
|
||||||
guacd_client_log_guac_error(client,
|
guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
|
||||||
"Error sending \"sync\" instruction");
|
"Error sending \"sync\" instruction");
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -89,7 +89,7 @@ void* __guacd_client_output_thread(void* data) {
|
|||||||
|
|
||||||
/* Flush */
|
/* Flush */
|
||||||
if (guac_socket_flush(socket)) {
|
if (guac_socket_flush(socket)) {
|
||||||
guacd_client_log_guac_error(client,
|
guacd_client_log_guac_error(client, GUAC_LOG_DEBUG,
|
||||||
"Error flushing output");
|
"Error flushing output");
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -139,7 +139,9 @@ void* __guacd_client_input_thread(void* data) {
|
|||||||
guac_client_abort(client, GUAC_PROTOCOL_STATUS_CLIENT_TIMEOUT, "Client is not responding.");
|
guac_client_abort(client, GUAC_PROTOCOL_STATUS_CLIENT_TIMEOUT, "Client is not responding.");
|
||||||
|
|
||||||
else {
|
else {
|
||||||
guacd_client_log_guac_error(client, "Error reading instruction");
|
if (guac_error != GUAC_STATUS_CLOSED)
|
||||||
|
guacd_client_log_guac_error(client, GUAC_LOG_WARNING,
|
||||||
|
"Guacamole connection failure");
|
||||||
guac_client_stop(client);
|
guac_client_stop(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,11 +157,11 @@ void* __guacd_client_input_thread(void* data) {
|
|||||||
if (guac_client_handle_instruction(client, instruction) < 0) {
|
if (guac_client_handle_instruction(client, instruction) < 0) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
guacd_client_log_guac_error(client,
|
guacd_client_log_guac_error(client, GUAC_LOG_WARNING,
|
||||||
"Client instruction handler error");
|
"Connection aborted");
|
||||||
|
|
||||||
/* Log handler details */
|
/* Log handler details */
|
||||||
guac_client_log(client, GUAC_LOG_INFO,
|
guac_client_log(client, GUAC_LOG_DEBUG,
|
||||||
"Failing instruction handler in client was \"%s\"",
|
"Failing instruction handler in client was \"%s\"",
|
||||||
instruction->opcode);
|
instruction->opcode);
|
||||||
|
|
||||||
|
@ -58,6 +58,27 @@
|
|||||||
#define GUACD_DEV_NULL "/dev/null"
|
#define GUACD_DEV_NULL "/dev/null"
|
||||||
#define GUACD_ROOT "/"
|
#define GUACD_ROOT "/"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs a reasonable explanatory message regarding handshake failure based on
|
||||||
|
* the current value of guac_error.
|
||||||
|
*/
|
||||||
|
static void guacd_log_handshake_failure() {
|
||||||
|
|
||||||
|
if (guac_error == GUAC_STATUS_CLOSED)
|
||||||
|
guacd_log(GUAC_LOG_INFO,
|
||||||
|
"Guacamole connection closed during handshake");
|
||||||
|
else if (guac_error == GUAC_STATUS_PROTOCOL_ERROR)
|
||||||
|
guacd_log(GUAC_LOG_ERROR,
|
||||||
|
"Guacamole protocol violation. Perhaps the version of "
|
||||||
|
"guacamole-client is incompatible with this version of "
|
||||||
|
"guacd?");
|
||||||
|
else
|
||||||
|
guacd_log(GUAC_LOG_WARNING,
|
||||||
|
"Guacamole handshake failed: %s",
|
||||||
|
guac_status_string(guac_error));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new guac_client for the connection on the given socket, adding
|
* Creates a new guac_client for the connection on the given socket, adding
|
||||||
* it to the client map based on its ID.
|
* it to the client map based on its ID.
|
||||||
@ -78,22 +99,25 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
guac_error_message = NULL;
|
guac_error_message = NULL;
|
||||||
|
|
||||||
/* Get protocol from select instruction */
|
/* Get protocol from select instruction */
|
||||||
select = guac_instruction_expect(
|
select = guac_instruction_expect(socket, GUACD_USEC_TIMEOUT, "select");
|
||||||
socket, GUACD_USEC_TIMEOUT, "select");
|
|
||||||
if (select == NULL) {
|
if (select == NULL) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
guacd_log_guac_error("Error reading \"select\"");
|
guacd_log_handshake_failure();
|
||||||
|
guacd_log_guac_error(GUAC_LOG_DEBUG,
|
||||||
|
"Error reading \"select\"");
|
||||||
|
|
||||||
/* Free resources */
|
/* Free resources */
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Validate args to select */
|
/* Validate args to select */
|
||||||
if (select->argc != 1) {
|
if (select->argc != 1) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
|
guacd_log_handshake_failure();
|
||||||
guacd_log(GUAC_LOG_ERROR, "Bad number of arguments to \"select\" (%i)",
|
guacd_log(GUAC_LOG_ERROR, "Bad number of arguments to \"select\" (%i)",
|
||||||
select->argc);
|
select->argc);
|
||||||
|
|
||||||
@ -111,7 +135,12 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
if (plugin == NULL) {
|
if (plugin == NULL) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
guacd_log_guac_error("Error loading client plugin");
|
if (guac_error == GUAC_STATUS_NOT_FOUND)
|
||||||
|
guacd_log(GUAC_LOG_WARNING,
|
||||||
|
"Support for selected protocol is not installed");
|
||||||
|
else
|
||||||
|
guacd_log_guac_error(GUAC_LOG_ERROR,
|
||||||
|
"Unable to load client plugin");
|
||||||
|
|
||||||
/* Free resources */
|
/* Free resources */
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
@ -123,10 +152,12 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
|| guac_socket_flush(socket)) {
|
|| guac_socket_flush(socket)) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
guacd_log_guac_error("Error sending \"args\"");
|
guacd_log_handshake_failure();
|
||||||
|
guacd_log_guac_error(GUAC_LOG_DEBUG, "Error sending \"args\"");
|
||||||
|
|
||||||
if (guac_client_plugin_close(plugin))
|
if (guac_client_plugin_close(plugin))
|
||||||
guacd_log_guac_error("Error closing client plugin");
|
guacd_log_guac_error(GUAC_LOG_WARNING,
|
||||||
|
"Unable to close client plugin");
|
||||||
|
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
return;
|
return;
|
||||||
@ -138,7 +169,8 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
if (size == NULL) {
|
if (size == NULL) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
guacd_log_guac_error("Error reading \"size\"");
|
guacd_log_handshake_failure();
|
||||||
|
guacd_log_guac_error(GUAC_LOG_DEBUG, "Error reading \"size\"");
|
||||||
|
|
||||||
/* Free resources */
|
/* Free resources */
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
@ -151,7 +183,8 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
if (audio == NULL) {
|
if (audio == NULL) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
guacd_log_guac_error("Error reading \"audio\"");
|
guacd_log_handshake_failure();
|
||||||
|
guacd_log_guac_error(GUAC_LOG_DEBUG, "Error reading \"audio\"");
|
||||||
|
|
||||||
/* Free resources */
|
/* Free resources */
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
@ -164,7 +197,8 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
if (video == NULL) {
|
if (video == NULL) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
guacd_log_guac_error("Error reading \"video\"");
|
guacd_log_handshake_failure();
|
||||||
|
guacd_log_guac_error(GUAC_LOG_DEBUG, "Error reading \"video\"");
|
||||||
|
|
||||||
/* Free resources */
|
/* Free resources */
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
@ -177,10 +211,12 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
if (connect == NULL) {
|
if (connect == NULL) {
|
||||||
|
|
||||||
/* Log error */
|
/* Log error */
|
||||||
guacd_log_guac_error("Error reading \"connect\"");
|
guacd_log_handshake_failure();
|
||||||
|
guacd_log_guac_error(GUAC_LOG_DEBUG, "Error reading \"connect\"");
|
||||||
|
|
||||||
if (guac_client_plugin_close(plugin))
|
if (guac_client_plugin_close(plugin))
|
||||||
guacd_log_guac_error("Error closing client plugin");
|
guacd_log_guac_error(GUAC_LOG_WARNING,
|
||||||
|
"Unable to close client plugin");
|
||||||
|
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
return;
|
return;
|
||||||
@ -189,7 +225,7 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
/* Get client */
|
/* Get client */
|
||||||
client = guac_client_alloc();
|
client = guac_client_alloc();
|
||||||
if (client == NULL) {
|
if (client == NULL) {
|
||||||
guacd_log_guac_error("Client could not be allocated");
|
guacd_log_guac_error(GUAC_LOG_ERROR, "Unable to create client");
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -240,10 +276,11 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
|
|
||||||
guac_client_free(client);
|
guac_client_free(client);
|
||||||
|
|
||||||
guacd_log_guac_error("Error instantiating client");
|
guacd_log_guac_error(GUAC_LOG_INFO, "Connection did not succeed");
|
||||||
|
|
||||||
if (guac_client_plugin_close(plugin))
|
if (guac_client_plugin_close(plugin))
|
||||||
guacd_log_guac_error("Error closing client plugin");
|
guacd_log_guac_error(GUAC_LOG_WARNING,
|
||||||
|
"Unable to close client plugin");
|
||||||
|
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
return;
|
return;
|
||||||
@ -252,9 +289,9 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
/* Start client threads */
|
/* Start client threads */
|
||||||
guacd_log(GUAC_LOG_INFO, "Starting client");
|
guacd_log(GUAC_LOG_INFO, "Starting client");
|
||||||
if (guacd_client_start(client))
|
if (guacd_client_start(client))
|
||||||
guacd_log(GUAC_LOG_ERROR, "Client finished abnormally");
|
guacd_log(GUAC_LOG_WARNING, "Client finished abnormally");
|
||||||
else
|
else
|
||||||
guacd_log(GUAC_LOG_INFO, "Client finished normally");
|
guacd_log(GUAC_LOG_INFO, "Client disconnected");
|
||||||
|
|
||||||
/* Remove client */
|
/* Remove client */
|
||||||
if (guacd_client_map_remove(map, client->connection_id) == NULL)
|
if (guacd_client_map_remove(map, client->connection_id) == NULL)
|
||||||
@ -272,7 +309,8 @@ static void guacd_handle_connection(guacd_client_map* map, guac_socket* socket)
|
|||||||
/* Clean up */
|
/* Clean up */
|
||||||
guac_client_free(client);
|
guac_client_free(client);
|
||||||
if (guac_client_plugin_close(plugin))
|
if (guac_client_plugin_close(plugin))
|
||||||
guacd_log(GUAC_LOG_ERROR, "Error closing client plugin");
|
guacd_log_guac_error(GUAC_LOG_WARNING,
|
||||||
|
"Unable to close client plugin");
|
||||||
|
|
||||||
/* Close socket */
|
/* Close socket */
|
||||||
guac_socket_free(socket);
|
guac_socket_free(socket);
|
||||||
@ -309,7 +347,7 @@ int daemonize() {
|
|||||||
|
|
||||||
/* Exit if we are the parent */
|
/* Exit if we are the parent */
|
||||||
if (pid > 0) {
|
if (pid > 0) {
|
||||||
guacd_log(GUAC_LOG_INFO, "Exiting and passing control to PID %i", pid);
|
guacd_log(GUAC_LOG_DEBUG, "Exiting and passing control to PID %i", pid);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +363,7 @@ int daemonize() {
|
|||||||
|
|
||||||
/* Exit if we are the parent */
|
/* Exit if we are the parent */
|
||||||
if (pid > 0) {
|
if (pid > 0) {
|
||||||
guacd_log(GUAC_LOG_INFO, "Exiting and passing control to PID %i", pid);
|
guacd_log(GUAC_LOG_DEBUG, "Exiting and passing control to PID %i", pid);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +432,7 @@ int main(int argc, char* argv[]) {
|
|||||||
openlog(GUACD_LOG_NAME, LOG_PID, LOG_DAEMON);
|
openlog(GUACD_LOG_NAME, LOG_PID, LOG_DAEMON);
|
||||||
|
|
||||||
/* Log start */
|
/* Log start */
|
||||||
guacd_log(GUAC_LOG_INFO, "Guacamole proxy daemon (guacd) version " VERSION);
|
guacd_log(GUAC_LOG_INFO, "Guacamole proxy daemon (guacd) version " VERSION " started");
|
||||||
|
|
||||||
/* Get addresses for binding */
|
/* Get addresses for binding */
|
||||||
if ((retval = getaddrinfo(config->bind_host, config->bind_port,
|
if ((retval = getaddrinfo(config->bind_host, config->bind_port,
|
||||||
@ -594,7 +632,8 @@ int main(int argc, char* argv[]) {
|
|||||||
if (ssl_context != NULL) {
|
if (ssl_context != NULL) {
|
||||||
socket = guac_socket_open_secure(ssl_context, connected_socket_fd);
|
socket = guac_socket_open_secure(ssl_context, connected_socket_fd);
|
||||||
if (socket == NULL) {
|
if (socket == NULL) {
|
||||||
guacd_log_guac_error("Error opening secure connection");
|
guacd_log_guac_error(GUAC_LOG_ERROR,
|
||||||
|
"Unable to set up SSL/TLS");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,20 +103,19 @@ void guacd_client_log(guac_client* client, guac_client_log_level level,
|
|||||||
vguacd_log(level, format, args);
|
vguacd_log(level, format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void guacd_log_guac_error(const char* message) {
|
void guacd_log_guac_error(guac_client_log_level level, const char* message) {
|
||||||
|
|
||||||
if (guac_error != GUAC_STATUS_SUCCESS) {
|
if (guac_error != GUAC_STATUS_SUCCESS) {
|
||||||
|
|
||||||
/* If error message provided, include in log */
|
/* If error message provided, include in log */
|
||||||
if (guac_error_message != NULL)
|
if (guac_error_message != NULL)
|
||||||
guacd_log(GUAC_LOG_ERROR, "%s: %s: %s",
|
guacd_log(level, "%s: %s",
|
||||||
message,
|
message,
|
||||||
guac_status_string(guac_error),
|
|
||||||
guac_error_message);
|
guac_error_message);
|
||||||
|
|
||||||
/* Otherwise just log with standard status string */
|
/* Otherwise just log with standard status string */
|
||||||
else
|
else
|
||||||
guacd_log(GUAC_LOG_ERROR, "%s: %s",
|
guacd_log(level, "%s: %s",
|
||||||
message,
|
message,
|
||||||
guac_status_string(guac_error));
|
guac_status_string(guac_error));
|
||||||
|
|
||||||
@ -124,24 +123,24 @@ void guacd_log_guac_error(const char* message) {
|
|||||||
|
|
||||||
/* Just log message if no status code */
|
/* Just log message if no status code */
|
||||||
else
|
else
|
||||||
guacd_log(GUAC_LOG_ERROR, "%s", message);
|
guacd_log(level, "%s", message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void guacd_client_log_guac_error(guac_client* client, const char* message) {
|
void guacd_client_log_guac_error(guac_client* client,
|
||||||
|
guac_client_log_level level, const char* message) {
|
||||||
|
|
||||||
if (guac_error != GUAC_STATUS_SUCCESS) {
|
if (guac_error != GUAC_STATUS_SUCCESS) {
|
||||||
|
|
||||||
/* If error message provided, include in log */
|
/* If error message provided, include in log */
|
||||||
if (guac_error_message != NULL)
|
if (guac_error_message != NULL)
|
||||||
guac_client_log(client, GUAC_LOG_ERROR, "%s: %s: %s",
|
guac_client_log(client, level, "%s: %s",
|
||||||
message,
|
message,
|
||||||
guac_status_string(guac_error),
|
|
||||||
guac_error_message);
|
guac_error_message);
|
||||||
|
|
||||||
/* Otherwise just log with standard status string */
|
/* Otherwise just log with standard status string */
|
||||||
else
|
else
|
||||||
guac_client_log(client, GUAC_LOG_ERROR, "%s: %s",
|
guac_client_log(client, level, "%s: %s",
|
||||||
message,
|
message,
|
||||||
guac_status_string(guac_error));
|
guac_status_string(guac_error));
|
||||||
|
|
||||||
@ -149,7 +148,7 @@ void guacd_client_log_guac_error(guac_client* client, const char* message) {
|
|||||||
|
|
||||||
/* Just log message if no status code */
|
/* Just log message if no status code */
|
||||||
else
|
else
|
||||||
guac_client_log(client, GUAC_LOG_ERROR, "%s", message);
|
guac_client_log(client, level, "%s", message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,9 +52,8 @@ void vguacd_log(guac_client_log_level level, const char* format, va_list args);
|
|||||||
void guacd_log(guac_client_log_level level, const char* format, ...);
|
void guacd_log(guac_client_log_level level, const char* format, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a message using the logging facilities of the given client,
|
* Writes a message using the logging facilities of the given client. This
|
||||||
* automatically including any information present in guac_error. This function
|
* function accepts parameters identically to printf.
|
||||||
* accepts parameters identically to printf.
|
|
||||||
*/
|
*/
|
||||||
void guacd_client_log(guac_client* client, guac_client_log_level level,
|
void guacd_client_log(guac_client* client, guac_client_log_level level,
|
||||||
const char* format, va_list args);
|
const char* format, va_list args);
|
||||||
@ -64,14 +63,15 @@ void guacd_client_log(guac_client* client, guac_client_log_level level,
|
|||||||
* information present in guac_error. This function accepts parameters
|
* information present in guac_error. This function accepts parameters
|
||||||
* identically to printf.
|
* identically to printf.
|
||||||
*/
|
*/
|
||||||
void guacd_log_guac_error(const char* message);
|
void guacd_log_guac_error(guac_client_log_level level, const char* message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints an error message using the logging facilities of the given client,
|
* Prints an error message using the logging facilities of the given client,
|
||||||
* automatically including any information present in guac_error. This function
|
* automatically including any information present in guac_error. This function
|
||||||
* accepts parameters identically to printf.
|
* accepts parameters identically to printf.
|
||||||
*/
|
*/
|
||||||
void guacd_client_log_guac_error(guac_client* client, const char* message);
|
void guacd_client_log_guac_error(guac_client* client,
|
||||||
|
guac_client_log_level level, const char* message);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user