chiark / gitweb /
Prep v228: Apply more cosmetic changes found in upstream.
[elogind.git] / src / libelogind / sd-bus / bus-control.c
index 3cdce6600387e99e1cc8774dc25f69dca85b0e20..c29bf30e0b99dc1d082553a31eb5518093472787 100644 (file)
 #include <valgrind/memcheck.h>
 #endif
 
-#include <stddef.h>
 #include <errno.h>
+#include <stddef.h>
 
-#include "strv.h"
 #include "sd-bus.h"
+
+#include "alloc-util.h"
+#include "bus-bloom.h"
+#include "bus-control.h"
 #include "bus-internal.h"
 #include "bus-message.h"
-#include "bus-control.h"
-#include "bus-bloom.h"
 #include "bus-util.h"
-#include "capability.h"
+#include "capability-util.h"
+#include "stdio-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "user-util.h"
 
 _public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
         int r;
@@ -258,7 +263,7 @@ static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
         KDBUS_FOREACH(name, name_list, cmd.list_size) {
                 struct kdbus_item *item;
 
-                if ((flags & KDBUS_LIST_UNIQUE) && name->id != previous_id) {
+                if ((flags & KDBUS_LIST_UNIQUE) && name->id != previous_id && !(name->flags & KDBUS_HELLO_ACTIVATOR)) {
                         char *n;
 
                         if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0) {
@@ -976,8 +981,12 @@ static int bus_get_owner_creds_kdbus(sd_bus *bus, uint64_t mask, sd_bus_creds **
 static int bus_get_owner_creds_dbus1(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
         _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
         pid_t pid = 0;
+        bool do_label;
         int r;
-        bool do_label = bus->label && (mask & SD_BUS_CREDS_SELINUX_CONTEXT);
+
+        assert(bus);
+
+        do_label = bus->label && (mask & SD_BUS_CREDS_SELINUX_CONTEXT);
 
         /* Avoid allocating anything if we have no chance of returning useful data */
         if (!bus->ucred_valid && !do_label)
@@ -1129,7 +1138,7 @@ static int add_name_change_match(sd_bus *bus,
 
                 /* If the old name is unset or empty, then
                  * this can match against added names */
-                if (!old_owner || old_owner[0] == 0) {
+                if (isempty(old_owner)) {
                         item->type = KDBUS_ITEM_NAME_ADD;
 
                         r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
@@ -1139,7 +1148,7 @@ static int add_name_change_match(sd_bus *bus,
 
                 /* If the new name is unset or empty, then
                  * this can match against removed names */
-                if (!new_owner || new_owner[0] == 0) {
+                if (isempty(new_owner)) {
                         item->type = KDBUS_ITEM_NAME_REMOVE;
 
                         r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
@@ -1183,7 +1192,7 @@ static int add_name_change_match(sd_bus *bus,
 
                 /* If the old name is unset or empty, then this can
                  * match against added ids */
-                if (!old_owner || old_owner[0] == 0) {
+                if (isempty(old_owner)) {
                         item->type = KDBUS_ITEM_ID_ADD;
                         if (!isempty(new_owner))
                                 item->id_change.id = new_owner_id;
@@ -1195,7 +1204,7 @@ static int add_name_change_match(sd_bus *bus,
 
                 /* If thew new name is unset or empty, then this can
                  * match against removed ids */
-                if (!new_owner || new_owner[0] == 0) {
+                if (isempty(new_owner)) {
                         item->type = KDBUS_ITEM_ID_REMOVE;
                         if (!isempty(old_owner))
                                 item->id_change.id = old_owner_id;
@@ -1309,7 +1318,16 @@ int bus_add_match_internal_kernel(
                         break;
                 }
 
-                case BUS_MATCH_ARG_PATH...BUS_MATCH_ARG_PATH_LAST: {
+                case BUS_MATCH_ARG_HAS...BUS_MATCH_ARG_HAS_LAST: {
+                        char buf[sizeof("arg")-1 + 2 + sizeof("-has")];
+
+                        xsprintf(buf, "arg%i-has", c->type - BUS_MATCH_ARG_HAS);
+                        bloom_add_pair(bloom, bus->bloom_size, bus->bloom_n_hash, buf, c->value_str);
+                        using_bloom = true;
+                        break;
+                }
+
+                case BUS_MATCH_ARG_PATH...BUS_MATCH_ARG_PATH_LAST:
                         /*
                          * XXX: DBus spec defines arg[0..63]path= matching to be
                          * a two-way glob. That is, if either string is a prefix
@@ -1323,7 +1341,6 @@ int bus_add_match_internal_kernel(
                          * to properly support multiple-matches here.
                          */
                         break;
-                }
 
                 case BUS_MATCH_ARG_NAMESPACE...BUS_MATCH_ARG_NAMESPACE_LAST: {
                         char buf[sizeof("arg")-1 + 2 + sizeof("-dot-prefix")];
@@ -1334,7 +1351,7 @@ int bus_add_match_internal_kernel(
                         break;
                 }
 
-                case BUS_MATCH_DESTINATION: {
+                case BUS_MATCH_DESTINATION:
                         /*
                          * Kernel only supports matching on destination IDs, but
                          * not on destination names. So just skip the
@@ -1352,7 +1369,6 @@ int bus_add_match_internal_kernel(
                                 matches_name_change = false;
 
                         break;
-                }
 
                 case BUS_MATCH_ROOT:
                 case BUS_MATCH_VALUE: