diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-23 22:33:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-23 22:33:52 +0000 |
commit | 2d672a8e5ce41108e0ab52cbeaef5ebcce94b67c (patch) | |
tree | 4a4f91b6b69d5bf2463f963924bc444caafd5ba1 /src | |
parent | de8fb70966c0eb3b0a8c7207a19a34b1ee24629f (diff) | |
download | gnunet-2d672a8e5ce41108e0ab52cbeaef5ebcce94b67c.tar.gz gnunet-2d672a8e5ce41108e0ab52cbeaef5ebcce94b67c.zip |
-LRN: Wincat:
I've been experimenting with an alternative non-MSYS buildsystem for
a while, and GNUNET_os_start_process() test kept failing due to lack
of cat. Wincat is a minimal cat implementation in pure WinAPI. It's
not named "cat.exe" to avoid clashing with MSYS cat (which can lead to
some very weird issues).
Diffstat (limited to 'src')
-rw-r--r-- | src/util/Makefile.am | 6 | ||||
-rw-r--r-- | src/util/test_os_start_process.c | 20 | ||||
-rw-r--r-- | src/util/w32cat.c | 108 |
3 files changed, 132 insertions, 2 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 5426953fc..3be3062d0 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -22,6 +22,7 @@ libgnunetutilwin_la_LIBADD = \ | |||
22 | -lshell32 -liconv -lstdc++ \ | 22 | -lshell32 -liconv -lstdc++ \ |
23 | -lcomdlg32 -lgdi32 -liphlpapi | 23 | -lcomdlg32 -lgdi32 -liphlpapi |
24 | WINLIB = libgnunetutilwin.la | 24 | WINLIB = libgnunetutilwin.la |
25 | W32CAT = w32cat | ||
25 | endif | 26 | endif |
26 | 27 | ||
27 | if !MINGW | 28 | if !MINGW |
@@ -33,8 +34,11 @@ if USE_COVERAGE | |||
33 | XLIB = -lgcov | 34 | XLIB = -lgcov |
34 | endif | 35 | endif |
35 | 36 | ||
37 | cat_SOURCES = w32cat.c | ||
38 | |||
36 | noinst_PROGRAMS = \ | 39 | noinst_PROGRAMS = \ |
37 | gnunet-config-diff \ | 40 | gnunet-config-diff \ |
41 | $(W32CAT) \ | ||
38 | test_common_logging_dummy | 42 | test_common_logging_dummy |
39 | 43 | ||
40 | 44 | ||
@@ -224,6 +228,8 @@ test_os_start_process_SOURCES = \ | |||
224 | test_os_start_process.c | 228 | test_os_start_process.c |
225 | test_os_start_process_LDADD = \ | 229 | test_os_start_process_LDADD = \ |
226 | $(top_builddir)/src/util/libgnunetutil.la | 230 | $(top_builddir)/src/util/libgnunetutil.la |
231 | test_os_start_process_DEPENDENCIES = \ | ||
232 | $(WINCAT) | ||
227 | 233 | ||
228 | test_client_SOURCES = \ | 234 | test_client_SOURCES = \ |
229 | test_client.c | 235 | test_client.c |
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 5b9973250..3c30c75f3 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c | |||
@@ -113,7 +113,11 @@ run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
113 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; | 113 | const struct GNUNET_DISK_FileHandle *stdout_read_handle; |
114 | const struct GNUNET_DISK_FileHandle *wh; | 114 | const struct GNUNET_DISK_FileHandle *wh; |
115 | 115 | ||
116 | #if !WINDOWS | ||
116 | GNUNET_asprintf (&fn, "cat"); | 117 | GNUNET_asprintf (&fn, "cat"); |
118 | #else | ||
119 | GNUNET_asprintf (&fn, "w32cat"); | ||
120 | #endif | ||
117 | 121 | ||
118 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); | 122 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); |
119 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | 123 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); |
@@ -183,6 +187,12 @@ check_run () | |||
183 | static int | 187 | static int |
184 | check_kill () | 188 | check_kill () |
185 | { | 189 | { |
190 | char *fn; | ||
191 | #if !WINDOWS | ||
192 | GNUNET_asprintf (&fn, "cat"); | ||
193 | #else | ||
194 | GNUNET_asprintf (&fn, "w32cat"); | ||
195 | #endif | ||
186 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); | 196 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); |
187 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | 197 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); |
188 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | 198 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) |
@@ -190,7 +200,7 @@ check_kill () | |||
190 | return 1; | 200 | return 1; |
191 | } | 201 | } |
192 | proc = | 202 | proc = |
193 | GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, "cat", | 203 | GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, fn, |
194 | "gnunet-service-resolver", "-", NULL); | 204 | "gnunet-service-resolver", "-", NULL); |
195 | sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */ | 205 | sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */ |
196 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 206 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
@@ -210,6 +220,12 @@ check_kill () | |||
210 | static int | 220 | static int |
211 | check_instant_kill () | 221 | check_instant_kill () |
212 | { | 222 | { |
223 | char *fn; | ||
224 | #if !WINDOWS | ||
225 | GNUNET_asprintf (&fn, "cat"); | ||
226 | #else | ||
227 | GNUNET_asprintf (&fn, "w32cat"); | ||
228 | #endif | ||
213 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); | 229 | hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); |
214 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); | 230 | hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); |
215 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) | 231 | if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) |
@@ -217,7 +233,7 @@ check_instant_kill () | |||
217 | return 1; | 233 | return 1; |
218 | } | 234 | } |
219 | proc = | 235 | proc = |
220 | GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, "cat", | 236 | GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, fn, |
221 | "gnunet-service-resolver", "-", NULL); | 237 | "gnunet-service-resolver", "-", NULL); |
222 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 238 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
223 | { | 239 | { |
diff --git a/src/util/w32cat.c b/src/util/w32cat.c new file mode 100644 index 000000000..0c5091c66 --- /dev/null +++ b/src/util/w32cat.c | |||
@@ -0,0 +1,108 @@ | |||
1 | /* | ||
2 | W32 version of 'cat' program | ||
3 | (C) 2012 LRN | ||
4 | |||
5 | cat is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | cat is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with cat; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <windows.h> | ||
23 | |||
24 | int | ||
25 | main (int argc, char **argv) | ||
26 | { | ||
27 | HANDLE stdi, stdo; | ||
28 | BOOL b; | ||
29 | wchar_t *commandlinew, **argvw; | ||
30 | int argcw; | ||
31 | int i; | ||
32 | |||
33 | stdo = GetStdHandle (STD_OUTPUT_HANDLE); | ||
34 | if (stdo == INVALID_HANDLE_VALUE || stdo == NULL) | ||
35 | return 1; | ||
36 | |||
37 | commandlinew = GetCommandLineW (); | ||
38 | argvw = CommandLineToArgvW (commandlinew, &argcw); | ||
39 | if (argvw == NULL) | ||
40 | return 1; | ||
41 | |||
42 | for (i = 1; i < argcw || argcw == 1; i++) | ||
43 | { | ||
44 | DWORD r, w; | ||
45 | int is_dash = wcscmp (argvw[i], L"-") == 0; | ||
46 | if (argcw == 1 || is_dash) | ||
47 | { | ||
48 | stdi = GetStdHandle (STD_INPUT_HANDLE); | ||
49 | if (stdi == INVALID_HANDLE_VALUE) | ||
50 | { | ||
51 | fprintf (stderr, "cat: Failed to obtain stdin handle.\n"); | ||
52 | return 4; | ||
53 | } | ||
54 | if (stdi == NULL) | ||
55 | { | ||
56 | fprintf (stderr, "cat: Have no stdin.\n"); | ||
57 | return 5; | ||
58 | } | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | stdi = CreateFileW (argvw[i], GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); | ||
63 | if (stdi == INVALID_HANDLE_VALUE) | ||
64 | { | ||
65 | wchar_t *msgbuf; | ||
66 | DWORD le = GetLastError (); | ||
67 | if (0 < FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, le, 0, (wchar_t *) &msgbuf, 0, NULL)) | ||
68 | { | ||
69 | fprintf (stderr, "cat: Failed to open file `%S'. Error %lu.\n", argvw[i], le); | ||
70 | return 3; | ||
71 | } | ||
72 | fprintf (stderr, "cat: Failed to open file `%S'. Error %lu: %S\n", argvw[i], le, msgbuf); | ||
73 | if (msgbuf != NULL) | ||
74 | LocalFree (msgbuf); | ||
75 | return 2; | ||
76 | } | ||
77 | } | ||
78 | do | ||
79 | { | ||
80 | unsigned char c; | ||
81 | b = ReadFile (stdi, &c, 1, &r, NULL); | ||
82 | if (r > 0) | ||
83 | { | ||
84 | b = WriteFile (stdo, &c, 1, &w, NULL); | ||
85 | if (b == 0) | ||
86 | { | ||
87 | wchar_t *msgbuf; | ||
88 | DWORD le = GetLastError (); | ||
89 | if (0 < FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, le, 0, (wchar_t *) &msgbuf, 0, NULL)) | ||
90 | { | ||
91 | fprintf (stderr, "cat: Failed to write into stdout. Error %lu.\n", le); | ||
92 | return 3; | ||
93 | } | ||
94 | fprintf (stderr, "cat: Failed to write into stdout. Error %lu: %S\n", le, msgbuf); | ||
95 | if (msgbuf != NULL) | ||
96 | LocalFree (msgbuf); | ||
97 | return 6; | ||
98 | } | ||
99 | } | ||
100 | } while (b && r > 0); | ||
101 | if (argcw == 1) | ||
102 | break; | ||
103 | if (!is_dash) | ||
104 | CloseHandle (stdi); | ||
105 | } | ||
106 | LocalFree (argvw); | ||
107 | return 0; | ||
108 | } | ||