Skip to content

Commit 178d5e2

Browse files
committed
GUACAMOLE-1841: Ensure that children get killed even under windows.
1 parent b845e18 commit 178d5e2

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

src/guacd/proc.c

+48-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
#include <sys/socket.h>
4444
#include <sys/wait.h>
4545

46+
// Don't do it
47+
#include <stdio.h>
48+
4649
#ifdef CYGWIN_BUILD
4750
#include "move-pipe.h"
4851
#include "guacamole/socket-handle.h"
@@ -275,16 +278,33 @@ static void* guacd_client_free_thread(void* data) {
275278

276279
guacd_client_free* free_operation = (guacd_client_free*) data;
277280

281+
FILE* the_file = fopen("./guacd_client_free_thread.txt","a+");
282+
fprintf(the_file, "In guacd_client_free_thread\n");
283+
fclose(the_file);
284+
278285
/* Attempt to free client (this may never return if the client is
279286
* malfunctioning) */
280287
guac_client_free(free_operation->client);
281288

289+
the_file = fopen("./guacd_client_free_thread.txt","a+");
290+
fprintf(the_file, "In guacd_client_free_thread, did guac_client_free()\n");
291+
fclose(the_file);
292+
282293
/* Signal that the client was successfully freed */
283294
pthread_mutex_lock(&free_operation->completed_mutex);
284295
free_operation->completed = 1;
296+
297+
the_file = fopen("./guacd_client_free_thread.txt","a+");
298+
fprintf(the_file, "In guacd_client_free_thread, set completed=1\n");
299+
fclose(the_file);
300+
285301
pthread_cond_broadcast(&free_operation->completed_cond);
286302
pthread_mutex_unlock(&free_operation->completed_mutex);
287303

304+
the_file = fopen("./guacd_client_free_thread.txt","a+");
305+
fprintf(the_file, "Done with guacd_client_free_thread\n");
306+
fclose(the_file);
307+
288308
return NULL;
289309

290310
}
@@ -317,11 +337,15 @@ static int guacd_timed_client_free(guac_client* client, int timeout) {
317337
.completed = 0
318338
};
319339

340+
fprintf(stderr, "In client_free_thread, waiting %i seconds\n", timeout);
341+
320342
/* Get current time */
321343
struct timeval current_time;
322344
if (gettimeofday(&current_time, NULL))
323345
return 1;
324346

347+
fprintf(stderr, "In client_free_thread, got time of day\n");
348+
325349
/* Calculate exact time that the free operation MUST complete by */
326350
struct timespec deadline = {
327351
.tv_sec = current_time.tv_sec + timeout,
@@ -333,9 +357,16 @@ static int guacd_timed_client_free(guac_client* client, int timeout) {
333357
if (pthread_mutex_lock(&free_operation.completed_mutex))
334358
return 1;
335359

360+
fprintf(stderr, "In client_free_thread, got completed_mutex\n");
361+
336362
/* Free the client in a separate thread, so we can time the free operation */
337-
if (!pthread_create(&client_free_thread, NULL,
338-
guacd_client_free_thread, &free_operation)) {
363+
int the_return = pthread_create(&client_free_thread, NULL,
364+
guacd_client_free_thread, &free_operation);
365+
fprintf(stderr, "pthread_create(): %i, errno: %i\n", the_return, errno);
366+
367+
if (!the_return) {
368+
369+
fprintf(stderr, "In client_free_thread, started guacd_client_free_thread...\n");
339370

340371
/* Wait a finite amount of time for the free operation to finish */
341372
(void) pthread_cond_timedwait(&free_operation.completed_cond,
@@ -363,6 +394,13 @@ guacd_proc* guacd_proc_self = NULL;
363394
*/
364395
static void signal_stop_handler(int signal) {
365396

397+
#ifdef CYGWIN_BUILD
398+
/* Convert to a windows PID for logging */
399+
pid_t windows_pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, guacd_proc_self->pid);
400+
fprintf(stderr, "I caught signal %i and am accordingly killing self with cyg %i, win %i\n",
401+
signal, guacd_proc_self->pid, windows_pid);
402+
#endif
403+
366404
/* Stop the current guacd proc */
367405
guacd_proc_stop(guacd_proc_self);
368406

@@ -579,6 +617,14 @@ guacd_proc* guacd_create_proc(const char* protocol) {
579617
*/
580618
static void guacd_proc_kill(guacd_proc* proc) {
581619

620+
621+
#ifdef CYGWIN_BUILD
622+
pid_t windows_pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, proc->pid);
623+
624+
guacd_log(GUAC_LOG_DEBUG, "Trying to kill child - cyg: %i, win: %i", proc->pid, windows_pid);
625+
#endif
626+
627+
582628
/* Request orderly termination of process */
583629
if (kill(proc->pid, SIGTERM))
584630
guacd_log(GUAC_LOG_DEBUG, "Unable to request termination of "

0 commit comments

Comments
 (0)