Skip to content

Commit

Permalink
GUACAMOLE-1841: Log Windows PIDs instead of Cygwin PIDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuehlner committed Oct 11, 2023
1 parent 2a0fe85 commit afb1b36
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
24 changes: 22 additions & 2 deletions src/guacd/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#include <sys/wait.h>
#include <unistd.h>

#ifdef CYGWIN_BUILD
#include <sys/cygwin.h>
#endif

#define GUACD_DEV_NULL "/dev/null"
#define GUACD_ROOT "/"

Expand Down Expand Up @@ -106,9 +110,20 @@ static int daemonize() {
return 1;
}

#ifdef CYGWIN_BUILD
/* Convert to a windows PID for logging */
pid_t windows_pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, pid);
#endif

/* Exit if we are the parent */
if (pid > 0) {
guacd_log(GUAC_LOG_DEBUG, "Exiting and passing control to PID %i", pid);

guacd_log(GUAC_LOG_DEBUG, "Exiting and passing control to PID %i",
#ifdef CYGWIN_BUILD
windows_pid);
#else
pid);
#endif
_exit(0);
}

Expand All @@ -124,7 +139,12 @@ static int daemonize() {

/* Exit if we are the parent */
if (pid > 0) {
guacd_log(GUAC_LOG_DEBUG, "Exiting and passing control to PID %i", pid);
guacd_log(GUAC_LOG_DEBUG, "Exiting and passing control to PID %i",
#ifdef CYGWIN_BUILD
windows_pid);
#else
pid);
#endif
_exit(0);
}

Expand Down
13 changes: 12 additions & 1 deletion src/guacd/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <syslog.h>
#include <unistd.h>

#ifdef CYGWIN_BUILD
#include <sys/cygwin.h>
#endif

int guacd_log_level = GUAC_LOG_INFO;

void vguacd_log(guac_client_log_level level, const char* format,
Expand Down Expand Up @@ -90,8 +94,15 @@ void vguacd_log(guac_client_log_level level, const char* format,
syslog(priority, "%s", message);

/* Log to STDERR */
pid_t pid = getpid();

#ifdef CYGWIN_BUILD
/* Convert to a windows PID for logging */
pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, pid);
#endif

fprintf(stderr, GUACD_LOG_NAME "[%i]: %s:\t%s\n",
getpid(), priority_name, message);
pid, priority_name, message);

}

Expand Down
27 changes: 25 additions & 2 deletions src/guacd/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "guacamole/socket-handle.h"
#include <io.h>
#include <handleapi.h>
#include <sys/cygwin.h>
#endif

/**
Expand Down Expand Up @@ -465,8 +466,19 @@ 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) {

#ifdef CYGWIN_BUILD
/* Convert to a windows PID for logging */
pid_t windows_pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, child_pid);
#endif

guacd_log(GUAC_LOG_DEBUG, "Automatically reaped unreaped "
"(zombie) child process with PID %i.", child_pid);
"(zombie) child process with PID %i.",
#ifdef CYGWIN_BUILD
windows_pid);
#else
child_pid);
#endif
}

/* If running children remain, warn and forcibly kill */
Expand Down Expand Up @@ -575,8 +587,19 @@ 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) {

#ifdef CYGWIN_BUILD
/* Convert to a windows PID for logging */
pid_t windows_pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, child_pid);
#endif

guacd_log(GUAC_LOG_DEBUG, "Child process %i of connection \"%s\" has terminated",
child_pid, proc->client->connection_id);
#ifdef CYGWIN_BUILD
windows_pid,
#else
child_pid,
#endif
proc->client->connection_id);
}

guacd_log(GUAC_LOG_DEBUG, "All child processes for connection \"%s\" have been terminated.",
Expand Down
16 changes: 15 additions & 1 deletion src/protocols/rdp/print-job.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
#include <string.h>
#include <unistd.h>

#ifdef CYGWIN_BUILD
#include <sys/cygwin.h>
#endif

/**
* The command to run when filtering postscript to produce PDF. This must be
* a NULL-terminated array of arguments, where the first argument is the name
Expand Down Expand Up @@ -365,8 +369,18 @@ static pid_t guac_rdp_create_filter_process(guac_client* client,
}

/* Log fork success */

#ifdef CYGWIN_BUILD
/* Convert to a windows PID for logging */
pid_t windows_pid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, child_pid);
#endif
guac_client_log(client, GUAC_LOG_INFO, "Created PDF filter process "
"PID=%i", child_pid);
"PID=%i",
#ifdef CYGWIN_BUILD
windows_pid);
#else
child_pid);
#endif
/* Close unneeded ends of pipe */
close(stdin_pipe[0]);
Expand Down

0 comments on commit afb1b36

Please sign in to comment.