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.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.c')
-rw-r--r-- | extcap.c | 60 |
1 files changed, 4 insertions, 56 deletions
@@ -42,6 +42,7 @@ #include <wsutil/glib-compat.h> #include <wsutil/file_util.h> #include <wsutil/filesystem.h> +#include <wsutil/ws_pipe.h> #include <wsutil/tempfile.h> #include "capture_opts.h" @@ -944,46 +945,6 @@ extcap_has_toolbar(const char *ifname) return FALSE; } -/* taken from capchild/capture_sync.c */ -static gboolean pipe_data_available(int pipe_fd) -{ -#ifdef _WIN32 /* PeekNamedPipe */ - HANDLE hPipe = (HANDLE) _get_osfhandle(pipe_fd); - DWORD bytes_avail; - - if (hPipe == INVALID_HANDLE_VALUE) - { - return FALSE; - } - - if (! PeekNamedPipe(hPipe, NULL, 0, NULL, &bytes_avail, NULL)) - { - return FALSE; - } - - if (bytes_avail > 0) - { - return TRUE; - } - return FALSE; -#else /* select */ - fd_set rfds; - struct timeval timeout; - - FD_ZERO(&rfds); - FD_SET(pipe_fd, &rfds); - timeout.tv_sec = 0; - timeout.tv_usec = 0; - - if (select(pipe_fd + 1, &rfds, NULL, NULL, &timeout) > 0) - { - return TRUE; - } - - return FALSE; -#endif -} - void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg) { interface_options *interface_opts; @@ -1064,23 +1025,10 @@ void extcap_if_cleanup(capture_options *capture_opts, gchar **errormsg) userdata = (extcap_userdata *) interface_opts->extcap_userdata; if (userdata) { - if (userdata->extcap_stderr_rd > 0 && pipe_data_available(userdata->extcap_stderr_rd)) + if (userdata->extcap_stderr_rd > 0 && ws_pipe_data_available(userdata->extcap_stderr_rd)) { - buffer = (gchar *)g_malloc0(sizeof(gchar) * STDERR_BUFFER_SIZE + 1); -#ifdef _WIN32 - win32_readfrompipe((HANDLE)_get_osfhandle(userdata->extcap_stderr_rd), STDERR_BUFFER_SIZE, buffer); -#else - ssize_t buffer_len; - buffer_len = read(userdata->extcap_stderr_rd, buffer, sizeof(gchar) * STDERR_BUFFER_SIZE); - if (buffer_len <= 0) - { - buffer[0] = '\0'; - } - else - { - buffer[buffer_len] = '\0'; - } -#endif + buffer = (gchar *)g_malloc0(STDERR_BUFFER_SIZE + 1); + ws_read_string_from_pipe(ws_get_pipe_handle(userdata->extcap_stderr_rd), buffer, STDERR_BUFFER_SIZE + 1); if (strlen(buffer) > 0) { userdata->extcap_stderr = g_strdup_printf("%s", buffer); |