From 39e16fe0760e9229acc8a5bc7e72feb97a71c911 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Thu, 11 Jul 2013 16:54:42 +0800 Subject: [PATCH 01/10] Cleanup: polish verbose mode checking --- bus/selinux.c | 19 ++++----------- bus/signals.c | 59 ++++++++++++++++++---------------------------- dbus/dbus-connection.c | 11 ++------- dbus/dbus-pending-call.c | 11 ++------- 4 files changed, 32 insertions(+), 68 deletions(-) diff --git a/bus/selinux.c b/bus/selinux.c index 36287e9..57c9432 100644 --- a/bus/selinux.c +++ b/bus/selinux.c @@ -936,8 +936,7 @@ bus_selinux_get_policy_root (void) void bus_selinux_id_table_print (DBusHashTable *service_table) { -#ifdef DBUS_ENABLE_VERBOSE_MODE -#ifdef HAVE_SELINUX +#if defined (DBUS_ENABLE_VERBOSE_MODE) && defined (HAVE_SELINUX) DBusHashIter iter; if (!selinux_enabled) @@ -953,19 +952,17 @@ bus_selinux_id_table_print (DBusHashTable *service_table) _dbus_verbose ("The context is %s\n", sid->ctx); _dbus_verbose ("The refcount is %d\n", sid->refcnt); } -#endif /* HAVE_SELINUX */ -#endif /* DBUS_ENABLE_VERBOSE_MODE */ +#endif /* DBUS_ENABLE_VERBOSE_MODE && HAVE_SELINUX */ } -#ifdef DBUS_ENABLE_VERBOSE_MODE -#ifdef HAVE_SELINUX /** * Print out some AVC statistics. */ static void bus_avc_print_stats (void) { +#if defined (DBUS_ENABLE_VERBOSE_MODE) && defined (HAVE_SELINUX) struct avc_cache_stats cstats; if (!selinux_enabled) @@ -983,9 +980,8 @@ bus_avc_print_stats (void) _dbus_verbose ("CAV hits: %d\n", cstats.cav_hits); _dbus_verbose ("CAV probes: %d\n", cstats.cav_probes); _dbus_verbose ("CAV misses: %d\n", cstats.cav_misses); +#endif /* DBUS_ENABLE_VERBOSE_MODE && HAVE_SELINUX */ } -#endif /* HAVE_SELINUX */ -#endif /* DBUS_ENABLE_VERBOSE_MODE */ /** @@ -1005,12 +1001,7 @@ bus_selinux_shutdown (void) sidput (bus_sid); bus_sid = SECSID_WILD; -#ifdef DBUS_ENABLE_VERBOSE_MODE - - if (_dbus_is_verbose()) - bus_avc_print_stats (); - -#endif /* DBUS_ENABLE_VERBOSE_MODE */ + bus_avc_print_stats (); avc_destroy (); #ifdef HAVE_LIBAUDIT diff --git a/bus/signals.c b/bus/signals.c index 72487ed..e6408d3 100644 --- a/bus/signals.c +++ b/bus/signals.c @@ -118,13 +118,13 @@ bus_match_rule_unref (BusMatchRule *rule) } } -#ifdef DBUS_ENABLE_VERBOSE_MODE /* Note this function does not do escaping, so it's only * good for debug spew at the moment */ static char* match_rule_to_string (BusMatchRule *rule) { +#ifdef DBUS_ENABLE_VERBOSE_MODE DBusString str; char *ret; @@ -278,8 +278,9 @@ match_rule_to_string (BusMatchRule *rule) ; /* only OK for debug spew... */ return s; } -} #endif /* DBUS_ENABLE_VERBOSE_MODE */ + return NULL; +} dbus_bool_t bus_match_rule_set_message_type (BusMatchRule *rule, @@ -1328,6 +1329,7 @@ bus_matchmaker_add_rule (BusMatchmaker *matchmaker, BusMatchRule *rule) { DBusList **rules; + char *s; _dbus_assert (bus_connection_is_active (rule->matches_go_to)); @@ -1354,15 +1356,11 @@ bus_matchmaker_add_rule (BusMatchmaker *matchmaker, bus_match_rule_ref (rule); -#ifdef DBUS_ENABLE_VERBOSE_MODE - { - char *s = match_rule_to_string (rule); + s = match_rule_to_string (rule); - _dbus_verbose ("Added match rule %s to connection %p\n", - s, rule->matches_go_to); - dbus_free (s); - } -#endif + _dbus_verbose ("Added match rule %s to connection %p\n", + s, rule->matches_go_to); + dbus_free (s); return TRUE; } @@ -1443,19 +1441,16 @@ bus_matchmaker_remove_rule_link (DBusList **rules, DBusList *link) { BusMatchRule *rule = link->data; + char *s; bus_connection_remove_match_rule (rule->matches_go_to, rule); _dbus_list_remove_link (rules, link); -#ifdef DBUS_ENABLE_VERBOSE_MODE - { - char *s = match_rule_to_string (rule); + s = match_rule_to_string (rule); - _dbus_verbose ("Removed match rule %s for connection %p\n", - s, rule->matches_go_to); - dbus_free (s); - } -#endif + _dbus_verbose ("Removed match rule %s for connection %p\n", + s, rule->matches_go_to); + dbus_free (s); bus_match_rule_unref (rule); } @@ -1465,6 +1460,7 @@ bus_matchmaker_remove_rule (BusMatchmaker *matchmaker, BusMatchRule *rule) { DBusList **rules; + char *s; _dbus_verbose ("Removing rule with message_type %d, interface %s\n", rule->message_type, @@ -1484,15 +1480,11 @@ bus_matchmaker_remove_rule (BusMatchmaker *matchmaker, bus_matchmaker_gc_rules (matchmaker, rule->message_type, rule->interface, rules); -#ifdef DBUS_ENABLE_VERBOSE_MODE - { - char *s = match_rule_to_string (rule); + s = match_rule_to_string (rule); - _dbus_verbose ("Removed match rule %s for connection %p\n", - s, rule->matches_go_to); - dbus_free (s); - } -#endif + _dbus_verbose ("Removed match rule %s for connection %p\n", + s, rule->matches_go_to); + dbus_free (s); bus_match_rule_unref (rule); } @@ -1955,18 +1947,15 @@ get_recipients_from_list (DBusList **rules, while (link != NULL) { BusMatchRule *rule; + char *s; rule = link->data; -#ifdef DBUS_ENABLE_VERBOSE_MODE - { - char *s = match_rule_to_string (rule); + s = match_rule_to_string (rule); - _dbus_verbose ("Checking whether message matches rule %s for connection %p\n", - s, rule->matches_go_to); - dbus_free (s); - } -#endif + _dbus_verbose ("Checking whether message matches rule %s for connection %p\n", + s, rule->matches_go_to); + dbus_free (s); if (match_rule_matches (rule, sender, addressed_recipient, message, @@ -1980,12 +1969,10 @@ get_recipients_from_list (DBusList **rules, if (!_dbus_list_append (recipients_p, rule->matches_go_to)) return FALSE; } -#ifdef DBUS_ENABLE_VERBOSE_MODE else { _dbus_verbose ("Connection already receiving this message, so not adding again\n"); } -#endif /* DBUS_ENABLE_VERBOSE_MODE */ } link = _dbus_list_get_next_link (rules, link); diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 86adaa5..c2f66ea 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -203,26 +203,19 @@ * @{ */ -#ifdef DBUS_ENABLE_VERBOSE_MODE static void _dbus_connection_trace_ref (DBusConnection *connection, int old_refcount, int new_refcount, const char *why) { +#ifdef DBUS_ENABLE_VERBOSE_MODE static int enabled = -1; _dbus_trace_ref ("DBusConnection", connection, old_refcount, new_refcount, why, "DBUS_CONNECTION_TRACE", &enabled); -} -#else -#define _dbus_connection_trace_ref(c,o,n,w) \ - do \ - {\ - (void) (o); \ - (void) (n); \ - } while (0) #endif +} /** * Internal struct representing a message filter function diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c index 1604408..be53410 100644 --- a/dbus/dbus-pending-call.c +++ b/dbus/dbus-pending-call.c @@ -79,26 +79,19 @@ struct DBusPendingCall unsigned int timeout_added : 1; /**< Have added the timeout */ }; -#ifdef DBUS_ENABLE_VERBOSE_MODE static void _dbus_pending_call_trace_ref (DBusPendingCall *pending_call, int old_refcount, int new_refcount, const char *why) { +#ifdef DBUS_ENABLE_VERBOSE_MODE static int enabled = -1; _dbus_trace_ref ("DBusPendingCall", pending_call, old_refcount, new_refcount, why, "DBUS_PENDING_CALL_TRACE", &enabled); -} -#else -#define _dbus_pending_call_trace_ref(p, o, n, w) \ - do \ - {\ - (void) (o); \ - (void) (n); \ - } while (0) #endif +} static dbus_int32_t notify_user_data_slot = -1; -- 1.7.9.5