This patch allows kill.exe -f to deal with Win9x pids.

Pierre

2004-11-03  Pierre Humblet <[EMAIL PROTECTED]>

        * kill.cc (forcekill): Do not pass negative pids to 
        cygwin_internal.
        (main): Make pid a long long and distinguish between pids,
        gpids (i.e. negative pids) and Win9x pids.
Index: kill.cc
===================================================================
RCS file: /cvs/src/src/winsup/utils/kill.cc,v
retrieving revision 1.24
diff -u -p -b -r1.24 kill.cc
--- kill.cc     27 May 2004 15:15:51 -0000      1.24
+++ kill.cc     2 Nov 2004 16:05:44 -0000
@@ -17,6 +17,7 @@ details. */
 #include <windows.h>
 #include <sys/cygwin.h>
 #include <getopt.h>
+#include <limits.h>

 static const char version[] = "$Revision: 1.14 $";
 static char *prog_name;
@@ -157,7 +158,10 @@ 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);
+  external_pinfo *p = NULL;
+  /* cygwin_internal misinterprets negative pids (Win9x pids) */
+  if (pid > 0)
+    p = (external_pinfo *) cygwin_internal (CW_GETPINFO_FULL, pid);
   DWORD dwpid = p ? p->dwProcessId : (DWORD) pid;
   HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) dwpid);
   if (!h)
@@ -195,7 +199,7 @@ main (int argc, char **argv)
   opterr = 0;

   char *p;
-  int pid = 0;
+  long long int pid = 0;

   for (;;)
     {
@@ -235,7 +239,7 @@ main (int argc, char **argv)
        case '?':
          if (gotasig)
            {
-             pid = strtol (argv[optind], &p, 10);
+             pid = strtoll (argv[optind], &p, 10);
              if (pid < 0)
                goto out;
              usage ();
@@ -258,23 +262,23 @@ out:
   while (*argv != NULL)
     {
       if (!pid)
-       pid = strtol (*argv, &p, 10);
-      if (*p != '\0')
+       pid = strtoll (*argv, &p, 10);
+      if (pid < LONG_MIN || pid > ULONG_MAX || *p != '\0')
        {
          fprintf (stderr, "%s: illegal pid: %s\n", prog_name, *argv);
          ret = 1;
        }
-      else if (kill (pid, sig) == 0)
+      else if (pid <= LONG_MAX && kill ((pid_t) pid, sig) == 0)
        {
          if (force)
-           forcekill (pid, sig, 1);
+           forcekill ((pid_t) pid, sig, 1);
        }
-      else if (force && sig != 0)
-       forcekill (pid, sig, 0);
+      else if (pid > 0 && (force || pid > LONG_MAX) && sig != 0)
+       forcekill ((pid_t) pid, sig, 0);
       else
        {
          char buf[1000];
-         sprintf (buf, "%s %d", prog_name, pid);
+         sprintf (buf, "%s %lld", prog_name, pid);
          perror (buf);
          ret = 1;
        }

Reply via email to