* Patch: kill() undex win32
@ 2004-11-11 10:48 Wesley W. Terpstra
2004-11-11 12:54 ` Wesley W. Terpstra
0 siblings, 1 reply; 4+ messages in thread
From: Wesley W. Terpstra @ 2004-11-11 10:48 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 776 bytes --]
Good evening.
I think it would be useful if the win32 version of ocaml could at least
terminate child processes. I am not a windows expert at all, and I do not
own VC++ so I cannot test this patch (is there a free licence for it?).
However, from reading the MSDN [1] it seems that to kill a process, the
method to use is TerminateProcess and has been present since Win95. The
attached patch adds to ocaml-3.08.1 a simple version of kill which
terminates a process.
Could someone who has VC++ verify if it works?
Do others think that this functionality would be useful?
Could something like this be present in the next version of OCaml?
Thanks!
[1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminateprocess.asp
--
Wesley W. Terpstra
[-- Attachment #2: ocaml-win32-terminate.patch --]
[-- Type: text/plain, Size: 2865 bytes --]
diff -uN otherlibs/win32unix.orig/Makefile.nt otherlibs/win32unix/Makefile.nt
--- otherlibs/win32unix.orig/Makefile.nt 2004-05-30 10:17:06.000000000 +0200
+++ otherlibs/win32unix/Makefile.nt 2004-11-11 11:34:58.000000000 +0100
@@ -30,7 +30,7 @@
mkdir.c open.c pipe.c read.c rename.c \
select.c sendrecv.c \
shutdown.c sleep.c socket.c sockopt.c startup.c stat.c \
- system.c unixsupport.c windir.c winwait.c write.c
+ system.c unixsupport.c windir.c winwait.c winkill.c write.c
# Files from the ../unix directory
UNIX_FILES = access.c addrofstr.c chdir.c chmod.c cst2constr.c \
diff -uN otherlibs/win32unix.orig/unix.ml otherlibs/win32unix/unix.ml
--- otherlibs/win32unix.orig/unix.ml 2004-06-22 19:18:50.000000000 +0200
+++ otherlibs/win32unix/unix.ml 2004-11-11 11:40:45.000000000 +0100
@@ -385,7 +385,8 @@
| F_TRLOCK
external lockf : file_descr -> lock_command -> int -> unit = "unix_lockf"
-let kill pid signo = invalid_arg "Unix.kill not implemented"
+external kill : int -> int -> unit = "win_killpid"
+
type sigprocmask_command = SIG_SETMASK | SIG_BLOCK | SIG_UNBLOCK
let sigprocmask cmd sigs = invalid_arg "Unix.sigprocmask not implemented"
let sigpending () = invalid_arg "Unix.sigpending not implemented"
diff -uN otherlibs/win32unix.orig/winkill.c otherlibs/win32unix/winkill.c
--- otherlibs/win32unix.orig/winkill.c 1970-01-01 01:00:00.000000000 +0100
+++ otherlibs/win32unix/winkill.c 2004-11-11 11:33:50.000000000 +0100
@@ -0,0 +1,33 @@
+/***********************************************************************/
+/* */
+/* Objective Caml */
+/* */
+/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 1996 Institut National de Recherche en Informatique et */
+/* en Automatique. All rights reserved. This file is distributed */
+/* under the terms of the GNU Library General Public License, with */
+/* the special exception on linking described in file ../../LICENSE. */
+/* */
+/***********************************************************************/
+
+/* $Id: winwait.c,v 1.14 2002/06/07 09:49:41 xleroy Exp $ */
+
+#include <windows.h>
+#include <mlvalues.h>
+#include <alloc.h>
+#include <memory.h>
+#include "unixsupport.h"
+#include <sys/types.h>
+
+CAMLprim value win_killpid(value sig, value vpid_req)
+{
+ /* we ignore the passed signal */
+ HANDLE pid_req = (HANDLE) Long_val(vpid_req);
+
+ if (! TerminateProcess(pid_req, 0x80)) {
+ win32_maperr(GetLastError());
+ uerror("killpid", Nothing);
+ }
+ return Val_unit;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Patch: kill() undex win32
2004-11-11 10:48 Patch: kill() undex win32 Wesley W. Terpstra
@ 2004-11-11 12:54 ` Wesley W. Terpstra
2004-11-11 23:42 ` [Caml-list] " Christopher A. Watford
0 siblings, 1 reply; 4+ messages in thread
From: Wesley W. Terpstra @ 2004-11-11 12:54 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 247 bytes --]
On Thu, Nov 11, 2004 at 11:48:49AM +0100, Wesley W. Terpstra wrote:
> ... so I cannot test this patch (is there a free licence for it?).
I can, however, find some bugs.
The parameters were backwards, this patch is better.
--
Wesley W. Terpstra
[-- Attachment #2: ocaml-win32-terminate.patch --]
[-- Type: text/plain, Size: 2865 bytes --]
diff -uN otherlibs/win32unix.orig/Makefile.nt otherlibs/win32unix/Makefile.nt
--- otherlibs/win32unix.orig/Makefile.nt 2004-05-30 10:17:06.000000000 +0200
+++ otherlibs/win32unix/Makefile.nt 2004-11-11 11:34:58.000000000 +0100
@@ -30,7 +30,7 @@
mkdir.c open.c pipe.c read.c rename.c \
select.c sendrecv.c \
shutdown.c sleep.c socket.c sockopt.c startup.c stat.c \
- system.c unixsupport.c windir.c winwait.c write.c
+ system.c unixsupport.c windir.c winwait.c winkill.c write.c
# Files from the ../unix directory
UNIX_FILES = access.c addrofstr.c chdir.c chmod.c cst2constr.c \
diff -uN otherlibs/win32unix.orig/unix.ml otherlibs/win32unix/unix.ml
--- otherlibs/win32unix.orig/unix.ml 2004-06-22 19:18:50.000000000 +0200
+++ otherlibs/win32unix/unix.ml 2004-11-11 11:40:45.000000000 +0100
@@ -385,7 +385,8 @@
| F_TRLOCK
external lockf : file_descr -> lock_command -> int -> unit = "unix_lockf"
-let kill pid signo = invalid_arg "Unix.kill not implemented"
+external kill : int -> int -> unit = "win_killpid"
+
type sigprocmask_command = SIG_SETMASK | SIG_BLOCK | SIG_UNBLOCK
let sigprocmask cmd sigs = invalid_arg "Unix.sigprocmask not implemented"
let sigpending () = invalid_arg "Unix.sigpending not implemented"
diff -uN otherlibs/win32unix.orig/winkill.c otherlibs/win32unix/winkill.c
--- otherlibs/win32unix.orig/winkill.c 1970-01-01 01:00:00.000000000 +0100
+++ otherlibs/win32unix/winkill.c 2004-11-11 11:33:50.000000000 +0100
@@ -0,0 +1,33 @@
+/***********************************************************************/
+/* */
+/* Objective Caml */
+/* */
+/* Pascal Cuoq and Xavier Leroy, projet Cristal, INRIA Rocquencourt */
+/* */
+/* Copyright 1996 Institut National de Recherche en Informatique et */
+/* en Automatique. All rights reserved. This file is distributed */
+/* under the terms of the GNU Library General Public License, with */
+/* the special exception on linking described in file ../../LICENSE. */
+/* */
+/***********************************************************************/
+
+/* $Id: winwait.c,v 1.14 2002/06/07 09:49:41 xleroy Exp $ */
+
+#include <windows.h>
+#include <mlvalues.h>
+#include <alloc.h>
+#include <memory.h>
+#include "unixsupport.h"
+#include <sys/types.h>
+
+CAMLprim value win_killpid(value vpid_req, value sig)
+{
+ /* we ignore the passed signal */
+ HANDLE pid_req = (HANDLE) Long_val(vpid_req);
+
+ if (! TerminateProcess(pid_req, 0x80)) {
+ win32_maperr(GetLastError());
+ uerror("killpid", Nothing);
+ }
+ return Val_unit;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Re: Patch: kill() undex win32
2004-11-11 12:54 ` Wesley W. Terpstra
@ 2004-11-11 23:42 ` Christopher A. Watford
2004-11-12 1:07 ` Wesley W. Terpstra
0 siblings, 1 reply; 4+ messages in thread
From: Christopher A. Watford @ 2004-11-11 23:42 UTC (permalink / raw)
To: Wesley W. Terpstra; +Cc: caml-list
On Thu, 11 Nov 2004 13:54:57 +0100, Wesley W. Terpstra
<terpstra@gkec.tu-darmstadt.de> wrote:
> On Thu, Nov 11, 2004 at 11:48:49AM +0100, Wesley W. Terpstra wrote:
> > ... so I cannot test this patch (is there a free licence for it?).
>
> I can, however, find some bugs.
> The parameters were backwards, this patch is better.
>
> --
> Wesley W. Terpstra
>
Might I ask why 0x80 is being returned as the exit code instead of
something from winbase.h (auto from windows.h) like:
STATUS_CONTROL_C_EXIT
Which, while it is not the case that exactly is happening, it does let
the user know with a fairly standard method as to what happened to
their thread/process.
--
Christopher A. Watford
christopher.watford@gmail.com
http://dorm.tunkeymicket.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Re: Patch: kill() undex win32
2004-11-11 23:42 ` [Caml-list] " Christopher A. Watford
@ 2004-11-12 1:07 ` Wesley W. Terpstra
0 siblings, 0 replies; 4+ messages in thread
From: Wesley W. Terpstra @ 2004-11-12 1:07 UTC (permalink / raw)
To: Christopher A. Watford; +Cc: caml-list
On Thu, Nov 11, 2004 at 06:42:04PM -0500, Christopher A. Watford wrote:
> Might I ask why 0x80 is being returned as the exit code instead of
> something from winbase.h (auto from windows.h) like:
>
> STATUS_CONTROL_C_EXIT
I didn't have any particular reason for choosing that value. If you think
that STATUS_CONTROL_C_EXIT makes more sense under windows, then I'm all for
that (esp. since you knew it existed and thus more than I).
Mostly I didn't want it to be near 'user' returnable values like 0,1,2,...
and also not near syscall return values -1,... 0x80 seemed to be a good
middle ground. ;) Another suggestion might be to use the signal number
itself for the return code.
At least for me the return code is irrelevant; I just need to be able to
kill my child processes when the ocaml program quits abnormally.
> Which, while it is not the case that exactly is happening, it does let
> the user know with a fairly standard method as to what happened to
> their thread/process.
I'd like to point out that this patch can only work for child processes
created from the ocaml program. So, I think it's unlikely that there is
a user involved to interpret the CTRL-C, or even be concerned that the
process vanished.
PS. Did you try the patch? Does it work?
--
Wesley W. Terpstra
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-11-12 1:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-11 10:48 Patch: kill() undex win32 Wesley W. Terpstra
2004-11-11 12:54 ` Wesley W. Terpstra
2004-11-11 23:42 ` [Caml-list] " Christopher A. Watford
2004-11-12 1:07 ` Wesley W. Terpstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox