[systemd-devel] [PATCH] bus: Add support for eavesdrop in sd_bus_add_match()

Lukasz Skalski l.skalski at partner.samsung.com
Thu Dec 12 04:09:41 PST 2013


Due to this patch, 'busctl monitor' prints all method calls,
method errors and signals both for dbus and kdbus.
---
 src/libsystemd-bus/bus-control.c |  6 ++++++
 src/libsystemd-bus/bus-match.c   | 10 ++++++++++
 src/libsystemd-bus/bus-match.h   |  1 +
 src/libsystemd-bus/busctl.c      |  2 +-
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 2682439..525e452 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -958,6 +958,12 @@ static int bus_add_match_internal_kernel(
                         }
                         break;
 
+                case BUS_MATCH_EAVESDROP:
+                        if (streq(c->value_str, "true")) {
+                                bus_kernel_monitor(bus);
+                        }
+                        break;
+
                 case BUS_MATCH_ARG...BUS_MATCH_ARG_LAST: {
                         char buf[sizeof("arg")-1 + 2 + 1];
 
diff --git a/src/libsystemd-bus/bus-match.c b/src/libsystemd-bus/bus-match.c
index f7fca5f..3da401c 100644
--- a/src/libsystemd-bus/bus-match.c
+++ b/src/libsystemd-bus/bus-match.c
@@ -163,6 +163,7 @@ static bool value_node_test(
         case BUS_MATCH_INTERFACE:
         case BUS_MATCH_MEMBER:
         case BUS_MATCH_PATH:
+        case BUS_MATCH_EAVESDROP:
         case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
                 return streq_ptr(node->value.str, value_str);
 
@@ -203,6 +204,7 @@ static bool value_node_same(
         case BUS_MATCH_INTERFACE:
         case BUS_MATCH_MEMBER:
         case BUS_MATCH_PATH:
+        case BUS_MATCH_EAVESDROP:
         case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
         case BUS_MATCH_ARG_NAMESPACE ... BUS_MATCH_ARG_NAMESPACE_LAST:
         case BUS_MATCH_PATH_NAMESPACE:
@@ -310,6 +312,9 @@ int bus_match_run(
                 test_str = m->path;
                 break;
 
+        case BUS_MATCH_EAVESDROP:
+                break;
+
         case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
                 test_str = bus_message_get_arg(m, node->type - BUS_MATCH_ARG);
                 break;
@@ -590,6 +595,8 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
                 return BUS_MATCH_PATH;
         if (n == 14 && startswith(k, "path_namespace"))
                 return BUS_MATCH_PATH_NAMESPACE;
+        if (n == 9 && startswith(k, "eavesdrop"))
+                return BUS_MATCH_EAVESDROP;
 
         if (n == 4 && startswith(k, "arg")) {
                 int j;
@@ -949,6 +956,9 @@ const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[]
         case BUS_MATCH_PATH_NAMESPACE:
                 return "path_namespace";
 
+        case BUS_MATCH_EAVESDROP:
+                return "eavesdrop";
+
         case BUS_MATCH_ARG ... BUS_MATCH_ARG_LAST:
                 snprintf(buf, l, "arg%i", t - BUS_MATCH_ARG);
                 return buf;
diff --git a/src/libsystemd-bus/bus-match.h b/src/libsystemd-bus/bus-match.h
index 1d38126..17b50cb 100644
--- a/src/libsystemd-bus/bus-match.h
+++ b/src/libsystemd-bus/bus-match.h
@@ -38,6 +38,7 @@ enum bus_match_node_type {
         BUS_MATCH_MEMBER,
         BUS_MATCH_PATH,
         BUS_MATCH_PATH_NAMESPACE,
+        BUS_MATCH_EAVESDROP,
         BUS_MATCH_ARG,
         BUS_MATCH_ARG_LAST = BUS_MATCH_ARG + 63,
         BUS_MATCH_ARG_PATH,
diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c
index 57bc83d..5f86e0d 100644
--- a/src/libsystemd-bus/busctl.c
+++ b/src/libsystemd-bus/busctl.c
@@ -206,7 +206,7 @@ static int monitor(sd_bus *bus, char *argv[]) {
         }
 
         if (!added_something) {
-                r = sd_bus_add_match(bus, "", NULL, NULL);
+                r = sd_bus_add_match(bus, "eavesdrop='true'", NULL, NULL);
                 if (r < 0) {
                         log_error("Failed to add match: %s", strerror(-r));
                         return r;
-- 
1.8.3.2



More information about the systemd-devel mailing list