aboutsummaryrefslogtreecommitdiffstats
path: root/capchild
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-12-23 00:05:21 -0800
committerGuy Harris <guy@alum.mit.edu>2017-12-23 20:43:32 +0000
commit6a949ed1556f239a84a7ccb8d3b207f99cdf71c8 (patch)
treee4e4ab558e3c6465f6906a6382859152492c040f /capchild
parent13a9c636a52ae2c6e2bc2070f4a4f047afe6a6ef (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 'capchild')
-rw-r--r--capchild/capture_sync.c41
1 files changed, 8 insertions, 33 deletions
diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c
index e8d6fcf10b..43fc2ac173 100644
--- a/capchild/capture_sync.c
+++ b/capchild/capture_sync.c
@@ -100,7 +100,7 @@
#include <process.h> /* For spawning child process */
#endif
-
+#include <wsutil/ws_pipe.h>
#ifdef _WIN32
static void create_dummy_signal_pipe();
@@ -1524,37 +1524,12 @@ pipe_read_bytes(int pipe_fd, char *bytes, int required, char **msg)
return offset;
}
-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
-}
-
-/* Read a line from a pipe, similar to fgets */
+/*
+ * Read a line from a pipe; similar to fgets, but doesn't block.
+ *
+ * XXX - just stops reading if there's nothing to be read right now;
+ * that could conceivably mean that you don't get a complete line.
+ */
int
sync_pipe_gets_nonblock(int pipe_fd, char *bytes, int max) {
ssize_t newly;
@@ -1562,7 +1537,7 @@ sync_pipe_gets_nonblock(int pipe_fd, char *bytes, int max) {
while(offset < max - 1) {
offset++;
- if (! pipe_data_available(pipe_fd))
+ if (! ws_pipe_data_available(pipe_fd))
break;
newly = ws_read(pipe_fd, &bytes[offset], 1);
if (newly == 0) {