diff options
author | Gerald Combs <gerald@wireshark.org> | 2017-12-11 14:41:58 -0800 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2017-12-11 23:29:00 +0000 |
commit | 34b62c60bfad56275dca48242c7e477f33b691ef (patch) | |
tree | 3370b3a9df2ce98d09a75419da725f3e97fb8b11 /ui | |
parent | 10e98462520b5dcfa1e5d7b80e53a95725d91d94 (diff) |
Revert "Move fill_in_local_interfaces to a thread."
Calling scan_local_interfaces ends up calling fork via extcap. Doing so
from a thread is ill-adivsed:
https://rachelbythebay.com/w/2014/08/16/forkenv/
http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them
This reverts commit 5b4894b7959f44e077f36194c490cbf402e1e659.
Revert "fix compilation without pcap." as well.
This reverts commit 51300b3c834a3877d567fb57ae78ec74ec8ba80d.
Change-Id: Ic80582b52398c44af73c6d74dbb3216c4d1b37fc
Reviewed-on: https://code.wireshark.org/review/24772
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/capture_globals.h | 17 | ||||
-rw-r--r-- | ui/commandline.c | 16 | ||||
-rw-r--r-- | ui/gtk/main.c | 5 | ||||
-rw-r--r-- | ui/gtk/main_welcome.c | 1 | ||||
-rw-r--r-- | ui/iface_lists.c | 71 | ||||
-rw-r--r-- | ui/iface_lists.h | 35 |
6 files changed, 77 insertions, 68 deletions
diff --git a/ui/capture_globals.h b/ui/capture_globals.h index e71f29ade4..916bd37516 100644 --- a/ui/capture_globals.h +++ b/ui/capture_globals.h @@ -5,7 +5,19 @@ * By Gerald Combs <gerald@wireshark.org> * Copyright 1998 Gerald Combs * - * SPDX-License-Identifier: GPL-2.0+ + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __CAPTURE_GLOBALS_H__ @@ -17,10 +29,7 @@ extern "C" { #endif /* __cplusplus */ -// This should probably be behind an API. extern capture_options global_capture_opts; -// Should this be an element of capture_options? -extern GMutex global_capture_opts_mtx; #ifdef __cplusplus } diff --git a/ui/commandline.c b/ui/commandline.c index f891fef5d0..8d81c8d1a9 100644 --- a/ui/commandline.c +++ b/ui/commandline.c @@ -5,7 +5,19 @@ * By Gerald Combs <gerald@wireshark.org> * Copyright 1998 Gerald Combs * - * SPDX-License-Identifier: GPL-2.0+ + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" @@ -54,8 +66,6 @@ commandline_param_info_t global_commandline_info; #if defined(HAVE_LIBPCAP) || defined(HAVE_EXTCAP) capture_options global_capture_opts; -// Initialized in fill_in_local_interfaces_start. -GMutex global_capture_opts_mtx; #endif void diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 2153a22a38..075f4995bf 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -2172,7 +2172,6 @@ main(int argc, char *argv[]) capture_session_init(&global_capture_session, &cfile); #endif - fill_in_local_interfaces_start(); init_report_message(vfailure_alert_box, vwarning_alert_box, open_failure_alert_box, read_failure_alert_box, @@ -2275,8 +2274,7 @@ main(int argc, char *argv[]) #ifdef HAVE_LIBPCAP splash_update(RA_INTERFACES, NULL, (gpointer)splash_win); - fill_in_local_interfaces_wait(main_window_update); - g_mutex_lock(&global_capture_opts_mtx); + fill_in_local_interfaces(main_window_update); if (global_commandline_info.list_link_layer_types) caps_queries |= CAPS_QUERY_LINK_TYPES; @@ -2613,7 +2611,6 @@ main(int argc, char *argv[]) if (!global_commandline_info.start_capture && !global_capture_opts.default_options.cfilter) { global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter()); } - g_mutex_unlock(&global_capture_opts_mtx); #else /* HAVE_LIBPCAP */ show_main_window(FALSE); check_and_warn_user_startup(global_commandline_info.cf_name); diff --git a/ui/gtk/main_welcome.c b/ui/gtk/main_welcome.c index 972552671d..8ab92a6f4a 100644 --- a/ui/gtk/main_welcome.c +++ b/ui/gtk/main_welcome.c @@ -1276,6 +1276,7 @@ welcome_new(void) g_object_set_data(G_OBJECT(welcome_hb), CAPTURE_VIEW, topic_capture_to_fill); #ifdef HAVE_LIBPCAP + fill_in_local_interfaces(main_window_update); fill_capture_box(); /* capture help topic */ diff --git a/ui/iface_lists.c b/ui/iface_lists.c index 965bb3f45b..a1b66745f1 100644 --- a/ui/iface_lists.c +++ b/ui/iface_lists.c @@ -6,7 +6,19 @@ * By Gerald Combs <gerald@wireshark.org> * Copyright 1998 Gerald Combs * - * SPDX-License-Identifier: GPL-2.0+ + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" @@ -101,14 +113,18 @@ scan_local_interfaces(void (*update_cb)(void)) GString *ip_str; interface_options *interface_opts; gboolean found = FALSE; + static gboolean running = FALSE; GHashTable *selected_devices; - /* scan_local_interfaces internally calls update_cb to process UI events - to avoid stuck UI while running possibly slow operations. A side effect - of this is that new interface changes can be detected before completing - the last one. - This return avoids recursive scan_local_interfaces operation. */ - if (!g_mutex_trylock(&global_capture_opts_mtx)) return; + if (running) { + /* scan_local_interfaces internally calls update_cb to process UI events + to avoid stuck UI while running possibly slow operations. A side effect + of this is that new interface changes can be detected before completing + the last one. + This return avoids recursive scan_local_interfaces operation. */ + return; + } + running = TRUE; /* * Clear list of known interfaces (all_ifaces) that will be re-discovered on @@ -375,21 +391,16 @@ scan_local_interfaces(void (*update_cb)(void)) } g_hash_table_destroy(selected_devices); - g_mutex_unlock(&global_capture_opts_mtx); + running = FALSE; } -// XXX Copied from register.c -#define CB_WAIT_TIME (150 * 1000) // microseconds -static GThread *local_if_thread; -static GAsyncQueue *local_interface_done_q; - /* * Get the global interface list. Generate it if we haven't done so * already. This can be quite time consuming the first time, so * record how long it takes in the info log. */ -static void * -fill_in_local_interfaces_worker(void *arg _U_) +void +fill_in_local_interfaces(void(*update_cb)(void)) { GTimeVal start_time; GTimeVal end_time; @@ -402,7 +413,7 @@ fill_in_local_interfaces_worker(void *arg _U_) if (!initialized) { /* do the actual work */ - scan_local_interfaces(NULL); + scan_local_interfaces(update_cb); initialized = TRUE; } /* log how long it took */ @@ -411,34 +422,6 @@ fill_in_local_interfaces_worker(void *arg _U_) ((end_time.tv_usec - start_time.tv_usec) / 1e6)); g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "fill_in_local_interfaces() ends, taking %.3fs", elapsed); - g_async_queue_push(local_interface_done_q, GINT_TO_POINTER(TRUE)); - return NULL; -} -#endif - -#if defined(HAVE_LIBPCAP) || defined(HAVE_EXTCAP) -void -fill_in_local_interfaces_start(void) -{ -#ifdef HAVE_LIBPCAP - if (!local_interface_done_q) { - g_mutex_init(&global_capture_opts_mtx); - local_interface_done_q = g_async_queue_new(); - } - local_if_thread = g_thread_new("fill_in_local_interfaces_worker", &fill_in_local_interfaces_worker, NULL); -#endif -} -#endif - -#ifdef HAVE_LIBPCAP -void -fill_in_local_interfaces_wait(void(*update_cb)(void)) -{ - while (!g_async_queue_timeout_pop(local_interface_done_q, CB_WAIT_TIME)) { - update_cb(); - } - g_thread_join(local_if_thread); - local_if_thread = NULL; } void diff --git a/ui/iface_lists.h b/ui/iface_lists.h index a0cfe624df..0c40f02f17 100644 --- a/ui/iface_lists.h +++ b/ui/iface_lists.h @@ -2,7 +2,23 @@ * Declarations of routines to manage the global list of interfaces and to * update widgets/windows displaying items from those lists * - * SPDX-License-Identifier: GPL-2.0+ + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __IFACE_LISTS_H__ @@ -12,14 +28,6 @@ extern "C" { #endif /* __cplusplus */ -#if defined(HAVE_LIBPCAP) || defined(HAVE_EXTCAP) -/* - * Update the global interface list in the background. Create it if we - * haven't done so already. - */ -extern void fill_in_local_interfaces_start(void); -#endif - #ifdef HAVE_LIBPCAP /* * Used when sorting an interface list into alphabetical order by @@ -28,14 +36,15 @@ extern void fill_in_local_interfaces_start(void); extern gint if_list_comparator_alph(const void *first_arg, const void *second_arg); /* - * Update the global interface list in the foreground. + * Get the global interface list. Generate it if we haven't + * done so already. */ -extern void scan_local_interfaces(void (*update_cb)(void)); +extern void fill_in_local_interfaces(void(*update_cb)(void)); /* - * Wait for the global interface list creation to finish. + * Update the global interface list. */ -extern void fill_in_local_interfaces_wait(void(*update_cb)(void)); +extern void scan_local_interfaces(void (*update_cb)(void)); /* * Hide the interfaces |