From 38e3976db873bd65bf52a7c266c14792fe7c874c Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sun, 1 Feb 2015 14:52:27 +0100 Subject: [PATCH] Add org.freedesktop.DBus.Verbose interface to dbus-daemon when compiled with DBUS_ENABLE_VERBOSE_MODE. This interface contains methods 'EnableVerbose' and 'DisableVerbose' to control verbose mode on daemon runtime. --- bus/driver.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ dbus/dbus-internals.c | 10 +++++++ dbus/dbus-internals.h | 2 ++ dbus/dbus-shared.h | 2 ++ 4 files changed, 91 insertions(+) diff --git a/bus/driver.c b/bus/driver.c index e82602b..603504f 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -1770,6 +1770,72 @@ bus_driver_handle_reload_config (DBusConnection *connection, return FALSE; } +#ifdef DBUS_ENABLE_VERBOSE_MODE +static dbus_bool_t +bus_driver_handle_enable_verbose (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply = NULL; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + _dbus_set_verbose(TRUE); + + dbus_message_unref (reply); + return TRUE; + + oom: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + BUS_SET_OOM (error); + + if (reply) + dbus_message_unref (reply); + return FALSE; +} + +static dbus_bool_t +bus_driver_handle_disable_verbose (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply = NULL; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + goto oom; + + if (! bus_transaction_send_from_driver (transaction, connection, reply)) + goto oom; + + _dbus_set_verbose(FALSE); + + dbus_message_unref (reply); + return TRUE; + + oom: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + BUS_SET_OOM (error); + + if (reply) + dbus_message_unref (reply); + return FALSE; +} +#endif + static dbus_bool_t bus_driver_handle_get_id (DBusConnection *connection, BusTransaction *transaction, @@ -2042,6 +2108,14 @@ static const MessageHandler monitoring_message_handlers[] = { { NULL, NULL, NULL, NULL } }; +#ifdef DBUS_ENABLE_VERBOSE_MODE +static const MessageHandler verbose_message_handlers[] = { + { "EnableVerbose", "", "", bus_driver_handle_enable_verbose}, + { "DisableVerbose", "", "", bus_driver_handle_disable_verbose}, + { NULL, NULL, NULL, NULL } +}; +#endif + #ifdef DBUS_ENABLE_STATS static const MessageHandler stats_message_handlers[] = { { "GetStats", "", "a{sv}", bus_stats_handle_get_stats }, @@ -2074,6 +2148,9 @@ static InterfaceHandler interface_handlers[] = { " \n" }, { DBUS_INTERFACE_INTROSPECTABLE, introspectable_message_handlers, NULL }, { DBUS_INTERFACE_MONITORING, monitoring_message_handlers, NULL }, +#ifdef DBUS_ENABLE_VERBOSE_MODE + { DBUS_INTERFACE_VERBOSE, verbose_message_handlers, NULL }, +#endif #ifdef DBUS_ENABLE_STATS { BUS_INTERFACE_STATS, stats_message_handlers, NULL }, #endif diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 575a087..92a108c 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -363,6 +363,16 @@ _dbus_is_verbose_real (void) return verbose; } +void _dbus_set_verbose (dbus_bool_t state) +{ + verbose = state; +} + +dbus_bool_t _dbus_get_verbose (void) +{ + return verbose; +} + /** * Prints a warning message to stderr * if the user has enabled verbose mode. diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 6b487f5..8dea10f 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -99,6 +99,8 @@ void _dbus_verbose_real (const char *format, #endif void _dbus_verbose_reset_real (void); dbus_bool_t _dbus_is_verbose_real (void); +dbus_bool_t _dbus_get_verbose (void); +void _dbus_set_verbose (dbus_bool_t state); # define _dbus_verbose_reset _dbus_verbose_reset_real # define _dbus_is_verbose _dbus_is_verbose_real diff --git a/dbus/dbus-shared.h b/dbus/dbus-shared.h index 51c3da8..7ab9103 100644 --- a/dbus/dbus-shared.h +++ b/dbus/dbus-shared.h @@ -89,6 +89,8 @@ typedef enum /** The monitoring interface exported by the dbus-daemon */ #define DBUS_INTERFACE_MONITORING "org.freedesktop.DBus.Monitoring" +/** The verbose interface exported by the dbus-daemon */ +#define DBUS_INTERFACE_VERBOSE "org.freedesktop.DBus.Verbose" /** The interface supported by introspectable objects */ #define DBUS_INTERFACE_INTROSPECTABLE "org.freedesktop.DBus.Introspectable" /** The interface supported by objects with properties */ -- 1.8.4.5