From: LRN Date: Thu, 14 Feb 2013 16:15:26 +0000 (+0000) Subject: Make w32cat pipe-controllable X-Git-Tag: initial-import-from-subversion-38251~9923 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=6ec800a7d58bd7e5d79adf2413732c90ba02397a;p=oweals%2Fgnunet.git Make w32cat pipe-controllable --- diff --git a/src/util/w32cat.c b/src/util/w32cat.c index 292bd6d48..4f56ba58e 100644 --- a/src/util/w32cat.c +++ b/src/util/w32cat.c @@ -20,6 +20,46 @@ #include #include +#include +#include + +DWORD WINAPI +parent_control_thread (LPVOID lpParameter) +{ + HANDLE h = (HANDLE) lpParameter; + while (TRUE) + { + DWORD dw; + BOOL b; + unsigned char c; + b = ReadFile (h, &c, 1, &dw, NULL); + if (!b) + { + ExitProcess (0); + } + raise ((int) c); + } +} + +void +install_parent_control_handler () +{ + const char *env_buf; + char *env_buf_end; + uint64_t pipe_fd; + HANDLE pipe_handle; + + env_buf = getenv ("GNUNET_OS_CONTROL_PIPE"); + if ( (NULL == env_buf) || (strlen (env_buf) <= 0) ) + return; + errno = 0; + pipe_fd = strtoull (env_buf, &env_buf_end, 16); + if ((0 != errno) || (env_buf == env_buf_end)) + return; + /* Gcc will issue a warning here. What to do with it? */ + pipe_handle = (HANDLE) pipe_fd; + CreateThread (NULL, 0, parent_control_thread, (LPVOID) pipe_handle, 0, NULL); +} int main (int argc, char **argv) @@ -39,6 +79,8 @@ main (int argc, char **argv) if (argvw == NULL) return 1; + install_parent_control_handler (); + for (i = 1; i < argcw || argcw == 1; i++) { DWORD r, w;