Wireshark-bugs: [Wireshark-bugs] [Bug 2592] Ctrl-C does not stop "dumpcap -S"

Date: Thu, 19 Jun 2008 16:42:42 -0700 (PDT)
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=2592


Guy Harris <guy@xxxxxxxxxxxx> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|PC                          |All




--- Comment #2 from Guy Harris <guy@xxxxxxxxxxxx>  2008-06-19 16:42:41 PDT ---
CTRL_LOGOFF_EVENT is not what's delivered for control-C; CTRL_C_EVENT is.  On a
^C, capture_cleanup() should be called with dwCtrlType being CTRL_C_EVENT, in
which case it should call capture_loop_stop() and return TRUE.

capture_loop_stop()

    1) sets ld.go to FALSE

and

    2) calls pcap_breakloop(ld.pcap_h) if ld.pcap_h is non-null.

2) doesn't cause any blocking calls trying to read captured packets to return
(there aren't any mechanisms in the low-level packet capture mechanisms to do
so).

On UN*X, the SIGINT should interrupt those reads (as we haven't set the
SA_RESTART flag for the signal), and they should return with EINTR, so that
should be sufficient to break out of a loop inside libpcap.

That doesn't happen on Windows - *however*, on Windows, a read waiting for
packets to arrive won't wait forever, it'll finish after the timeout expires
even if no packets have arrived, so the read will eventually finish.

In either case, pcap_breakloop() should set a flag in the pcap_t structure so
that the routine being used to read packets - pcap_dispatch() or
pcap_next_ex(), in the case of dumpcap - will not keep reading, but will return
an "interrupted" value, and capture_loop_dispatch() should also stop reading
packets and should set ld->go to FALSE.

So the problem is somewhere else - and, in fact, on at least one UN*X (Mac OS
X), ^C doesn't stop "dumpcap -S", either, which further indicates that the
problem is somewhere else.

In fact, the problem is in capture_opts_print_statistics(), which has the
comment

    /* XXX - Add signal handling? */

on its main loop.  That means that it just loops forever, *without even reading
any captured packets* (all it wants are statistics; the packets arrive in the
buffer until the buffer fills up, and all packets that arrive after that are
discarded).

It *also* loops forever without checking for any end condition, so it just
keeps looping.

The fact that capture_opts_print_statistics() is in capture_opts.c is probably
a relic from before we did *all* capture stuff in dumpcap.c; it has nothing to
do with command-line options, so it should probably be moved into dumpcap.c and
made to honor

    1) a -1 return, with errno set to EINTR, from sleep()

and

    2) ld.go being set to FALSE

so that it quits when the capture loop is stopped.


-- 
Configure bugmail: https://bugs.wireshark.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.