From c452048cae6ff8b275e72a2f4b590ccaeebc35ba Mon Sep 17 00:00:00 2001 From: Paul Joseph Davis Date: Thu, 26 Nov 2009 19:29:35 +0000 Subject: Move all C code to src/couchdb/priv Shuffling bits around to conform to Erlang conventions. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@884671 13f79535-47bb-0310-9956-ffa450edef68 --- .../priv/spawnkillable/couchspawnkillable.sh | 20 +++ .../priv/spawnkillable/couchspawnkillable_win.c | 139 +++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 src/couchdb/priv/spawnkillable/couchspawnkillable.sh create mode 100644 src/couchdb/priv/spawnkillable/couchspawnkillable_win.c (limited to 'src/couchdb/priv/spawnkillable') diff --git a/src/couchdb/priv/spawnkillable/couchspawnkillable.sh b/src/couchdb/priv/spawnkillable/couchspawnkillable.sh new file mode 100644 index 00000000..f8d042e3 --- /dev/null +++ b/src/couchdb/priv/spawnkillable/couchspawnkillable.sh @@ -0,0 +1,20 @@ +#! /bin/sh -e + +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +# The purpose of this script is to echo an OS specific command before launching +# the actual process. This provides a way for Erlang to hard-kill its external +# processes. + +echo "kill -9 $$" +exec $* diff --git a/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c b/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c new file mode 100644 index 00000000..f812711e --- /dev/null +++ b/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c @@ -0,0 +1,139 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +// Do what 2 lines of shell script in couchspawnkillable does... +// * Create a new suspended process with the same (duplicated) standard +// handles as us. +// * Write a line to stdout, consisting of the path to ourselves, plus +// '--kill {pid}' where {pid} is the PID of the newly created process. +// * Un-suspend the new process. +// * Terminate + +// Later, couch will call us with --kill and the PID, so we dutifully +// terminate the specified PID. + +#include +#include "windows.h" + +char *get_child_cmdline(int argc, char **argv) +{ + // make a new command-line, but skipping me. + // XXX - todo - spaces etc in args??? + int i; + char *p, *cmdline; + int nchars = 0; + int nthis = 1; + for (i=1;i