Skip to content

Commit

Permalink
GUACAMOLE-1846: Add error handling support to join pending handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuehlner committed Aug 24, 2023
1 parent b9d46fb commit 30a9a89
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9 deletions.
21 changes: 19 additions & 2 deletions src/libguac/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,25 @@ static void guac_client_promote_pending_users(union sigval data) {
guac_acquire_write_lock(&(client->__pending_users_lock));

/* Run the pending join handler, if one is defined */
if (client->join_pending_handler)
client->join_pending_handler(client);
if (client->join_pending_handler) {

/* If an error occurs in the pending handler */
if(client->join_pending_handler(client)) {

guac_release_lock(&(client->__pending_users_lock));

/* Mark the handler as not running */
pthread_mutex_lock(&(client->__pending_users_timer_mutex));
client->__pending_users_timer_state = GUAC_CLIENT_PENDING_TIMER_REGISTERED;
pthread_mutex_unlock(&(client->__pending_users_timer_mutex));

/* Log a warning and abort the promotion of the pending users */
guac_client_log(client, GUAC_LOG_WARNING,
"join_pending_handler did not successfully complete;"
" any pending users have not been promoted.\n");
return;
}
}

/* The first pending user in the list, if any */
guac_user* first_user = client->__pending_users;
Expand Down
6 changes: 5 additions & 1 deletion src/libguac/guacamole/client-fntypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ typedef int guac_client_free_handler(guac_client* client);
*
* @param client
* The client whose handler was invoked.
*
* @return
* Zero if the pending handler ran successfuly, or a non-zero value if an
* error occured.
*/
typedef void guac_client_join_pending_handler(guac_client* client);
typedef int guac_client_join_pending_handler(guac_client* client);

/**
* Handler for logging messages related to a given guac_client instance.
Expand Down
2 changes: 1 addition & 1 deletion src/libguac/guacamole/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ struct guac_client {
*
* Example:
* @code
* void join_pending_handler(guac_client* client);
* int join_pending_handler(guac_client* client);
*
* int guac_client_init(guac_client* client) {
* client->join_pending_handler = join_pending_handler;
Expand Down
7 changes: 6 additions & 1 deletion src/protocols/kubernetes/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ static void guac_kubernetes_log(int level, const char* line) {
* @param client
* The client whose pending users are about to be promoted to full users,
* and therefore need their connection state synchronized.
*
* @return
* Always zero.
*/
static void guac_kubernetes_join_pending_handler(guac_client* client) {
static int guac_kubernetes_join_pending_handler(guac_client* client) {

guac_kubernetes_client* kubernetes_client =
(guac_kubernetes_client*) client->data;
Expand All @@ -97,6 +100,8 @@ static void guac_kubernetes_join_pending_handler(guac_client* client) {
guac_kubernetes_send_current_argv_batch(client, broadcast_socket);
guac_socket_flush(broadcast_socket);

return 0;

}

int guac_client_init(guac_client* client) {
Expand Down
7 changes: 6 additions & 1 deletion src/protocols/rdp/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ static void* guac_rdp_sync_pending_user_audio(guac_user* user, void* data) {
*
* @param client
* The client whose pending users are about to be promoted.
*
* @return
* Always zero.
*/
static void guac_rdp_join_pending_handler(guac_client* client) {
static int guac_rdp_join_pending_handler(guac_client* client) {

guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
guac_socket* broadcast_socket = client->pending_socket;
Expand All @@ -126,6 +129,8 @@ static void guac_rdp_join_pending_handler(guac_client* client) {

guac_socket_flush(broadcast_socket);

return 0;

}

int guac_client_init(guac_client* client, int argc, char** argv) {
Expand Down
7 changes: 6 additions & 1 deletion src/protocols/ssh/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@
*
* @param client
* The client whose pending users are about to be promoted.
*
* @return
* Always zero.
*/
static void guac_ssh_join_pending_handler(guac_client* client) {
static int guac_ssh_join_pending_handler(guac_client* client) {

guac_ssh_client* ssh_client = (guac_ssh_client*) client->data;

Expand All @@ -54,6 +57,8 @@ static void guac_ssh_join_pending_handler(guac_client* client) {
guac_ssh_send_current_argv_batch(client, broadcast_socket);
guac_socket_flush(broadcast_socket);

return 0;

}

int guac_client_init(guac_client* client) {
Expand Down
7 changes: 6 additions & 1 deletion src/protocols/telnet/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@
*
* @param client
* The client whose pending users are about to be promoted.
*
* @return
* Always zero.
*/
static void guac_telnet_join_pending_handler(guac_client* client) {
static int guac_telnet_join_pending_handler(guac_client* client) {

guac_telnet_client* telnet_client = (guac_telnet_client*) client->data;

Expand All @@ -53,6 +56,8 @@ static void guac_telnet_join_pending_handler(guac_client* client) {
guac_telnet_send_current_argv_batch(client, broadcast_socket);
guac_socket_flush(broadcast_socket);

return 0;

}

int guac_client_init(guac_client* client) {
Expand Down
7 changes: 6 additions & 1 deletion src/protocols/vnc/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ static void* guac_vnc_sync_pending_user_audio(guac_user* user, void* data) {
*
* @param client
* The client whose pending users are about to be promoted.
*
* @return
* Always zero.
*/
static void guac_vnc_join_pending_handler(guac_client* client) {
static int guac_vnc_join_pending_handler(guac_client* client) {

guac_vnc_client* vnc_client = (guac_vnc_client*) client->data;
guac_socket* broadcast_socket = client->pending_socket;
Expand All @@ -87,6 +90,8 @@ static void guac_vnc_join_pending_handler(guac_client* client) {
guac_common_display_dup(vnc_client->display, client, broadcast_socket);
guac_socket_flush(broadcast_socket);

return 0;

}

int guac_client_init(guac_client* client) {
Expand Down

0 comments on commit 30a9a89

Please sign in to comment.