From 1902392ba62849c39fc14b2ec893e531ea9e00b3 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Wed, 2 Dec 2009 06:38:23 +0000 Subject: ensure the child exit code is reported correctly to couch git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@886061 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/priv/spawnkillable/couchspawnkillable_win.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/couchdb/priv') diff --git a/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c b/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c index f812711e..06782315 100644 --- a/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c +++ b/src/couchdb/priv/spawnkillable/couchspawnkillable_win.c @@ -16,7 +16,8 @@ // * 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 +// * Wait for the process to terminate. +// * Terminate with the child's exit-code. // Later, couch will call us with --kill and the PID, so we dutifully // terminate the specified PID. @@ -112,6 +113,7 @@ int main(int argc, char **argv) char out_buf[1024]; int rc; DWORD cbwritten; + DWORD exitcode; PROCESS_INFORMATION pi; if (argc==3 && strcmp(argv[1], "--kill")==0) { HANDLE h = OpenProcess(PROCESS_TERMINATE, 0, atoi(argv[2])); @@ -134,6 +136,10 @@ int main(int argc, char **argv) &cbwritten, NULL); // Let the child process go... ResumeThread(pi.hThread); - // and that is all - we can die... - return 0; + // Wait for the process to terminate so we can reflect the exit code + // back to couch. + WaitForSingleObject(pi.hProcess, INFINITE); + if (!GetExitCodeProcess(pi.hProcess, &exitcode)) + return 6; + return exitcode; } -- cgit v1.2.3