diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-12-23 00:05:21 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-12-23 20:43:32 +0000 |
commit | 6a949ed1556f239a84a7ccb8d3b207f99cdf71c8 (patch) | |
tree | e4e4ab558e3c6465f6906a6382859152492c040f /extcap_spawn.c | |
parent | 13a9c636a52ae2c6e2bc2070f4a4f047afe6a6ef (diff) |
Put special pipe-handling code into libwsutil.
Ask, in a comment, why we're doing PeekNamedPipe() when we're trying
to read everyting in the pipe, up to the EOF, into a string.
On UN*X, do the same "read up to an EOF and then NUL-terminate the
result" stuff that we did on Windows; nothing guarantees that, on all
UN*Xes, in all circumstances, until the end of time, world without end,
amen, we can do one read and get the entire string.
Change-Id: I578802b23fec1051139eaefd9a09fe2a6de06a11
Reviewed-on: https://code.wireshark.org/review/24959
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'extcap_spawn.c')
-rw-r--r-- | extcap_spawn.c | 32 |
1 files changed, 2 insertions, 30 deletions
diff --git a/extcap_spawn.c b/extcap_spawn.c index a5d9f4df53..42434df819 100644 --- a/extcap_spawn.c +++ b/extcap_spawn.c @@ -18,6 +18,7 @@ #include <wsutil/file_util.h> #include <wsutil/filesystem.h> +#include <wsutil/ws_pipe.h> #ifdef _WIN32 #include <wsutil/win32-utils.h> #endif @@ -27,35 +28,6 @@ #include "extcap.h" #include "extcap_spawn.h" -#ifdef _WIN32 - -void win32_readfrompipe(HANDLE read_pipe, gint32 max_buffer, gchar *buffer) -{ - gboolean bSuccess = FALSE; - gint32 bytes_written = 0; - gint32 max_bytes = 0; - - DWORD dwRead; - DWORD bytes_avail = 0; - - for (;;) - { - if (!PeekNamedPipe(read_pipe, NULL, 0, NULL, &bytes_avail, NULL)) break; - if (bytes_avail <= 0) break; - - max_bytes = max_buffer - bytes_written - 1; - - bSuccess = ReadFile(read_pipe, &buffer[bytes_written], max_bytes, &dwRead, NULL); - if (!bSuccess || dwRead == 0) break; - - bytes_written += dwRead; - if ((bytes_written + 1) >= max_buffer) break; - } - - buffer[bytes_written] = '\0'; -} -#endif - gboolean extcap_spawn_sync(gchar *dirname, gchar *command, gint argc, gchar **args, gchar **command_output) { gboolean status = FALSE; @@ -148,7 +120,7 @@ gboolean extcap_spawn_sync(gchar *dirname, gchar *command, gint argc, gchar **ar if (CreateProcess(NULL, wcommandline, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &info, &processInfo)) { WaitForSingleObject(processInfo.hProcess, INFINITE); - win32_readfrompipe(child_stdout_rd, BUFFER_SIZE, buffer); + ws_read_string_from_pipe(child_stdout_rd, buffer, BUFFER_SIZE); local_output = g_strdup_printf("%s", buffer); CloseHandle(child_stdout_rd); |