From abfa0d6218108a14898778b7142c55a27d42b298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Thu, 7 Nov 2019 11:35:47 +0000 Subject: [PATCH] Qt: Keep extcap control channels when capturing to multiple files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using the "Create a new file automatically" feature the capture in Wireshark will stop and start, but the extcap utility will continue run as normal. Ensure the control channels are kept when doing this. Rename the unused capture_session.session_started to session_will_restart to detect this. Bug: 16178 Change-Id: I6797c982760a1013fca2a24699befff1dc82f28c Reviewed-on: https://code.wireshark.org/review/35013 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall --- capchild/capture_session.h | 2 +- capchild/capture_sync.c | 2 +- ui/capture.c | 2 ++ ui/qt/main_window.cpp | 16 +++++++++------- ui/qt/main_window.h | 2 +- ui/qt/main_window_slots.cpp | 11 +++++++---- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/capchild/capture_session.h b/capchild/capture_session.h index 93ddabb147..eb99a2d556 100644 --- a/capchild/capture_session.h +++ b/capchild/capture_session.h @@ -48,7 +48,7 @@ typedef struct _capture_session { uid_t owner; /**< owner of the cfile */ gid_t group; /**< group of the cfile */ #endif - gboolean session_started; + gboolean session_will_restart; /**< Set when session will restart */ guint32 count; /**< Total number of frames captured */ capture_options *capture_opts; /**< options for this capture */ capture_file *cf; /**< handle to cfile */ diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c index d2ed2ee75a..ca59d9711e 100644 --- a/capchild/capture_sync.c +++ b/capchild/capture_sync.c @@ -128,7 +128,7 @@ capture_session_init(capture_session *cap_session, capture_file *cf) cap_session->group = getgid(); #endif cap_session->count = 0; - cap_session->session_started = FALSE; + cap_session->session_will_restart = FALSE; } /* Append an arg (realloc) to an argc/argv array */ diff --git a/ui/capture.c b/ui/capture.c index 24ea06b59d..e8390b08db 100644 --- a/ui/capture.c +++ b/ui/capture.c @@ -414,6 +414,7 @@ capture_input_new_file(capture_session *cap_session, gchar *new_file) /* (we can only have an open capture file in real_time_mode!) */ if( ((capture_file *) cap_session->cf)->state != FILE_CLOSED) { if(capture_opts->real_time_mode) { + cap_session->session_will_restart = TRUE; capture_callback_invoke(capture_cb_capture_update_finished, cap_session); cf_finish_tail((capture_file *)cap_session->cf, &cap_session->rec, &cap_session->buf, &err); @@ -714,6 +715,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg) /* Tell the GUI we are not doing a capture any more. Must be done after the cf_finish_tail(), so file lengths are correctly displayed */ + cap_session->session_will_restart = FALSE; capture_callback_invoke(capture_cb_capture_update_finished, cap_session); /* Finish the capture. */ diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 7ab32b55ec..dc63107dd7 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -2517,7 +2517,7 @@ void MainWindow::changeEvent(QEvent* event) } /* Update main window items based on whether there's a capture in progress. */ -void MainWindow::setForCaptureInProgress(bool capture_in_progress, GArray *ifaces) +void MainWindow::setForCaptureInProgress(bool capture_in_progress, bool handle_toolbars, GArray *ifaces) { setMenusForCaptureInProgress(capture_in_progress); @@ -2532,12 +2532,14 @@ void MainWindow::setForCaptureInProgress(bool capture_in_progress, GArray *iface // set_capture_if_dialog_for_capture_in_progress(capture_in_progress); #endif - QList toolbars = findChildren(); - foreach(InterfaceToolbar *toolbar, toolbars) { - if (capture_in_progress) { - toolbar->startCapture(ifaces); - } else { - toolbar->stopCapture(); + if (handle_toolbars) { + QList toolbars = findChildren(); + foreach(InterfaceToolbar *toolbar, toolbars) { + if (capture_in_progress) { + toolbar->startCapture(ifaces); + } else { + toolbar->stopCapture(); + } } } } diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 60f145f20e..72a10fe7fa 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -268,7 +268,7 @@ private: void externalMenuHelper(ext_menu_t * menu, QMenu * subMenu, gint depth); - void setForCaptureInProgress(bool capture_in_progress = false, GArray *ifaces = NULL); + void setForCaptureInProgress(bool capture_in_progress = false, bool handle_toolbars = false, GArray *ifaces = NULL); QMenu* findOrAddMenu(QMenu *parent_menu, QString& menu_text); void captureFileReadStarted(const QString &action); diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index c0b8ce0247..e6bda8ab85 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -501,7 +501,8 @@ void MainWindow::captureCapturePrepared(capture_session *session) { /* Disable menu items that make no sense if you're currently running a capture. */ - setForCaptureInProgress(true, session->capture_opts->ifaces); + bool handle_toolbars = (session->session_will_restart ? false : true); + setForCaptureInProgress(true, handle_toolbars, session->capture_opts->ifaces); // set_capture_if_dialog_for_capture_in_progress(TRUE); // /* Don't set up main window for a capture file. */ @@ -515,12 +516,13 @@ void MainWindow::captureCaptureUpdateStarted(capture_session *session) { switching to the next multiple file. */ setTitlebarForCaptureInProgress(); - setForCaptureInProgress(true, session->capture_opts->ifaces); + bool handle_toolbars = (session->session_will_restart ? false : true); + setForCaptureInProgress(true, handle_toolbars, session->capture_opts->ifaces); setForCapturedPackets(true); } -void MainWindow::captureCaptureUpdateFinished(capture_session *) { +void MainWindow::captureCaptureUpdateFinished(capture_session *session) { /* The capture isn't stopping any more - it's stopped. */ capture_stopping_ = false; @@ -530,7 +532,8 @@ void MainWindow::captureCaptureUpdateFinished(capture_session *) { /* Enable menu items that make sense if you're not currently running a capture. */ - setForCaptureInProgress(false); + bool handle_toolbars = (session->session_will_restart ? false : true); + setForCaptureInProgress(false, handle_toolbars); setMenusForCaptureFile(); setWindowIcon(wsApp->normalIcon());