gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r26118 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r26118 - gnunet/src/util
Date: Thu, 14 Feb 2013 17:15:26 +0100

Author: LRN
Date: 2013-02-14 17:15:26 +0100 (Thu, 14 Feb 2013)
New Revision: 26118

Modified:
   gnunet/src/util/w32cat.c
Log:
Make w32cat pipe-controllable

Modified: gnunet/src/util/w32cat.c
===================================================================
--- gnunet/src/util/w32cat.c    2013-02-14 16:15:22 UTC (rev 26117)
+++ gnunet/src/util/w32cat.c    2013-02-14 16:15:26 UTC (rev 26118)
@@ -20,7 +20,47 @@
 
 #include <stdio.h>
 #include <windows.h>
+#include <stdint.h>
+#include <signal.h>
 
+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 @@
   if (argvw == NULL)
     return 1;
 
+  install_parent_control_handler ();
+
   for (i = 1; i < argcw || argcw == 1; i++)
   {
     DWORD r, w;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]