Skip to content

Instantly share code, notes, and snippets.

@orgads
Created April 24, 2018 14:29
Show Gist options
  • Select an option

  • Save orgads/460270b84d9b0849b26d65ca15bcd302 to your computer and use it in GitHub Desktop.

Select an option

Save orgads/460270b84d9b0849b26d65ca15bcd302 to your computer and use it in GitHub Desktop.
diff --git a/winsup/cygwin/include/cygwin/exit_process.h b/winsup/cygwin/include/cygwin/exit_process.h
index e0981bbe4..a5a3f5d85 100644
--- a/winsup/cygwin/include/cygwin/exit_process.h
+++ b/winsup/cygwin/include/cygwin/exit_process.h
@@ -218,6 +218,7 @@ inject_remote_thread_into_process(HANDLE process, LPTHREAD_START_ROUTINE address
DWORD thread_id;
HANDLE thread = CreateRemoteThread (process, NULL, 1024 * 1024, address,
(PVOID) exit_code, 0, &thread_id);
+ small_printf("injecting: %d. thread_id: %d, thread: %p\n", exit_code, thread_id, thread);
if (thread)
{
/*
@@ -245,11 +246,13 @@ exit_one_process(HANDLE process, int exit_code)
LPTHREAD_START_ROUTINE address = NULL;
int signo = exit_code & 0x7f;
+ small_printf("signo: %d\n", signo);
switch (signo)
{
case SIGINT:
case SIGQUIT:
address = get_ctrl_routine_address_for_process(process);
+ small_printf("address: %p\n", address);
if (address &&
!inject_remote_thread_into_process(process, address,
signo == SIGINT ?
@@ -258,6 +261,7 @@ exit_one_process(HANDLE process, int exit_code)
/* fall-through */
case SIGTERM:
address = get_exit_process_address_for_process(process);
+ small_printf("address on SIGTERM: %p\n", address);
if (address && !inject_remote_thread_into_process(process, address, exit_code))
return 0;
break;
@@ -289,6 +293,7 @@ exit_process_tree(HANDLE main_process, int exit_code)
pids[0] = (DWORD) pid;
len = 1;
+ small_printf("exit_process_tree. pid: %d, signo: %d\n", pid, signo);
/*
* Even if Process32First()/Process32Next() seem to traverse the
* processes in topological order (i.e. parent processes before
@@ -309,6 +314,7 @@ exit_process_tree(HANDLE main_process, int exit_code)
int orig_len = len;
do
{
+ //small_printf("pid: %d, ppid: %d\n",entry.th32ProcessID, entry.th32ParentProcessID);
/**
* Look for the parent process ID in the list of pids to kill, and if
* found, add it to the list.
@@ -316,19 +322,26 @@ exit_process_tree(HANDLE main_process, int exit_code)
for (i = len - 1; i >= 0; i--)
{
if (pids[i] == entry.th32ProcessID)
- break;
+ {
+ small_printf("match pids[%d] == %d\n", i, pids[i]);
+ break;
+ }
if (pids[i] != entry.th32ParentProcessID)
continue;
+ small_printf("match parent pids[%d] == %d\n", i, pids[i]);
/* We found a process to kill; is it an MSYS2 process? */
pid_t cyg_pid = cygwin_winpid_to_pid(entry.th32ProcessID);
+ small_printf("cyg_pid: %d\n",cyg_pid);
if (cyg_pid > -1)
{
+ small_printf("getpgid: %d\n",getpgid(cyg_pid));
if (cyg_pid == getpgid (cyg_pid))
kill(cyg_pid, signo);
break;
}
pids[len++] = entry.th32ProcessID;
+ small_printf("Added pids[%d] = %d\n",len-1, entry.th32ProcessID);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment