If we're using threads, time out when reading the file header.
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 14 Jan 2010 22:45:12 +0000 (22:45 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 14 Jan 2010 22:45:12 +0000 (22:45 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@31529 f5534014-38df-0310-8fa8-9805f1628bb7

dumpcap.c

index 08fea0788e176339a436b4068c0ee82a5434bcfd..49b9766b086ee98422061bb87da27f2b4b76ef8b 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -272,7 +272,7 @@ static int need_timeout_workaround;
  * Timeout, in microseconds, for threaded reads from a pipe.
  */
 #define THREAD_READ_TIMEOUT   100
-
+#define THREAD_OPEN_TIMEOUT   (5 * 1000000)
 static char *cap_pipe_err_str;
 
 static void
@@ -825,6 +825,10 @@ static void
 cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
                  char *errmsg, int errmsgl)
 {
+#ifdef USE_THREADS
+  GTimeVal wait_time;
+  gpointer q_status;
+#endif
 #ifndef _WIN32
   struct stat pipe_stat;
   int          sel_ret;
@@ -982,8 +986,14 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
   ld->cap_pipe_bytes_to_read = sizeof(magic);
   /* We don't have to worry about cap_pipe_read_mtx here */
   g_async_queue_push(cap_pipe_pending_q, ld->cap_pipe_buf);
-  g_async_queue_pop(cap_pipe_done_q);
-  if (ld->cap_pipe_bytes_read <= 0) {
+  g_get_current_time(&wait_time);
+  g_time_val_add(&wait_time, THREAD_OPEN_TIMEOUT);
+  q_status = g_async_queue_timed_pop(cap_pipe_done_q, &wait_time);
+  if (!q_status) {
+    /* XXX - Are there more appropriate values we should use? */
+    g_snprintf(errmsg, errmsgl, "Timeout on pipe magic during open");
+    goto error;
+  } else if (ld->cap_pipe_bytes_read <= 0) {
     if (ld->cap_pipe_bytes_read == 0)
       g_snprintf(errmsg, errmsgl, "End of file on pipe magic during open");
     else
@@ -991,6 +1001,7 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
                  strerror(errno));
     goto error;
   }
+  
 #endif /* USE_THREADS */
 
   switch (magic) {
@@ -1054,8 +1065,13 @@ cap_pipe_open_live(char *pipename, struct pcap_hdr *hdr, loop_data *ld,
   ld->cap_pipe_bytes_read = 0;
   ld->cap_pipe_bytes_to_read = sizeof(struct pcap_hdr);
   g_async_queue_push(cap_pipe_pending_q, ld->cap_pipe_buf);
-  g_async_queue_pop(cap_pipe_done_q);
-  if (ld->cap_pipe_bytes_read <= 0) {
+  g_get_current_time(&wait_time);
+  g_time_val_add(&wait_time, THREAD_OPEN_TIMEOUT);
+  q_status = g_async_queue_timed_pop(cap_pipe_done_q, &wait_time);
+  if (!q_status) {
+    g_snprintf(errmsg, errmsgl, "Timeout on pipe header during open");
+    goto error;
+  } else if (ld->cap_pipe_bytes_read <= 0) {
     if (ld->cap_pipe_bytes_read == 0)
       g_snprintf(errmsg, errmsgl, "End of file on pipe header during open");
     else
@@ -1092,6 +1108,11 @@ error:
 #ifndef _WIN32
   ws_close(fd);
   ld->cap_pipe_fd = -1;
+#else
+  if (ld->cap_pipe_h != INVALID_HANDLE_VALUE) {
+    CloseHandle(ld->cap_pipe_h);
+    ld->cap_pipe_h = INVALID_HANDLE_VALUE;
+  }
 #endif
   return;