Skip to content

Commit

Permalink
WIP: Debugging cruft cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuehlner committed Jan 26, 2024
1 parent 5d09398 commit a84907f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
39 changes: 8 additions & 31 deletions src/guacd/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;

}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 */
Expand All @@ -465,7 +447,7 @@ static void guacd_exec_proc(guacd_proc* proc, const char* protocol) {
owner = 0;

}

cleanup_client:

/* Request client to stop/disconnect */
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/protocols/rdp/channels/rdpdr/rdpdr-messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {

/* Support XPS mode only on Windows*/
#ifdef WINDOWS_BUILD

guac_client_log(svc->client, GUAC_LOG_WARNING, "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

}
4 changes: 3 additions & 1 deletion src/protocols/rdp/rdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a84907f

Please sign in to comment.