OSDN Git Service

* kill.cc (get_debug_priv): New function.
authorcorinna <corinna>
Sat, 13 Mar 2004 18:11:13 +0000 (18:11 +0000)
committercorinna <corinna>
Sat, 13 Mar 2004 18:11:13 +0000 (18:11 +0000)
(forcekill): Call get_debug_priv before trying to kill process.

winsup/utils/ChangeLog
winsup/utils/kill.cc

index c6f1d9e..1aa9e1f 100644 (file)
@@ -1,3 +1,8 @@
+2004-03-13  Rob Siklos  <rob2@siklos.ca>
+
+       * kill.cc (get_debug_priv): New function.
+       (forcekill): Call get_debug_priv before trying to kill process.
+
 2004-02-24  Christopher Faylor  <cgf@redhat.com>
 
        * cygpath.cc (long_options): Add "mode" option.
index a4dba05..deb0b41 100644 (file)
@@ -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;
 }
+