From: corinna Date: Sat, 13 Mar 2004 18:11:13 +0000 (+0000) Subject: * kill.cc (get_debug_priv): New function. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=c83e4865772fa7e5f9f93911812d2841ceeaac29;p=pf3gnuchains%2Fpf3gnuchains3x.git * kill.cc (get_debug_priv): New function. (forcekill): Call get_debug_priv before trying to kill process. --- diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index c6f1d9e507..1aa9e1ffcd 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,8 @@ +2004-03-13 Rob Siklos + + * kill.cc (get_debug_priv): New function. + (forcekill): Call get_debug_priv before trying to kill process. + 2004-02-24 Christopher Faylor * cygpath.cc (long_options): Add "mode" option. diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc index a4dba050d5..deb0b41a32 100644 --- a/winsup/utils/kill.cc +++ b/winsup/utils/kill.cc @@ -125,9 +125,38 @@ listsig (const char *in_sig) } } +static void +get_debug_priv (void) +{ + HANDLE tok; + LUID luid; + TOKEN_PRIVILEGES tkp; + + if (!OpenProcessToken (GetCurrentProcess (), + TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tok)) + return; + + if (!LookupPrivilegeValue (NULL, SE_DEBUG_NAME, &luid)) + { + CloseHandle (tok); + return; + } + + tkp.PrivilegeCount = 1; + tkp.Privileges[0].Luid = luid; + tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + + AdjustTokenPrivileges (tok, FALSE, &tkp, sizeof tkp, NULL, NULL); + + CloseHandle (tok); +} + static void __stdcall forcekill (int pid, int sig, int wait) { + // try to acquire SeDebugPrivilege + get_debug_priv(); + external_pinfo *p = (external_pinfo *) cygwin_internal (CW_GETPINFO_FULL, pid); DWORD dwpid = p ? p->dwProcessId : (DWORD) pid; HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) dwpid); @@ -254,3 +283,4 @@ out: } return ret; } +