aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2019-09-04 13:51:29 +0200
committerAnders Broman <a.broman58@gmail.com>2019-09-04 12:31:53 +0000
commit98cda1bf46fb262dbfd1865cf131a23504a41cec (patch)
tree9dba36fdaf4f3c885760ace24c2e76c7b00e70d6
parentf2162a1005328a4921367cc52b767f7629944330 (diff)
Load environment vars to globals for efficency.
These environment variables are read very frequently, read them once to globals for performance improvment. Change-Id: I4f05a5edca85b370674cc5f85fce40bd1af695cb Reviewed-on: https://code.wireshark.org/review/34449 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--epan/capture_dissectors.c2
-rw-r--r--epan/dissectors/packet-rpc.c4
-rw-r--r--epan/epan.c22
-rw-r--r--epan/epan.h10
-rw-r--r--epan/expert.c2
-rw-r--r--epan/packet.c26
-rw-r--r--epan/proto.c4
7 files changed, 49 insertions, 21 deletions
diff --git a/epan/capture_dissectors.c b/epan/capture_dissectors.c
index f364a9f3aa..4afb11d8b2 100644
--- a/epan/capture_dissectors.c
+++ b/epan/capture_dissectors.c
@@ -122,7 +122,7 @@ void capture_dissector_add_uint(const char *name, const guint32 pattern, capture
sub_dissectors = (struct capture_dissector_table*)g_hash_table_lookup( capture_dissector_tables, name );
if (sub_dissectors == NULL) {
fprintf(stderr, "OOPS: Subdissector \"%s\" not found in capture_dissector_tables\n", name);
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
diff --git a/epan/dissectors/packet-rpc.c b/epan/dissectors/packet-rpc.c
index f936059408..cd084cbdf3 100644
--- a/epan/dissectors/packet-rpc.c
+++ b/epan/dissectors/packet-rpc.c
@@ -557,7 +557,7 @@ rpc_init_prog(int proto, guint32 prog, int ett, size_t nvers,
proc->strptr);
/* Abort out if desired - but don't throw an exception here! */
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
REPORT_DISSECTOR_BUG("RPC: No call handler!");
continue;
@@ -572,7 +572,7 @@ rpc_init_prog(int proto, guint32 prog, int ett, size_t nvers,
proc->strptr);
/* Abort out if desired - but don't throw an exception here! */
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
REPORT_DISSECTOR_BUG("RPC: No reply handler!");
continue;
diff --git a/epan/epan.c b/epan/epan.c
index cc4327d270..f06d4c0ea6 100644
--- a/epan/epan.c
+++ b/epan/epan.c
@@ -98,6 +98,12 @@ static GSList *epan_plugin_register_all_handoffs = NULL;
static wmem_allocator_t *pinfo_pool_cache = NULL;
+/* Global variables holding the content of the corresponding environment variable
+ * to save fetching it repeatedly.
+ */
+gboolean wireshark_abort_on_dissector_bug = FALSE;
+gboolean wireshark_abort_on_too_many_items = FALSE;
+
#ifdef HAVE_PLUGINS
plugins_t *libwireshark_plugins = NULL;
static GSList *epan_plugins = NULL;
@@ -192,6 +198,22 @@ epan_init(register_cb cb, gpointer client_data, gboolean load_plugins)
{
volatile gboolean status = TRUE;
+ /* Get the value of some environment variables and set corresponding globals for performance reasons*/
+ /* If the WIRESHARK_ABORT_ON_DISSECTOR_BUG environment variable is set,
+ * it will call abort(), instead, to make it easier to get a stack trace.
+ */
+ if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL) {
+ wireshark_abort_on_dissector_bug = TRUE;
+ } else {
+ wireshark_abort_on_dissector_bug = FALSE;
+ }
+
+ if (getenv("WIRESHARK_ABORT_ON_TOO_MANY_ITEMS") != NULL) {
+ wireshark_abort_on_too_many_items = TRUE;
+ } else {
+ wireshark_abort_on_too_many_items = FALSE;
+ }
+
/*
* proto_init -> register_all_protocols -> g_async_queue_new which
* requires threads to be initialized. This happens automatically with
diff --git a/epan/epan.h b/epan/epan.h
index 217886eb84..61a217ca44 100644
--- a/epan/epan.h
+++ b/epan/epan.h
@@ -22,12 +22,18 @@ extern "C" {
#include <epan/register.h>
#include "ws_symbol_export.h"
+
+/** Global variable holding the content of the corresponding environment variable
+ * to save fetching it repeatedly.
+ */
+extern gboolean wireshark_abort_on_dissector_bug;
+
typedef struct epan_dissect epan_dissect_t;
struct epan_dfilter;
struct epan_column_info;
-/*
+/**
* Opaque structure provided when an epan_t is created; it contains
* information needed to allow the user of libwireshark to provide
* time stamps, comments, and other information outside the packet
@@ -35,7 +41,7 @@ struct epan_column_info;
*/
struct packet_provider_data;
-/*
+/**
* Structure containing pointers to functions supplied by the user
* of libwireshark.
*/
diff --git a/epan/expert.c b/epan/expert.c
index 40c024d0b8..a916f4834f 100644
--- a/epan/expert.c
+++ b/epan/expert.c
@@ -174,7 +174,7 @@ static void uat_expert_post_update_cb(void)
}
#define EXPERT_REGISTRAR_GET_NTH(eiindex, expinfo) \
- if((guint)eiindex >= gpa_expertinfo.len && getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG")) \
+ if((guint)eiindex >= gpa_expertinfo.len && wireshark_abort_on_dissector_bug) \
g_error("Unregistered expert info! index=%d", eiindex); \
DISSECTOR_ASSERT_HINT((guint)eiindex < gpa_expertinfo.len, "Unregistered expert info!"); \
DISSECTOR_ASSERT_HINT(gpa_expertinfo.ei[eiindex] != NULL, "Unregistered expert info!"); \
diff --git a/epan/packet.c b/epan/packet.c
index 84878a8b2c..64b2da5935 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -1023,7 +1023,7 @@ dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t h
if (handle == NULL) {
fprintf(stderr, "OOPS: handle to register \"%s\" to doesn't exist\n",
name);
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -1032,7 +1032,7 @@ dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t h
name);
fprintf(stderr, "Protocol being registered is \"%s\"\n",
proto_get_protocol_long_name(handle->protocol));
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -1506,7 +1506,7 @@ dissector_add_string(const char *name, const gchar *pattern,
if (handle == NULL) {
fprintf(stderr, "OOPS: handle to register \"%s\" to doesn't exist\n",
name);
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -1515,7 +1515,7 @@ dissector_add_string(const char *name, const gchar *pattern,
name);
fprintf(stderr, "Protocol being registered is \"%s\"\n",
proto_get_protocol_long_name(handle->protocol));
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -1768,7 +1768,7 @@ void dissector_add_custom_table_handle(const char *name, void *pattern, dissecto
if (handle == NULL) {
fprintf(stderr, "OOPS: handle to register \"%s\" to doesn't exist\n",
name);
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -1777,7 +1777,7 @@ void dissector_add_custom_table_handle(const char *name, void *pattern, dissecto
name);
fprintf(stderr, "Protocol being registered is \"%s\"\n",
proto_get_protocol_long_name(handle->protocol));
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -1824,7 +1824,7 @@ void dissector_add_guid(const char *name, guid_key* guid_val, dissector_handle_t
if (handle == NULL) {
fprintf(stderr, "OOPS: handle to register \"%s\" to doesn't exist\n",
name);
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -1833,7 +1833,7 @@ void dissector_add_guid(const char *name, guid_key* guid_val, dissector_handle_t
name);
fprintf(stderr, "Protocol being registered is \"%s\"\n",
proto_get_protocol_long_name(handle->protocol));
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -2019,7 +2019,7 @@ dissector_add_for_decode_as(const char *name, dissector_handle_t handle)
name);
fprintf(stderr, "Protocol being registered is \"%s\"\n",
proto_get_protocol_long_name(handle->protocol));
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -2037,7 +2037,7 @@ dissector_add_for_decode_as(const char *name, dissector_handle_t handle)
dissector_name,
proto_get_protocol_short_name(handle->protocol),
name);
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -2081,7 +2081,7 @@ dissector_add_for_decode_as(const char *name, dissector_handle_t handle)
dissector_name, dup_dissector_name,
proto_get_protocol_short_name(handle->protocol),
name);
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
}
}
@@ -2621,7 +2621,7 @@ heur_dissector_add(const char *name, heur_dissector_t dissector, const char *dis
fprintf(stderr, "Protocol being registered is \"%s\"\n",
proto_name);
}
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
@@ -2640,7 +2640,7 @@ heur_dissector_add(const char *name, heur_dissector_t dissector, const char *dis
fprintf(stderr, "Protocol %s is already registered in \"%s\" table\n",
proto_name, name);
}
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
+ if (wireshark_abort_on_dissector_bug)
abort();
return;
}
diff --git a/epan/proto.c b/epan/proto.c
index 29d8e223d7..72b17bbb49 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -363,7 +363,7 @@ static GHashTable* prefixes = NULL;
wmem_free(pool, il);
#define PROTO_REGISTRAR_GET_NTH(hfindex, hfinfo) \
- if((guint)hfindex >= gpa_hfinfo.len && getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG")) \
+ if((guint)hfindex >= gpa_hfinfo.len && wireshark_abort_on_dissector_bug) \
g_error("Unregistered hf! index=%d", hfindex); \
DISSECTOR_ASSERT_HINT((guint)hfindex < gpa_hfinfo.len, "Unregistered hf!"); \
DISSECTOR_ASSERT_HINT(gpa_hfinfo.hfi[hfindex] != NULL, "Unregistered hf!"); \
@@ -1454,7 +1454,7 @@ void proto_report_dissector_bug(const char *format, ...)
{
va_list args;
- if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL) {
+ if (wireshark_abort_on_dissector_bug) {
/*
* Try to have the error message show up in the crash
* information.