git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC 06/11] run-command: add kill_async() and is_async_alive()

From
Erik Faye-Lund <kusmabite@googlemail.com>
Date
Nov 26, 2009, 00:39 UTC
Message-ID
<1259195958-2372-7-git-send-email-kusmabite@gmail.com>
In-Reply-To
<1259195958-2372-6-git-send-email-kusmabite@gmail.com>
These functions will aid the Windows port of git-daemon.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 run-command.c |   27 +++++++++++++++++++++++++++
 run-command.h |    2 ++
 2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/run-command.c b/run-command.c
index cf2d8f7..e5a0e06 100644
--- a/run-command.c
+++ b/run-command.c
@@ -373,6 +373,33 @@ int finish_async(struct async *async)
 	return ret;
 }
 
+int kill_async(struct async *async)
+{
+#ifndef WIN32
+	return kill(async->pid, SIGTERM);
+#else
+	DWORD ret = 0;
+	if (!TerminateThread(async->tid, 0))
+		ret = error("killing thread failed: %lu", GetLastError());
+	else if (!GetExitCodeThread(async->tid, &ret))
+		ret = error("cannot get thread exit code: %lu", GetLastError());
+	return ret;
+#endif
+}
+
+int is_async_alive(struct async *async)
+{
+#ifndef WIN32
+	int dummy;
+	return waitpid(async->pid, &dummy, WNOHANG);
+#else
+	int ret = WaitForSingleObject(async->tid, 0);
+	if (ret == WAIT_FAILED)
+		return error("checking thread state failed: %lu", GetLastError());
+	return ret != WAIT_OBJECT_0;
+#endif
+}
+
 int run_hook(const char *index_file, const char *name, ...)
 {
 	struct child_process hook;
diff --git a/run-command.h b/run-command.h
index fb34209..955b0bd 100644
--- a/run-command.h
+++ b/run-command.h
@@ -80,5 +80,7 @@ struct async {
 
 int start_async(struct async *async);
 int finish_async(struct async *async);
+int kill_async(struct async *async);
+int is_async_alive(struct async *async);
 
 #endif
-- 
1.6.5.rc2.7.g4f8d3
Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 7 of 13 in “daemon-win32”
  1. 00/11 daemon-win32Erik Faye-Lund, Nov 26, 2009
  2. 01/11 mingw: add network-wrappers for daemonErik Faye-Lund, Nov 26, 2009
  3. 02/11 strbuf: add non-variadic function strbuf_vaddf()Erik Faye-Lund, Nov 26, 2009
  4. 03/11 mingw: implement syslogErik Faye-Lund, Nov 26, 2009
  5. 04/11 compat: add inet_pton and inet_ntop prototypesErik Faye-Lund, Nov 26, 2009
  6. 05/11 inet_ntop: fix a couple of old-style declsErik Faye-Lund, Nov 26, 2009
  7. 06/11 run-command: add kill_async() and is_async_alive()Erik Faye-Lund, Nov 26, 2009
  8. 07/11 run-command: support input-fdErik Faye-Lund, Nov 26, 2009
  9. 08/11 daemon: use explicit file descriptorErik Faye-Lund, Nov 26, 2009
  10. 09/11 daemon: use run-command api for async servingErik Faye-Lund, Nov 26, 2009
  11. 10/11 daemon: use full buffered mode for stderrErik Faye-Lund, Nov 26, 2009
  12. 11/11 mingw: compile git-daemonErik Faye-Lund, Nov 26, 2009
  13. Erik Faye-LundNov 26, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.