1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #ifdef HAVE_VALGRIND_MEMCHECK_H
23 #include <valgrind/memcheck.h>
31 #include "bus-internal.h"
32 #include "bus-message.h"
33 #include "bus-control.h"
34 #include "bus-bloom.h"
37 _public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
40 assert_return(bus, -EINVAL);
41 assert_return(unique, -EINVAL);
42 assert_return(!bus_pid_changed(bus), -ECHILD);
44 r = bus_ensure_running(bus);
48 *unique = bus->unique_name;
52 static int bus_request_name_kernel(sd_bus *bus, const char *name, unsigned flags) {
53 struct kdbus_cmd_name *n;
61 n = alloca0(offsetof(struct kdbus_cmd_name, name) + l + 1);
62 n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
63 kdbus_translate_request_name_flags(flags, (uint64_t *) &n->flags);
64 memcpy(n->name, name, l+1);
66 #ifdef HAVE_VALGRIND_MEMCHECK_H
67 VALGRIND_MAKE_MEM_DEFINED(n, n->size);
70 r = ioctl(bus->input_fd, KDBUS_CMD_NAME_ACQUIRE, n);
74 if (n->flags & KDBUS_NAME_IN_QUEUE)
80 static int bus_request_name_dbus1(sd_bus *bus, const char *name, unsigned flags) {
81 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
88 r = sd_bus_call_method(
90 "org.freedesktop.DBus",
92 "org.freedesktop.DBus",
102 r = sd_bus_message_read(reply, "u", &ret);
106 if (ret == BUS_NAME_ALREADY_OWNER)
108 else if (ret == BUS_NAME_EXISTS)
110 else if (ret == BUS_NAME_IN_QUEUE)
112 else if (ret == BUS_NAME_PRIMARY_OWNER)
118 _public_ int sd_bus_request_name(sd_bus *bus, const char *name, unsigned flags) {
119 assert_return(bus, -EINVAL);
120 assert_return(name, -EINVAL);
121 assert_return(bus->bus_client, -EINVAL);
122 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
123 assert_return(!bus_pid_changed(bus), -ECHILD);
124 assert_return(!(flags & ~(SD_BUS_NAME_ALLOW_REPLACEMENT|SD_BUS_NAME_REPLACE_EXISTING|SD_BUS_NAME_DO_NOT_QUEUE)), -EINVAL);
127 return bus_request_name_kernel(bus, name, flags);
129 return bus_request_name_dbus1(bus, name, flags);
132 static int bus_release_name_kernel(sd_bus *bus, const char *name) {
133 struct kdbus_cmd_name *n;
141 n = alloca0(offsetof(struct kdbus_cmd_name, name) + l + 1);
142 n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
143 memcpy(n->name, name, l+1);
145 #ifdef HAVE_VALGRIND_MEMCHECK_H
146 VALGRIND_MAKE_MEM_DEFINED(n, n->size);
148 r = ioctl(bus->input_fd, KDBUS_CMD_NAME_RELEASE, n);
155 static int bus_release_name_dbus1(sd_bus *bus, const char *name) {
156 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
163 r = sd_bus_call_method(
165 "org.freedesktop.DBus",
167 "org.freedesktop.DBus",
176 r = sd_bus_message_read(reply, "u", &ret);
179 if (ret == BUS_NAME_NON_EXISTENT)
181 if (ret == BUS_NAME_NOT_OWNER)
182 return -EADDRNOTAVAIL;
183 if (ret == BUS_NAME_RELEASED)
189 _public_ int sd_bus_release_name(sd_bus *bus, const char *name) {
190 assert_return(bus, -EINVAL);
191 assert_return(name, -EINVAL);
192 assert_return(bus->bus_client, -EINVAL);
193 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
194 assert_return(!bus_pid_changed(bus), -ECHILD);
197 return bus_release_name_kernel(bus, name);
199 return bus_release_name_dbus1(bus, name);
202 static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
203 struct kdbus_cmd_name_list cmd = {};
204 struct kdbus_name_list *name_list;
205 struct kdbus_cmd_name *name;
206 uint64_t previous_id = 0;
209 /* Caller will free half-constructed list on failure... */
213 r = ioctl(bus->input_fd, KDBUS_CMD_NAME_LIST, &cmd);
217 name_list = (struct kdbus_name_list *) ((uint8_t *) bus->kdbus_buffer + cmd.offset);
219 KDBUS_ITEM_FOREACH(name, name_list, names) {
221 if ((flags & KDBUS_NAME_LIST_UNIQUE) && name->id != previous_id) {
224 if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0)
233 previous_id = name->id;
236 if (name->size > sizeof(*name)) {
237 r = strv_extend(x, name->name);
243 r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_FREE, &cmd.offset);
250 static int bus_list_names_kernel(sd_bus *bus, char ***acquired, char ***activatable) {
251 _cleanup_strv_free_ char **x = NULL, **y = NULL;
255 r = kernel_get_list(bus, KDBUS_NAME_LIST_UNIQUE | KDBUS_NAME_LIST_NAMES, &x);
261 r = kernel_get_list(bus, KDBUS_NAME_LIST_STARTERS, &y);
277 static int bus_list_names_dbus1(sd_bus *bus, char ***acquired, char ***activatable) {
278 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
279 _cleanup_strv_free_ char **x = NULL, **y = NULL;
283 r = sd_bus_call_method(
285 "org.freedesktop.DBus",
287 "org.freedesktop.DBus",
295 r = sd_bus_message_read_strv(reply, &x);
299 reply = sd_bus_message_unref(reply);
303 r = sd_bus_call_method(
305 "org.freedesktop.DBus",
307 "org.freedesktop.DBus",
308 "ListActivatableNames",
315 r = sd_bus_message_read_strv(reply, &y);
331 _public_ int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatable) {
332 assert_return(bus, -EINVAL);
333 assert_return(acquired || activatable, -EINVAL);
334 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
335 assert_return(!bus_pid_changed(bus), -ECHILD);
338 return bus_list_names_kernel(bus, acquired, activatable);
340 return bus_list_names_dbus1(bus, acquired, activatable);
343 static int bus_get_owner_kdbus(
347 sd_bus_creds **creds) {
349 _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
350 struct kdbus_cmd_conn_info *cmd;
351 struct kdbus_conn_info *conn_info;
352 struct kdbus_item *item;
357 r = bus_kernel_parse_unique_name(name, &id);
361 size = offsetof(struct kdbus_cmd_conn_info, name);
365 size = offsetof(struct kdbus_cmd_conn_info, name) + strlen(name) + 1;
367 strcpy(cmd->name, name);
369 cmd->flags = KDBUS_ATTACH_NAMES;
372 r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd);
376 conn_info = (struct kdbus_conn_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
382 if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
383 if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0)
386 c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
389 KDBUS_ITEM_FOREACH(item, conn_info, items) {
391 switch (item->type) {
393 case KDBUS_ITEM_CREDS:
394 m = (SD_BUS_CREDS_UID | SD_BUS_CREDS_GID | SD_BUS_CREDS_PID |
395 SD_BUS_CREDS_TID | SD_BUS_CREDS_PID_STARTTIME) & mask;
398 c->uid = item->creds.uid;
399 c->pid = item->creds.pid;
400 c->gid = item->creds.gid;
401 c->tid = item->creds.tid;
402 c->pid_starttime = item->creds.starttime;
407 case KDBUS_ITEM_PID_COMM:
408 if (mask & SD_BUS_CREDS_COMM) {
409 c->comm = strdup(item->str);
415 c->mask |= SD_BUS_CREDS_COMM;
419 case KDBUS_ITEM_TID_COMM:
420 if (mask & SD_BUS_CREDS_TID_COMM) {
421 c->tid_comm = strdup(item->str);
427 c->mask |= SD_BUS_CREDS_TID_COMM;
432 if (mask & SD_BUS_CREDS_EXE) {
433 c->exe = strdup(item->str);
439 c->mask |= SD_BUS_CREDS_EXE;
443 case KDBUS_ITEM_CMDLINE:
444 if (mask & SD_BUS_CREDS_CMDLINE) {
445 c->cmdline_size = item->size - KDBUS_ITEM_HEADER_SIZE;
446 c->cmdline = memdup(item->data, c->cmdline_size);
452 c->mask |= SD_BUS_CREDS_CMDLINE;
456 case KDBUS_ITEM_CGROUP:
457 m = (SD_BUS_CREDS_CGROUP | SD_BUS_CREDS_UNIT |
458 SD_BUS_CREDS_USER_UNIT | SD_BUS_CREDS_SLICE |
459 SD_BUS_CREDS_SESSION | SD_BUS_CREDS_OWNER_UID) & mask;
462 c->cgroup = strdup(item->str);
472 case KDBUS_ITEM_CAPS:
473 m = (SD_BUS_CREDS_EFFECTIVE_CAPS | SD_BUS_CREDS_PERMITTED_CAPS |
474 SD_BUS_CREDS_INHERITABLE_CAPS | SD_BUS_CREDS_BOUNDING_CAPS) & mask;
477 c->capability_size = item->size - KDBUS_ITEM_HEADER_SIZE;
478 c->capability = memdup(item->data, c->capability_size);
479 if (!c->capability) {
488 case KDBUS_ITEM_SECLABEL:
489 if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
490 c->label = strdup(item->str);
496 c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
500 case KDBUS_ITEM_AUDIT:
501 m = (SD_BUS_CREDS_AUDIT_SESSION_ID | SD_BUS_CREDS_AUDIT_LOGIN_UID) & mask;
504 c->audit_session_id = item->audit.sessionid;
505 c->audit_login_uid = item->audit.loginuid;
510 case KDBUS_ITEM_NAME:
511 if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) {
512 r = strv_extend(&c->well_known_names, item->name.name);
516 c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES;
530 ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd->offset);
534 static int bus_get_owner_dbus1(
538 sd_bus_creds **creds) {
540 _cleanup_bus_message_unref_ sd_bus_message *reply_unique = NULL, *reply = NULL;
541 _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
542 const char *unique = NULL;
546 /* Only query the owner if the caller wants to know it or if
547 * the caller just wants to check whether a name exists */
548 if ((mask & SD_BUS_CREDS_UNIQUE_NAME) || mask == 0) {
549 r = sd_bus_call_method(
551 "org.freedesktop.DBus",
553 "org.freedesktop.DBus",
562 r = sd_bus_message_read(reply_unique, "s", &unique);
572 if ((mask & SD_BUS_CREDS_UNIQUE_NAME) && unique) {
573 c->unique_name = strdup(unique);
577 c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
580 if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_GID|
581 SD_BUS_CREDS_COMM|SD_BUS_CREDS_EXE|SD_BUS_CREDS_CMDLINE|
582 SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID|
583 SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS|
584 SD_BUS_CREDS_AUDIT_SESSION_ID|SD_BUS_CREDS_AUDIT_LOGIN_UID)) {
587 r = sd_bus_call_method(
589 "org.freedesktop.DBus",
591 "org.freedesktop.DBus",
592 "GetConnectionUnixProcessID",
596 unique ? unique : name);
600 r = sd_bus_message_read(reply, "u", &u);
605 if (mask & SD_BUS_CREDS_PID) {
607 c->mask |= SD_BUS_CREDS_PID;
610 reply = sd_bus_message_unref(reply);
613 if (mask & SD_BUS_CREDS_UID) {
616 r = sd_bus_call_method(
618 "org.freedesktop.DBus",
620 "org.freedesktop.DBus",
621 "GetConnectionUnixUser",
625 unique ? unique : name);
629 r = sd_bus_message_read(reply, "u", &u);
634 c->mask |= SD_BUS_CREDS_UID;
636 reply = sd_bus_message_unref(reply);
639 if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
643 r = sd_bus_call_method(
645 "org.freedesktop.DBus",
647 "org.freedesktop.DBus",
648 "GetConnectionSELinuxSecurityContext",
652 unique ? unique : name);
656 r = sd_bus_message_read_array(reply, 'y', &p, &sz);
660 c->label = strndup(p, sz);
664 c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
667 r = bus_creds_add_more(c, mask, pid, 0);
680 _public_ int sd_bus_get_owner(
684 sd_bus_creds **creds) {
686 assert_return(bus, -EINVAL);
687 assert_return(name, -EINVAL);
688 assert_return(mask <= _SD_BUS_CREDS_ALL, -ENOTSUP);
689 assert_return(mask == 0 || creds, -EINVAL);
690 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
691 assert_return(!bus_pid_changed(bus), -ECHILD);
694 return bus_get_owner_kdbus(bus, name, mask, creds);
696 return bus_get_owner_dbus1(bus, name, mask, creds);
699 static int add_name_change_match(sd_bus *bus,
702 const char *old_owner,
703 const char *new_owner) {
705 uint64_t name_id = 0, old_owner_id = 0, new_owner_id = 0;
706 int is_name_id = -1, r;
707 struct kdbus_item *item;
711 /* If we encounter a match that could match against
712 * NameOwnerChanged messages, then we need to create
713 * KDBUS_MATCH_NAME_{ADD,REMOVE,CHANGE} and
714 * KDBUS_MATCH_ID_{ADD,REMOVE} matches for it, possibly
715 * multiple if the match is underspecified.
717 * The NameOwnerChanged signals take three parameters with
718 * unique or well-known names, but only some forms actually
721 * WELLKNOWN, "", UNIQUE → KDBUS_MATCH_NAME_ADD
722 * WELLKNOWN, UNIQUE, "" → KDBUS_MATCH_NAME_REMOVE
723 * WELLKNOWN, UNIQUE, UNIQUE → KDBUS_MATCH_NAME_CHANGE
724 * UNIQUE, "", UNIQUE → KDBUS_MATCH_ID_ADD
725 * UNIQUE, UNIQUE, "" → KDBUS_MATCH_ID_REMOVE
727 * For the latter two the two unique names must be identical.
732 is_name_id = bus_kernel_parse_unique_name(name, &name_id);
738 r = bus_kernel_parse_unique_name(old_owner, &old_owner_id);
743 if (is_name_id > 0 && old_owner_id != name_id)
748 r = bus_kernel_parse_unique_name(new_owner, &new_owner_id);
753 if (is_name_id > 0 && new_owner_id != name_id)
757 if (is_name_id <= 0) {
758 struct kdbus_cmd_match *m;
761 /* If the name argument is missing or is a well-known
762 * name, then add KDBUS_MATCH_NAME_{ADD,REMOVE,CHANGE}
765 l = name ? strlen(name) : 0;
767 sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) +
768 offsetof(struct kdbus_item, name_change) +
769 offsetof(struct kdbus_notify_name_change, name) +
775 m->src_id = KDBUS_SRC_ID_KERNEL;
779 offsetof(struct kdbus_item, name_change) +
780 offsetof(struct kdbus_notify_name_change, name) +
783 item->name_change.old_id = old_owner_id;
784 item->name_change.new_id = new_owner_id;
787 strcpy(item->name_change.name, name);
789 /* If the old name is unset or empty, then
790 * this can match against added names */
791 if (!old_owner || old_owner[0] == 0) {
792 item->type = KDBUS_MATCH_NAME_ADD;
794 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
799 /* If the new name is unset or empty, then
800 * this can match against removed names */
801 if (!new_owner || new_owner[0] == 0) {
802 item->type = KDBUS_MATCH_NAME_REMOVE;
804 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
809 /* If the neither name is explicitly set to
810 * the empty string, then this can match
811 * agains changed names */
812 if (!(old_owner && old_owner[0] == 0) &&
813 !(new_owner && new_owner[0] == 0)) {
814 item->type = KDBUS_MATCH_NAME_CHANGE;
816 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
822 if (is_name_id != 0) {
823 struct kdbus_cmd_match *m;
826 /* If the name argument is missing or is a unique
827 * name, then add KDBUS_MATCH_ID_{ADD,REMOVE} matches
830 sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) +
831 offsetof(struct kdbus_item, id_change) +
832 sizeof(struct kdbus_notify_id_change));
837 m->src_id = KDBUS_SRC_ID_KERNEL;
840 item->size = offsetof(struct kdbus_item, id_change) + sizeof(struct kdbus_notify_id_change);
841 item->id_change.id = name_id;
843 /* If the old name is unset or empty, then this can
844 * match against added ids */
845 if (!old_owner || old_owner[0] == 0) {
846 item->type = KDBUS_MATCH_ID_ADD;
848 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
853 /* If thew new name is unset or empty, then this can
854 match against removed ids */
855 if (!new_owner || new_owner[0] == 0) {
856 item->type = KDBUS_MATCH_ID_REMOVE;
858 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
867 static int bus_add_match_internal_kernel(
870 struct bus_match_component *components,
871 unsigned n_components,
874 struct kdbus_cmd_match *m;
875 struct kdbus_item *item;
876 uint64_t bloom[BLOOM_SIZE/8];
878 const char *sender = NULL;
879 size_t sender_length = 0;
880 uint64_t src_id = KDBUS_MATCH_SRC_ID_ANY;
881 bool using_bloom = false;
883 bool matches_name_change = true;
884 const char *name_change_arg[3] = {};
892 sz = offsetof(struct kdbus_cmd_match, items);
894 for (i = 0; i < n_components; i++) {
895 struct bus_match_component *c = &components[i];
899 case BUS_MATCH_SENDER:
900 if (!streq(c->value_str, "org.freedesktop.DBus"))
901 matches_name_change = false;
903 r = bus_kernel_parse_unique_name(c->value_str, &src_id);
908 sender = c->value_str;
909 sender_length = strlen(sender);
910 sz += ALIGN8(offsetof(struct kdbus_item, str) + sender_length + 1);
915 case BUS_MATCH_MESSAGE_TYPE:
916 if (c->value_u8 != SD_BUS_MESSAGE_SIGNAL)
917 matches_name_change = false;
919 bloom_add_pair(bloom, "message-type", bus_message_type_to_string(c->value_u8));
923 case BUS_MATCH_INTERFACE:
924 if (!streq(c->value_str, "org.freedesktop.DBus"))
925 matches_name_change = false;
927 bloom_add_pair(bloom, "interface", c->value_str);
931 case BUS_MATCH_MEMBER:
932 if (!streq(c->value_str, "NameOwnerChanged"))
933 matches_name_change = false;
935 bloom_add_pair(bloom, "member", c->value_str);
940 if (!streq(c->value_str, "/org/freedesktop/DBus"))
941 matches_name_change = false;
943 bloom_add_pair(bloom, "path", c->value_str);
947 case BUS_MATCH_PATH_NAMESPACE:
948 if (!streq(c->value_str, "/")) {
949 bloom_add_pair(bloom, "path-slash-prefix", c->value_str);
954 case BUS_MATCH_ARG...BUS_MATCH_ARG_LAST: {
955 char buf[sizeof("arg")-1 + 2 + 1];
957 if (c->type - BUS_MATCH_ARG < 3)
958 name_change_arg[c->type - BUS_MATCH_ARG] = c->value_str;
960 snprintf(buf, sizeof(buf), "arg%u", c->type - BUS_MATCH_ARG);
961 bloom_add_pair(bloom, buf, c->value_str);
966 case BUS_MATCH_ARG_PATH...BUS_MATCH_ARG_PATH_LAST: {
967 char buf[sizeof("arg")-1 + 2 + sizeof("-slash-prefix")];
969 snprintf(buf, sizeof(buf), "arg%u-slash-prefix", c->type - BUS_MATCH_ARG_PATH);
970 bloom_add_pair(bloom, buf, c->value_str);
975 case BUS_MATCH_ARG_NAMESPACE...BUS_MATCH_ARG_NAMESPACE_LAST: {
976 char buf[sizeof("arg")-1 + 2 + sizeof("-dot-prefix")];
978 snprintf(buf, sizeof(buf), "arg%u-dot-prefix", c->type - BUS_MATCH_ARG_NAMESPACE);
979 bloom_add_pair(bloom, buf, c->value_str);
984 case BUS_MATCH_DESTINATION:
985 /* The bloom filter does not include
986 the destination, since it is only
987 available for broadcast messages
988 which do not carry a destination
989 since they are undirected. */
993 case BUS_MATCH_VALUE:
995 case _BUS_MATCH_NODE_TYPE_MAX:
996 case _BUS_MATCH_NODE_TYPE_INVALID:
997 assert_not_reached("Invalid match type?");
1002 sz += ALIGN8(offsetof(struct kdbus_item, data64) + BLOOM_SIZE);
1012 item->size = offsetof(struct kdbus_item, data64) + BLOOM_SIZE;
1013 item->type = KDBUS_MATCH_BLOOM;
1014 memcpy(item->data64, bloom, BLOOM_SIZE);
1016 item = KDBUS_ITEM_NEXT(item);
1020 item->size = offsetof(struct kdbus_item, str) + sender_length + 1;
1021 item->type = KDBUS_MATCH_SRC_NAME;
1022 memcpy(item->str, sender, sender_length + 1);
1025 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
1029 if (matches_name_change) {
1031 /* If this match could theoretically match
1032 * NameOwnerChanged messages, we need to
1033 * install a second non-bloom filter explitly
1036 r = add_name_change_match(bus, cookie, name_change_arg[0], name_change_arg[1], name_change_arg[2]);
1044 static int bus_add_match_internal_dbus1(
1046 const char *match) {
1051 return sd_bus_call_method(
1053 "org.freedesktop.DBus",
1055 "org.freedesktop.DBus",
1063 int bus_add_match_internal(
1066 struct bus_match_component *components,
1067 unsigned n_components,
1074 return bus_add_match_internal_kernel(bus, match, components, n_components, cookie);
1076 return bus_add_match_internal_dbus1(bus, match);
1079 static int bus_remove_match_internal_kernel(
1084 struct kdbus_cmd_match m;
1091 m.size = offsetof(struct kdbus_cmd_match, items);
1094 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_REMOVE, &m);
1101 static int bus_remove_match_internal_dbus1(
1103 const char *match) {
1108 return sd_bus_call_method(
1110 "org.freedesktop.DBus",
1112 "org.freedesktop.DBus",
1120 int bus_remove_match_internal(
1129 return bus_remove_match_internal_kernel(bus, match, cookie);
1131 return bus_remove_match_internal_dbus1(bus, match);
1134 _public_ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine) {
1135 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
1139 assert_return(bus, -EINVAL);
1140 assert_return(name, -EINVAL);
1141 assert_return(machine, -EINVAL);
1142 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
1143 assert_return(!bus_pid_changed(bus), -ECHILD);
1145 if (streq_ptr(name, bus->unique_name))
1146 return sd_id128_get_machine(machine);
1148 r = sd_bus_message_new_method_call(
1152 "org.freedesktop.DBus.Peer",
1153 "GetMachineId", &m);
1157 r = sd_bus_message_set_no_auto_start(m, true);
1161 r = sd_bus_call(bus, m, 0, NULL, &reply);
1165 r = sd_bus_message_read(reply, "s", &mid);
1169 return sd_id128_from_string(mid, machine);