From 42299001165a1e04d67db14da714cd0d55e65903 Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Fri, 26 Jan 2024 22:13:49 +0000 Subject: [PATCH] WIP: Debugging cruft cleanup. --- src/guacd/proc.c | 39 ++++--------------- .../rdp/channels/rdpdr/rdpdr-messages.c | 13 ++++++- src/protocols/rdp/rdp.h | 4 +- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/guacd/proc.c b/src/guacd/proc.c index d9e92cacf7..3da138d328 100644 --- a/src/guacd/proc.c +++ b/src/guacd/proc.c @@ -151,7 +151,7 @@ static void* guacd_user_thread(void* data) { * * @param proc * The process that the user is being added to. - + * @param handle * The handle associated with the user's connection to guacd. * @@ -279,33 +279,16 @@ static void* guacd_client_free_thread(void* data) { guacd_client_free* free_operation = (guacd_client_free*) data; - FILE* the_file = fopen("./guacd_client_free_thread.txt","a+"); - fprintf(the_file, "In guacd_client_free_thread\n"); - fclose(the_file); - /* Attempt to free client (this may never return if the client is * malfunctioning) */ guac_client_free(free_operation->client); - the_file = fopen("./guacd_client_free_thread.txt","a+"); - fprintf(the_file, "In guacd_client_free_thread, did guac_client_free()\n"); - fclose(the_file); - /* Signal that the client was successfully freed */ pthread_mutex_lock(&free_operation->completed_mutex); free_operation->completed = 1; - - the_file = fopen("./guacd_client_free_thread.txt","a+"); - fprintf(the_file, "In guacd_client_free_thread, set completed=1\n"); - fclose(the_file); - pthread_cond_broadcast(&free_operation->completed_cond); pthread_mutex_unlock(&free_operation->completed_mutex); - the_file = fopen("./guacd_client_free_thread.txt","a+"); - fprintf(the_file, "Done with guacd_client_free_thread\n"); - fclose(the_file); - return NULL; } @@ -355,14 +338,13 @@ static int guacd_timed_client_free(guac_client* client, int timeout) { return 1; /* Free the client in a separate thread, so we can time the free operation */ - int the_return = pthread_create(&client_free_thread, NULL, - guacd_client_free_thread, &free_operation); - - if (!the_return) + if (!pthread_create(&client_free_thread, NULL, + guacd_client_free_thread, &free_operation)) { /* Wait a finite amount of time for the free operation to finish */ (void) pthread_cond_timedwait(&free_operation.completed_cond, &free_operation.completed_mutex, &deadline); + } (void) pthread_mutex_unlock(&free_operation.completed_mutex); @@ -442,7 +424,7 @@ static void guacd_exec_proc(guacd_proc* proc, const char* protocol) { struct sigaction signal_stop_action = { .sa_handler = signal_stop_handler }; sigaction(SIGINT, &signal_stop_action, NULL); sigaction(SIGTERM, &signal_stop_action, NULL); - + #ifdef WINDOWS_BUILD /* Add each received file handle as a new user */ @@ -465,7 +447,7 @@ static void guacd_exec_proc(guacd_proc* proc, const char* protocol) { owner = 0; } - + cleanup_client: /* Request client to stop/disconnect */ @@ -488,11 +470,8 @@ static void guacd_exec_proc(guacd_proc* proc, const char* protocol) { /* Verify whether children were all properly reaped */ pid_t child_pid; while ((child_pid = waitpid(0, NULL, WNOHANG)) > 0) { - guacd_log(GUAC_LOG_DEBUG, "Automatically reaped unreaped " - "(zombie) child process with PID %i.", - child_pid); - + "(zombie) child process with PID %i.", child_pid); } /* If running children remain, warn and forcibly kill */ @@ -601,8 +580,6 @@ static void guacd_proc_kill(guacd_proc* proc) { /* Wait for all processes within process group to terminate */ pid_t child_pid; while ((child_pid = waitpid(-proc->pid, NULL, 0)) > 0 || errno == EINTR) { - - guacd_log(GUAC_LOG_DEBUG, "Child process %i of connection \"%s\" has terminated", child_pid, proc->client->connection_id); } @@ -629,7 +606,7 @@ void guacd_proc_stop(guacd_proc* proc) { if (shutdown(proc->fd_socket, SHUT_RDWR) == -1) guacd_log(GUAC_LOG_ERROR, "Unable to shutdown internal socket for " "connection %s. Corresponding process may remain running but " - "inactive. errno: %i", proc->client->connection_id, errno); + "inactive.", proc->client->connection_id); /* Clean up our end of the socket */ close(proc->fd_socket); diff --git a/src/protocols/rdp/channels/rdpdr/rdpdr-messages.c b/src/protocols/rdp/channels/rdpdr/rdpdr-messages.c index 34e898bc63..829a797232 100644 --- a/src/protocols/rdp/channels/rdpdr/rdpdr-messages.c +++ b/src/protocols/rdp/channels/rdpdr/rdpdr-messages.c @@ -17,6 +17,8 @@ * under the License. */ +#include "config.h" + #include "channels/rdpdr/rdpdr-messages.h" #include "channels/rdpdr/rdpdr-printer.h" #include "channels/rdpdr/rdpdr.h" @@ -397,10 +399,19 @@ void guac_rdpdr_process_prn_cache_data(guac_rdp_common_svc* svc, void guac_rdpdr_process_prn_using_xps(guac_rdp_common_svc* svc, wStream* input_stream) { - guac_client_log(svc->client, GUAC_LOG_WARNING, "Printer switched to XPS mode"); +/* Support XPS mode only on Windows*/ +#ifdef WINDOWS_BUILD + + guac_client_log(svc->client, GUAC_LOG_INFO, "Printer switched to XPS mode"); /* Mark the client as XPS mode being enabled for the printer */ guac_rdp_client* client = (guac_rdp_client*) svc->client->data; client->xps_printer_mode_enabled = 1; +#else + + guac_client_log(svc->client, GUAC_LOG_WARNING, "Printer unexpectedly switched to XPS mode"); + +#endif + } diff --git a/src/protocols/rdp/rdp.h b/src/protocols/rdp/rdp.h index cc89e7a32e..d233cea03e 100644 --- a/src/protocols/rdp/rdp.h +++ b/src/protocols/rdp/rdp.h @@ -197,7 +197,9 @@ typedef struct guac_rdp_client { pthread_mutex_t message_lock; /** - * Non-zero if XPS mode is enabled, or zero otherwise. See + * Non-zero if XPS mode is enabled, or zero otherwise. + * NOTE: XPS mode is currently only supported on Windows. Attempts to set + * XPS mode on linux will be ignored. For more, see: * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpepc/f97d26e7-d862-4cca-8ec9-98d3c69e2717 */ int xps_printer_mode_enabled;