Skip to content

Commit d14a895

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

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎src/guacd/proc.c‎

Lines changed: 33 additions & 0 deletions
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,25 @@ static void* guacd_client_free_thread(void* data) {
275278

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

281+
fprintf(stderr, "In guacd_client_free_thread\n");
282+
278283
/* Attempt to free client (this may never return if the client is
279284
* malfunctioning) */
280285
guac_client_free(free_operation->client);
281286

287+
fprintf(stderr, "In guacd_client_free_thread, did guac_client_free()\n");
288+
282289
/* Signal that the client was successfully freed */
283290
pthread_mutex_lock(&free_operation->completed_mutex);
284291
free_operation->completed = 1;
292+
293+
fprintf(stderr, "In guacd_client_free_thread, set completed=1\n");
294+
285295
pthread_cond_broadcast(&free_operation->completed_cond);
286296
pthread_mutex_unlock(&free_operation->completed_mutex);
287297

298+
fprintf(stderr, "Done with guacd_client_free_thread\n");
299+
288300
return NULL;
289301

290302
}
@@ -317,11 +329,15 @@ static int guacd_timed_client_free(guac_client* client, int timeout) {
317329
.completed = 0
318330
};
319331

332+
fprintf(stderr, "In client_free_thread, waiting %i seconds\n", timeout);
333+
320334
/* Get current time */
321335
struct timeval current_time;
322336
if (gettimeofday(&current_time, NULL))
323337
return 1;
324338

339+
fprintf(stderr, "In client_free_thread, got time of day\n");
340+
325341
/* Calculate exact time that the free operation MUST complete by */
326342
struct timespec deadline = {
327343
.tv_sec = current_time.tv_sec + timeout,
@@ -333,6 +349,8 @@ static int guacd_timed_client_free(guac_client* client, int timeout) {
333349
if (pthread_mutex_lock(&free_operation.completed_mutex))
334350
return 1;
335351

352+
fprintf(stderr, "In client_free_thread, got completed_mutex\n");
353+
336354
/* Free the client in a separate thread, so we can time the free operation */
337355
if (!pthread_create(&client_free_thread, NULL,
338356
guacd_client_free_thread, &free_operation)) {
@@ -363,6 +381,13 @@ guacd_proc* guacd_proc_self = NULL;
363381
*/
364382
static void signal_stop_handler(int signal) {
365383

384+
#ifdef CYGWIN_BUILD
385+
/* Convert to a windows PID for logging */
386+
pid_t windows_pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, guacd_proc_self->pid);
387+
fprintf(stderr, "I caught signal %i and am accordingly killing self with cyg %i, win %i\n",
388+
signal, guacd_proc_self->pid, windows_pid);
389+
#endif
390+
366391
/* Stop the current guacd proc */
367392
guacd_proc_stop(guacd_proc_self);
368393

@@ -579,6 +604,14 @@ guacd_proc* guacd_create_proc(const char* protocol) {
579604
*/
580605
static void guacd_proc_kill(guacd_proc* proc) {
581606

607+
608+
#ifdef CYGWIN_BUILD
609+
pid_t windows_pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, proc->pid);
610+
611+
guacd_log(GUAC_LOG_DEBUG, "Trying to kill child - cyg: %i, win: %i", proc->pid, windows_pid);
612+
#endif
613+
614+
582615
/* Request orderly termination of process */
583616
if (kill(proc->pid, SIGTERM))
584617
guacd_log(GUAC_LOG_DEBUG, "Unable to request termination of "

0 commit comments

Comments
 (0)