diff options
author | LRN <lrn1986@gmail.com> | 2013-02-14 16:15:26 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-02-14 16:15:26 +0000 |
commit | 6ec800a7d58bd7e5d79adf2413732c90ba02397a (patch) | |
tree | ee944568d5dac7e2a303a78273077bedbdd8b8c9 /src/util | |
parent | f408da5bae9e316687069845a9da34a59df2eca8 (diff) | |
download | gnunet-6ec800a7d58bd7e5d79adf2413732c90ba02397a.tar.gz gnunet-6ec800a7d58bd7e5d79adf2413732c90ba02397a.zip |
Make w32cat pipe-controllable
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/w32cat.c | 42 |
1 files changed, 42 insertions, 0 deletions
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 @@ | |||
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <windows.h> | 22 | #include <windows.h> |
23 | #include <stdint.h> | ||
24 | #include <signal.h> | ||
25 | |||
26 | DWORD WINAPI | ||
27 | parent_control_thread (LPVOID lpParameter) | ||
28 | { | ||
29 | HANDLE h = (HANDLE) lpParameter; | ||
30 | while (TRUE) | ||
31 | { | ||
32 | DWORD dw; | ||
33 | BOOL b; | ||
34 | unsigned char c; | ||
35 | b = ReadFile (h, &c, 1, &dw, NULL); | ||
36 | if (!b) | ||
37 | { | ||
38 | ExitProcess (0); | ||
39 | } | ||
40 | raise ((int) c); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | void | ||
45 | install_parent_control_handler () | ||
46 | { | ||
47 | const char *env_buf; | ||
48 | char *env_buf_end; | ||
49 | uint64_t pipe_fd; | ||
50 | HANDLE pipe_handle; | ||
51 | |||
52 | env_buf = getenv ("GNUNET_OS_CONTROL_PIPE"); | ||
53 | if ( (NULL == env_buf) || (strlen (env_buf) <= 0) ) | ||
54 | return; | ||
55 | errno = 0; | ||
56 | pipe_fd = strtoull (env_buf, &env_buf_end, 16); | ||
57 | if ((0 != errno) || (env_buf == env_buf_end)) | ||
58 | return; | ||
59 | /* Gcc will issue a warning here. What to do with it? */ | ||
60 | pipe_handle = (HANDLE) pipe_fd; | ||
61 | CreateThread (NULL, 0, parent_control_thread, (LPVOID) pipe_handle, 0, NULL); | ||
62 | } | ||
23 | 63 | ||
24 | int | 64 | int |
25 | main (int argc, char **argv) | 65 | main (int argc, char **argv) |
@@ -39,6 +79,8 @@ main (int argc, char **argv) | |||
39 | if (argvw == NULL) | 79 | if (argvw == NULL) |
40 | return 1; | 80 | return 1; |
41 | 81 | ||
82 | install_parent_control_handler (); | ||
83 | |||
42 | for (i = 1; i < argcw || argcw == 1; i++) | 84 | for (i = 1; i < argcw || argcw == 1; i++) |
43 | { | 85 | { |
44 | DWORD r, w; | 86 | DWORD r, w; |