From af53a09c707a8fd0bd8eaf218d9625e0c7fe09e9 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 11 Mar 2002 18:33:02 +0000 Subject: [PATCH] * kill.cc (usage): Move to top of file. (getsig): Ditto. (forcekill): Ditto. --- winsup/utils/ChangeLog | 6 ++++ winsup/utils/kill.cc | 76 ++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index 1a6bf8a49..a02f2a460 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,9 @@ +2001-03-11 Joshua Daniel Franklin + + * kill.cc (usage): Move to top of file. + (getsig): Ditto. + (forcekill): Ditto. + 2002-03-06 Christopher Faylor * cygcheck.cc: Reformat. diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc index 626b07156..2f538ea49 100644 --- a/winsup/utils/kill.cc +++ b/winsup/utils/kill.cc @@ -17,9 +17,42 @@ details. */ #include #include -static void usage (void); -static int __stdcall getsig (char *); -static void __stdcall forcekill (int, int, int); +static void +usage (void) +{ + fprintf (stderr, "Usage: kill [-sigN] pid1 [pid2 ...]\n"); + exit (1); +} + +static int +getsig (char *in_sig) +{ + char *sig; + char buf[80]; + + if (strncmp (in_sig, "SIG", 3) == 0) + sig = in_sig; + else + { + sprintf (buf, "SIG%s", in_sig); + sig = buf; + } + return (strtosigno (sig) ?: atoi (in_sig)); +} + +static void __stdcall +forcekill (int pid, int sig, int wait) +{ + external_pinfo *p = (external_pinfo *) cygwin_internal (CW_GETPINFO_FULL, pid); + if (!p) + return; + HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) p->dwProcessId); + if (!h) + return; + if (!wait || WaitForSingleObject (h, 200) != WAIT_OBJECT_0) + TerminateProcess (h, sig << 8); + CloseHandle (h); +} int main (int argc, char **argv) @@ -83,40 +116,3 @@ sig0: } return ret; } - -static void -usage (void) -{ - fprintf (stderr, "Usage: kill [-sigN] pid1 [pid2 ...]\n"); - exit (1); -} - -static int -getsig (char *in_sig) -{ - char *sig; - char buf[80]; - - if (strncmp (in_sig, "SIG", 3) == 0) - sig = in_sig; - else - { - sprintf (buf, "SIG%s", in_sig); - sig = buf; - } - return (strtosigno (sig) ?: atoi (in_sig)); -} - -static void __stdcall -forcekill (int pid, int sig, int wait) -{ - external_pinfo *p = (external_pinfo *) cygwin_internal (CW_GETPINFO_FULL, pid); - if (!p) - return; - HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) p->dwProcessId); - if (!h) - return; - if (!wait || WaitForSingleObject (h, 200) != WAIT_OBJECT_0) - TerminateProcess (h, sig << 8); - CloseHandle (h); -}