Skip to content

Commit

Permalink
GUACAMOLE-1846: Ensure successful builds on older GCC.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuehlner committed Aug 29, 2023
1 parent 5e0fb22 commit eb281c1
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 68 deletions.
3 changes: 1 addition & 2 deletions src/guacd/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,7 @@ int main(int argc, char* argv[]) {
}

/* Clean up and exit if SIGINT or SIGTERM signals are caught */
struct sigaction signal_stop_action = { 0 };
signal_stop_action.sa_handler = signal_stop_handler;
struct sigaction signal_stop_action = { .sa_handler = signal_stop_handler };
sigaction(SIGINT, &signal_stop_action, NULL);
sigaction(SIGTERM, &signal_stop_action, NULL);

Expand Down
3 changes: 1 addition & 2 deletions src/guacd/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ static void guacd_exec_proc(guacd_proc* proc, const char* protocol) {
guacd_proc_self = proc;

/* Clean up and exit if SIGINT or SIGTERM signals are caught */
struct sigaction signal_stop_action = { 0 };
signal_stop_action.sa_handler = signal_stop_handler;
struct sigaction signal_stop_action = { .sa_handler = signal_stop_handler };
sigaction(SIGINT, &signal_stop_action, NULL);
sigaction(SIGTERM, &signal_stop_action, NULL);

Expand Down
4 changes: 2 additions & 2 deletions src/libguac/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ libguacinc_HEADERS = \
guacamole/protocol-constants.h \
guacamole/protocol-types.h \
guacamole/recording.h \
guacamole/rwlock.h \
guacamole/socket-constants.h \
guacamole/socket.h \
guacamole/socket-fntypes.h \
Expand All @@ -82,7 +83,6 @@ noinst_HEADERS = \
id.h \
encode-jpeg.h \
encode-png.h \
reentrant-rwlock.h \
palette.h \
user-handlers.h \
raw_encoder.h \
Expand All @@ -98,7 +98,7 @@ libguac_la_SOURCES = \
fips.c \
hash.c \
id.c \
reentrant-rwlock.c \
rwlock.c \
palette.c \
parser.c \
pool.c \
Expand Down
68 changes: 34 additions & 34 deletions src/libguac/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
#include "guacamole/plugin.h"
#include "guacamole/pool.h"
#include "guacamole/protocol.h"
#include "guacamole/rwlock.h"
#include "guacamole/socket.h"
#include "guacamole/stream.h"
#include "guacamole/string.h"
#include "guacamole/timestamp.h"
#include "guacamole/user.h"
#include "id.h"
#include "reentrant-rwlock.h"

#include <dlfcn.h>
#include <errno.h>
Expand Down Expand Up @@ -183,15 +183,15 @@ static void guac_client_promote_pending_users(union sigval data) {
return;

/* Acquire the lock for reading and modifying the list of pending users */
guac_acquire_write_lock(&(client->__pending_users_lock));
guac_rwlock_acquire_write_lock(&(client->__pending_users_lock));

/* Run the pending join handler, if one is defined */
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));
guac_rwlock_release_lock(&(client->__pending_users_lock));

/* Mark the handler as not running */
pthread_mutex_lock(&(client->__pending_users_timer_mutex));
Expand Down Expand Up @@ -223,7 +223,7 @@ static void guac_client_promote_pending_users(union sigval data) {
client->__pending_users = NULL;

/* Acquire the lock for reading and modifying the list of full users. */
guac_acquire_write_lock(&(client->__users_lock));
guac_rwlock_acquire_write_lock(&(client->__users_lock));

/* If any users were removed from the pending list, promote them now */
if (last_user != NULL) {
Expand All @@ -237,11 +237,11 @@ static void guac_client_promote_pending_users(union sigval data) {

}

guac_release_lock(&(client->__users_lock));
guac_rwlock_release_lock(&(client->__users_lock));

/* Release the lock (this is done AFTER updating the connected user list
* to ensure that all users are always on exactly one of these lists) */
guac_release_lock(&(client->__pending_users_lock));
guac_rwlock_release_lock(&(client->__pending_users_lock));

/* Mark the handler as complete so the next instance can run */
pthread_mutex_lock(&(client->__pending_users_timer_mutex));
Expand Down Expand Up @@ -291,8 +291,8 @@ guac_client* guac_client_alloc() {
}

/* Init locks */
guac_init_reentrant_rwlock(&(client->__users_lock));
guac_init_reentrant_rwlock(&(client->__pending_users_lock));
guac_init_rwlock(&(client->__users_lock));
guac_init_rwlock(&(client->__pending_users_lock));

/* Initialize the write lock flags to 0, as threads won't have yet */
pthread_key_create(&(client->__users_lock.key), (void *) 0);
Expand All @@ -315,8 +315,8 @@ guac_client* guac_client_alloc() {
void guac_client_free(guac_client* client) {

/* Acquire write locks before referencing user pointers */
guac_acquire_write_lock(&(client->__pending_users_lock));
guac_acquire_write_lock(&(client->__users_lock));
guac_rwlock_acquire_write_lock(&(client->__pending_users_lock));
guac_rwlock_acquire_write_lock(&(client->__users_lock));

/* Remove all pending users */
while (client->__pending_users != NULL)
Expand All @@ -327,8 +327,8 @@ void guac_client_free(guac_client* client) {
guac_client_remove_user(client, client->__users);

/* Release the locks */
guac_release_lock(&(client->__users_lock));
guac_release_lock(&(client->__pending_users_lock));
guac_rwlock_release_lock(&(client->__users_lock));
guac_rwlock_release_lock(&(client->__pending_users_lock));

if (client->free_handler) {

Expand Down Expand Up @@ -371,8 +371,8 @@ void guac_client_free(guac_client* client) {
pthread_mutex_destroy(&(client->__pending_users_timer_mutex));

/* Destroy the reentrant read-write locks */
guac_destroy_reentrant_rwlock(&(client->__users_lock));
guac_destroy_reentrant_rwlock(&(client->__pending_users_lock));
guac_destroy_rwlock(&(client->__users_lock));
guac_destroy_rwlock(&(client->__pending_users_lock));

free(client->connection_id);
free(client);
Expand Down Expand Up @@ -451,7 +451,7 @@ static void guac_client_add_pending_user(
guac_client* client, guac_user* user) {

/* Acquire the lock for modifying the list of pending users */
guac_acquire_write_lock(&(client->__pending_users_lock));
guac_rwlock_acquire_write_lock(&(client->__pending_users_lock));

user->__prev = NULL;
user->__next = client->__pending_users;
Expand All @@ -465,7 +465,7 @@ static void guac_client_add_pending_user(
client->connected_users++;

/* Release the lock */
guac_release_lock(&(client->__pending_users_lock));
guac_rwlock_release_lock(&(client->__pending_users_lock));

}

Expand Down Expand Up @@ -494,9 +494,8 @@ static int guac_client_start_pending_users_timer(guac_client* client) {
}

/* Configure the timer to synchronize and clear the pending users */
struct sigevent signal_config = { 0 };
signal_config.sigev_notify = SIGEV_THREAD;
signal_config.sigev_notify_function = guac_client_promote_pending_users;
struct sigevent signal_config = {
.sigev_notify_function = guac_client_promote_pending_users };
signal_config.sigev_value.sival_ptr = client;

/* Create a timer to synchronize any pending users periodically */
Expand All @@ -509,9 +508,10 @@ static int guac_client_start_pending_users_timer(guac_client* client) {
}

/* Configure the pending users timer to run on the defined interval */
struct itimerspec time_config = { 0 };
time_config.it_interval.tv_nsec = GUAC_CLIENT_PENDING_USERS_REFRESH_INTERVAL;
time_config.it_value.tv_nsec = GUAC_CLIENT_PENDING_USERS_REFRESH_INTERVAL;
struct itimerspec time_config = {
.it_interval = { .tv_nsec = GUAC_CLIENT_PENDING_USERS_REFRESH_INTERVAL },
.it_value = { .tv_nsec = GUAC_CLIENT_PENDING_USERS_REFRESH_INTERVAL }
};

/* Start the timer */
if (timer_settime(
Expand Down Expand Up @@ -574,8 +574,8 @@ int guac_client_add_user(guac_client* client, guac_user* user, int argc, char**

void guac_client_remove_user(guac_client* client, guac_user* user) {

guac_acquire_write_lock(&(client->__pending_users_lock));
guac_acquire_write_lock(&(client->__users_lock));
guac_rwlock_acquire_write_lock(&(client->__pending_users_lock));
guac_rwlock_acquire_write_lock(&(client->__users_lock));

/* Update prev / head */
if (user->__prev != NULL)
Expand All @@ -595,8 +595,8 @@ void guac_client_remove_user(guac_client* client, guac_user* user) {
if (user->owner)
client->__owner = NULL;

guac_release_lock(&(client->__users_lock));
guac_release_lock(&(client->__pending_users_lock));
guac_rwlock_release_lock(&(client->__users_lock));
guac_rwlock_release_lock(&(client->__pending_users_lock));

/* Update owner of user having left the connection. */
if (!user->owner)
Expand All @@ -614,7 +614,7 @@ void guac_client_foreach_user(guac_client* client, guac_user_callback* callback,

guac_user* current;

guac_acquire_read_lock(&(client->__users_lock));
guac_rwlock_acquire_read_lock(&(client->__users_lock));

/* Call function on each user */
current = client->__users;
Expand All @@ -623,7 +623,7 @@ void guac_client_foreach_user(guac_client* client, guac_user_callback* callback,
current = current->__next;
}

guac_release_lock(&(client->__users_lock));
guac_rwlock_release_lock(&(client->__users_lock));

}

Expand All @@ -632,7 +632,7 @@ void guac_client_foreach_pending_user(

guac_user* current;

guac_acquire_read_lock(&(client->__pending_users_lock));
guac_rwlock_acquire_read_lock(&(client->__pending_users_lock));

/* Call function on each pending user */
current = client->__pending_users;
Expand All @@ -641,7 +641,7 @@ void guac_client_foreach_pending_user(
current = current->__next;
}

guac_release_lock(&(client->__pending_users_lock));
guac_rwlock_release_lock(&(client->__pending_users_lock));

}

Expand All @@ -650,12 +650,12 @@ void* guac_client_for_owner(guac_client* client, guac_user_callback* callback,

void* retval;

guac_acquire_read_lock(&(client->__users_lock));
guac_rwlock_acquire_read_lock(&(client->__users_lock));

/* Invoke callback with current owner */
retval = callback(client->__owner, data);

guac_release_lock(&(client->__users_lock));
guac_rwlock_release_lock(&(client->__users_lock));

/* Return value from callback */
return retval;
Expand All @@ -670,7 +670,7 @@ void* guac_client_for_user(guac_client* client, guac_user* user,
int user_valid = 0;
void* retval;

guac_acquire_read_lock(&(client->__users_lock));
guac_rwlock_acquire_read_lock(&(client->__users_lock));

/* Loop through all users, searching for a pointer to the given user */
current = client->__users;
Expand All @@ -692,7 +692,7 @@ void* guac_client_for_user(guac_client* client, guac_user* user,
/* Invoke callback with requested user (if they exist) */
retval = callback(user, data);

guac_release_lock(&(client->__users_lock));
guac_rwlock_release_lock(&(client->__users_lock));

/* Return value from callback */
return retval;
Expand Down
6 changes: 3 additions & 3 deletions src/libguac/guacamole/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "client-types.h"
#include "client-constants.h"
#include "layer-types.h"
#include "reentrant-rwlock.h"
#include "guacamole/rwlock.h"
#include "object-types.h"
#include "pool-types.h"
#include "socket-types.h"
Expand Down Expand Up @@ -172,7 +172,7 @@ struct guac_client {
* Lock which is acquired when the users list is being manipulated, or when
* the users list is being iterated.
*/
guac_reentrant_rwlock __users_lock;
guac_rwlock __users_lock;

/**
* The first user within the list of all connected users, or NULL if no
Expand All @@ -184,7 +184,7 @@ struct guac_client {
* Lock which is acquired when the pending users list is being manipulated,
* or when the pending users list is being iterated.
*/
guac_reentrant_rwlock __pending_users_lock;
guac_rwlock __pending_users_lock;

/**
* A timer that will periodically synchronize the list of pending users,
Expand Down
Loading

0 comments on commit eb281c1

Please sign in to comment.