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>
32 #include "bus-internal.h"
33 #include "bus-message.h"
34 #include "bus-control.h"
35 #include "bus-bloom.h"
38 _public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
41 assert_return(bus, -EINVAL);
42 assert_return(unique, -EINVAL);
43 assert_return(!bus_pid_changed(bus), -ECHILD);
45 r = bus_ensure_running(bus);
49 *unique = bus->unique_name;
53 static int bus_request_name_kernel(sd_bus *bus, const char *name, unsigned flags) {
54 struct kdbus_cmd_name *n;
62 n = alloca0(offsetof(struct kdbus_cmd_name, name) + l + 1);
63 n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
64 kdbus_translate_request_name_flags(flags, (uint64_t *) &n->flags);
65 memcpy(n->name, name, l+1);
67 #ifdef HAVE_VALGRIND_MEMCHECK_H
68 VALGRIND_MAKE_MEM_DEFINED(n, n->size);
71 r = ioctl(bus->input_fd, KDBUS_CMD_NAME_ACQUIRE, n);
75 if (n->flags & KDBUS_NAME_IN_QUEUE)
81 static int bus_request_name_dbus1(sd_bus *bus, const char *name, unsigned flags) {
82 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
89 r = sd_bus_call_method(
91 "org.freedesktop.DBus",
93 "org.freedesktop.DBus",
103 r = sd_bus_message_read(reply, "u", &ret);
107 if (ret == BUS_NAME_ALREADY_OWNER)
109 else if (ret == BUS_NAME_EXISTS)
111 else if (ret == BUS_NAME_IN_QUEUE)
113 else if (ret == BUS_NAME_PRIMARY_OWNER)
119 _public_ int sd_bus_request_name(sd_bus *bus, const char *name, unsigned flags) {
120 assert_return(bus, -EINVAL);
121 assert_return(name, -EINVAL);
122 assert_return(bus->bus_client, -EINVAL);
123 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
124 assert_return(!bus_pid_changed(bus), -ECHILD);
125 assert_return(!(flags & ~(SD_BUS_NAME_ALLOW_REPLACEMENT|SD_BUS_NAME_REPLACE_EXISTING|SD_BUS_NAME_DO_NOT_QUEUE)), -EINVAL);
128 return bus_request_name_kernel(bus, name, flags);
130 return bus_request_name_dbus1(bus, name, flags);
133 static int bus_release_name_kernel(sd_bus *bus, const char *name) {
134 struct kdbus_cmd_name *n;
142 n = alloca0(offsetof(struct kdbus_cmd_name, name) + l + 1);
143 n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
144 memcpy(n->name, name, l+1);
146 #ifdef HAVE_VALGRIND_MEMCHECK_H
147 VALGRIND_MAKE_MEM_DEFINED(n, n->size);
149 r = ioctl(bus->input_fd, KDBUS_CMD_NAME_RELEASE, n);
156 static int bus_release_name_dbus1(sd_bus *bus, const char *name) {
157 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
164 r = sd_bus_call_method(
166 "org.freedesktop.DBus",
168 "org.freedesktop.DBus",
177 r = sd_bus_message_read(reply, "u", &ret);
180 if (ret == BUS_NAME_NON_EXISTENT)
182 if (ret == BUS_NAME_NOT_OWNER)
183 return -EADDRNOTAVAIL;
184 if (ret == BUS_NAME_RELEASED)
190 _public_ int sd_bus_release_name(sd_bus *bus, const char *name) {
191 assert_return(bus, -EINVAL);
192 assert_return(name, -EINVAL);
193 assert_return(bus->bus_client, -EINVAL);
194 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
195 assert_return(!bus_pid_changed(bus), -ECHILD);
198 return bus_release_name_kernel(bus, name);
200 return bus_release_name_dbus1(bus, name);
203 static int kernel_get_list(sd_bus *bus, uint64_t flags, char ***x) {
204 struct kdbus_cmd_name_list cmd = {};
205 struct kdbus_name_list *name_list;
206 struct kdbus_cmd_name *name;
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_PART_FOREACH(name, name_list, names) {
221 if (name->size > sizeof(*name)) {
222 r = strv_extend(x, name->name);
228 if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0)
240 r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_FREE, &cmd.offset);
247 static int bus_list_names_kernel(sd_bus *bus, char ***acquired, char ***activatable) {
248 _cleanup_strv_free_ char **x = NULL, **y = NULL;
252 r = kernel_get_list(bus, KDBUS_NAME_LIST_UNIQUE | KDBUS_NAME_LIST_NAMES, &x);
258 r = kernel_get_list(bus, KDBUS_NAME_LIST_STARTERS, &y);
274 static int bus_list_names_dbus1(sd_bus *bus, char ***acquired, char ***activatable) {
275 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
276 _cleanup_strv_free_ char **x = NULL, **y = NULL;
280 r = sd_bus_call_method(
282 "org.freedesktop.DBus",
284 "org.freedesktop.DBus",
292 r = sd_bus_message_read_strv(reply, &x);
296 reply = sd_bus_message_unref(reply);
300 r = sd_bus_call_method(
302 "org.freedesktop.DBus",
304 "org.freedesktop.DBus",
305 "ListActivatableNames",
312 r = sd_bus_message_read_strv(reply, &y);
328 _public_ int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatable) {
329 assert_return(bus, -EINVAL);
330 assert_return(acquired || activatable, -EINVAL);
331 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
332 assert_return(!bus_pid_changed(bus), -ECHILD);
335 return bus_list_names_kernel(bus, acquired, activatable);
337 return bus_list_names_dbus1(bus, acquired, activatable);
340 static int bus_get_owner_kdbus(
344 sd_bus_creds **creds) {
346 _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
347 struct kdbus_cmd_conn_info *cmd;
348 struct kdbus_conn_info *conn_info;
349 struct kdbus_item *item;
354 r = bus_kernel_parse_unique_name(name, &id);
358 size = offsetof(struct kdbus_cmd_conn_info, name);
362 size = offsetof(struct kdbus_cmd_conn_info, name) + strlen(name) + 1;
364 strcpy(cmd->name, name);
366 cmd->flags = KDBUS_ATTACH_NAMES;
369 r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd);
373 conn_info = (struct kdbus_conn_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
379 if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
380 if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0)
383 c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
386 KDBUS_PART_FOREACH(item, conn_info, items) {
388 switch (item->type) {
390 case KDBUS_ITEM_CREDS:
391 m = (SD_BUS_CREDS_UID | SD_BUS_CREDS_GID | SD_BUS_CREDS_PID |
392 SD_BUS_CREDS_TID | SD_BUS_CREDS_PID_STARTTIME) & mask;
395 c->uid = item->creds.uid;
396 c->pid = item->creds.pid;
397 c->gid = item->creds.gid;
398 c->tid = item->creds.tid;
399 c->pid_starttime = item->creds.starttime;
404 case KDBUS_ITEM_PID_COMM:
405 if (mask & SD_BUS_CREDS_COMM) {
406 c->comm = strdup(item->str);
412 c->mask |= SD_BUS_CREDS_COMM;
416 case KDBUS_ITEM_TID_COMM:
417 if (mask & SD_BUS_CREDS_TID_COMM) {
418 c->tid_comm = strdup(item->str);
424 c->mask |= SD_BUS_CREDS_TID_COMM;
429 if (mask & SD_BUS_CREDS_EXE) {
430 c->exe = strdup(item->str);
436 c->mask |= SD_BUS_CREDS_EXE;
440 case KDBUS_ITEM_CMDLINE:
441 if (mask & SD_BUS_CREDS_CMDLINE) {
442 c->cmdline_size = item->size - KDBUS_PART_HEADER_SIZE;
443 c->cmdline = memdup(item->data, c->cmdline_size);
449 c->mask |= SD_BUS_CREDS_CMDLINE;
453 case KDBUS_ITEM_CGROUP:
454 m = (SD_BUS_CREDS_CGROUP | SD_BUS_CREDS_UNIT |
455 SD_BUS_CREDS_USER_UNIT | SD_BUS_CREDS_SLICE |
456 SD_BUS_CREDS_SESSION | SD_BUS_CREDS_OWNER_UID) & mask;
459 c->cgroup = strdup(item->str);
469 case KDBUS_ITEM_CAPS:
470 m = (SD_BUS_CREDS_EFFECTIVE_CAPS | SD_BUS_CREDS_PERMITTED_CAPS |
471 SD_BUS_CREDS_INHERITABLE_CAPS | SD_BUS_CREDS_BOUNDING_CAPS) & mask;
474 c->capability_size = item->size - KDBUS_PART_HEADER_SIZE;
475 c->capability = memdup(item->data, c->capability_size);
476 if (!c->capability) {
485 case KDBUS_ITEM_SECLABEL:
486 if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
487 c->label = strdup(item->str);
493 c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
497 case KDBUS_ITEM_AUDIT:
498 m = (SD_BUS_CREDS_AUDIT_SESSION_ID | SD_BUS_CREDS_AUDIT_LOGIN_UID) & mask;
501 c->audit_session_id = item->audit.sessionid;
502 c->audit_login_uid = item->audit.loginuid;
507 case KDBUS_ITEM_NAME:
508 if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) {
509 r = strv_extend(&c->well_known_names, item->name.name);
513 c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES;
527 ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd->offset);
531 static int bus_get_owner_dbus1(
535 sd_bus_creds **creds) {
537 _cleanup_bus_message_unref_ sd_bus_message *reply_unique = NULL, *reply = NULL;
538 _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
539 const char *unique = NULL;
543 /* Only query the owner if the caller wants to know it or if
544 * the caller just wants to check whether a name exists */
545 if ((mask & SD_BUS_CREDS_UNIQUE_NAME) || mask == 0) {
546 r = sd_bus_call_method(
548 "org.freedesktop.DBus",
550 "org.freedesktop.DBus",
559 r = sd_bus_message_read(reply_unique, "s", &unique);
569 if ((mask & SD_BUS_CREDS_UNIQUE_NAME) && unique) {
570 c->unique_name = strdup(unique);
574 c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
577 if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_GID|
578 SD_BUS_CREDS_COMM|SD_BUS_CREDS_EXE|SD_BUS_CREDS_CMDLINE|
579 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|
580 SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS|
581 SD_BUS_CREDS_AUDIT_SESSION_ID|SD_BUS_CREDS_AUDIT_LOGIN_UID)) {
584 r = sd_bus_call_method(
586 "org.freedesktop.DBus",
588 "org.freedesktop.DBus",
589 "GetConnectionUnixProcessID",
593 unique ? unique : name);
597 r = sd_bus_message_read(reply, "u", &u);
602 if (mask & SD_BUS_CREDS_PID) {
604 c->mask |= SD_BUS_CREDS_PID;
607 reply = sd_bus_message_unref(reply);
610 if (mask & SD_BUS_CREDS_UID) {
613 r = sd_bus_call_method(
615 "org.freedesktop.DBus",
617 "org.freedesktop.DBus",
618 "GetConnectionUnixUser",
622 unique ? unique : name);
626 r = sd_bus_message_read(reply, "u", &u);
631 c->mask |= SD_BUS_CREDS_UID;
633 reply = sd_bus_message_unref(reply);
636 if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
640 r = sd_bus_call_method(
642 "org.freedesktop.DBus",
644 "org.freedesktop.DBus",
645 "GetConnectionSELinuxSecurityContext",
649 unique ? unique : name);
653 r = sd_bus_message_read_array(reply, 'y', &p, &sz);
657 c->label = strndup(p, sz);
661 c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
664 r = bus_creds_add_more(c, mask, pid, 0);
677 _public_ int sd_bus_get_owner(
681 sd_bus_creds **creds) {
683 assert_return(bus, -EINVAL);
684 assert_return(name, -EINVAL);
685 assert_return(mask <= _SD_BUS_CREDS_ALL, -ENOTSUP);
686 assert_return(mask == 0 || creds, -EINVAL);
687 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
688 assert_return(!bus_pid_changed(bus), -ECHILD);
691 return bus_get_owner_kdbus(bus, name, mask, creds);
693 return bus_get_owner_dbus1(bus, name, mask, creds);
696 static int add_name_change_match(sd_bus *bus,
699 const char *old_owner,
700 const char *new_owner) {
702 uint64_t name_id = 0, old_owner_id = 0, new_owner_id = 0;
703 int is_name_id = -1, r;
704 struct kdbus_item *item;
708 /* If we encounter a match that could match against
709 * NameOwnerChanged messages, then we need to create
710 * KDBUS_MATCH_NAME_{ADD,REMOVE,CHANGE} and
711 * KDBUS_MATCH_ID_{ADD,REMOVE} matches for it, possibly
712 * multiple if the match is underspecified.
714 * The NameOwnerChanged signals take three parameters with
715 * unique or well-known names, but only some forms actually
718 * WELLKNOWN, "", UNIQUE → KDBUS_MATCH_NAME_ADD
719 * WELLKNOWN, UNIQUE, "" → KDBUS_MATCH_NAME_REMOVE
720 * WELLKNOWN, UNIQUE, UNIQUE → KDBUS_MATCH_NAME_CHANGE
721 * UNIQUE, "", UNIQUE → KDBUS_MATCH_ID_ADD
722 * UNIQUE, UNIQUE, "" → KDBUS_MATCH_ID_REMOVE
724 * For the latter two the two unique names must be identical.
729 is_name_id = bus_kernel_parse_unique_name(name, &name_id);
735 r = bus_kernel_parse_unique_name(old_owner, &old_owner_id);
740 if (is_name_id > 0 && old_owner_id != name_id)
745 r = bus_kernel_parse_unique_name(new_owner, &new_owner_id);
750 if (is_name_id > 0 && new_owner_id != name_id)
754 if (is_name_id <= 0) {
755 struct kdbus_cmd_match *m;
758 /* If the name argument is missing or is a well-known
759 * name, then add KDBUS_MATCH_NAME_{ADD,REMOVE,CHANGE}
762 l = name ? strlen(name) : 0;
764 sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) +
765 offsetof(struct kdbus_item, name_change) +
766 offsetof(struct kdbus_notify_name_change, name) +
772 m->src_id = KDBUS_SRC_ID_KERNEL;
776 offsetof(struct kdbus_item, name_change) +
777 offsetof(struct kdbus_notify_name_change, name) +
780 item->name_change.old_id = old_owner_id;
781 item->name_change.new_id = new_owner_id;
784 strcpy(item->name_change.name, name);
786 /* If the old name is unset or empty, then
787 * this can match against added names */
788 if (!old_owner || old_owner[0] == 0) {
789 item->type = KDBUS_MATCH_NAME_ADD;
791 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
796 /* If the new name is unset or empty, then
797 * this can match against removed names */
798 if (!new_owner || new_owner[0] == 0) {
799 item->type = KDBUS_MATCH_NAME_REMOVE;
801 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
806 /* If the neither name is explicitly set to
807 * the empty string, then this can match
808 * agains changed names */
809 if (!(old_owner && old_owner[0] == 0) &&
810 !(new_owner && new_owner[0] == 0)) {
811 item->type = KDBUS_MATCH_NAME_CHANGE;
813 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
819 if (is_name_id != 0) {
820 struct kdbus_cmd_match *m;
823 /* If the name argument is missing or is a unique
824 * name, then add KDBUS_MATCH_ID_{ADD,REMOVE} matches
827 sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) +
828 offsetof(struct kdbus_item, id_change) +
829 sizeof(struct kdbus_notify_id_change));
834 m->src_id = KDBUS_SRC_ID_KERNEL;
837 item->size = offsetof(struct kdbus_item, id_change) + sizeof(struct kdbus_notify_id_change);
838 item->id_change.id = name_id;
840 /* If the old name is unset or empty, then this can
841 * match against added ids */
842 if (!old_owner || old_owner[0] == 0) {
843 item->type = KDBUS_MATCH_ID_ADD;
845 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
850 /* If thew new name is unset or empty, then this can
851 match against removed ids */
852 if (!new_owner || new_owner[0] == 0) {
853 item->type = KDBUS_MATCH_ID_REMOVE;
855 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
864 static int bus_add_match_internal_kernel(
867 struct bus_match_component *components,
868 unsigned n_components,
871 struct kdbus_cmd_match *m;
872 struct kdbus_item *item;
873 uint64_t bloom[BLOOM_SIZE/8];
875 const char *sender = NULL;
876 size_t sender_length = 0;
877 uint64_t src_id = KDBUS_MATCH_SRC_ID_ANY;
878 bool using_bloom = false;
880 bool matches_name_change = true;
881 const char *name_change_arg[3] = {};
889 sz = offsetof(struct kdbus_cmd_match, items);
891 for (i = 0; i < n_components; i++) {
892 struct bus_match_component *c = &components[i];
896 case BUS_MATCH_SENDER:
897 if (!streq(c->value_str, "org.freedesktop.DBus"))
898 matches_name_change = false;
900 r = bus_kernel_parse_unique_name(c->value_str, &src_id);
905 sender = c->value_str;
906 sender_length = strlen(sender);
907 sz += ALIGN8(offsetof(struct kdbus_item, str) + sender_length + 1);
912 case BUS_MATCH_MESSAGE_TYPE:
913 if (c->value_u8 != SD_BUS_MESSAGE_SIGNAL)
914 matches_name_change = false;
916 bloom_add_pair(bloom, "message-type", bus_message_type_to_string(c->value_u8));
920 case BUS_MATCH_INTERFACE:
921 if (!streq(c->value_str, "org.freedesktop.DBus"))
922 matches_name_change = false;
924 bloom_add_pair(bloom, "interface", c->value_str);
928 case BUS_MATCH_MEMBER:
929 if (!streq(c->value_str, "NameOwnerChanged"))
930 matches_name_change = false;
932 bloom_add_pair(bloom, "member", c->value_str);
937 if (!streq(c->value_str, "/org/freedesktop/DBus"))
938 matches_name_change = false;
940 bloom_add_pair(bloom, "path", c->value_str);
944 case BUS_MATCH_PATH_NAMESPACE:
945 if (!streq(c->value_str, "/")) {
946 bloom_add_pair(bloom, "path-slash-prefix", c->value_str);
951 case BUS_MATCH_ARG...BUS_MATCH_ARG_LAST: {
952 char buf[sizeof("arg")-1 + 2 + 1];
954 if (c->type - BUS_MATCH_ARG < 3)
955 name_change_arg[c->type - BUS_MATCH_ARG] = c->value_str;
957 snprintf(buf, sizeof(buf), "arg%u", c->type - BUS_MATCH_ARG);
958 bloom_add_pair(bloom, buf, c->value_str);
963 case BUS_MATCH_ARG_PATH...BUS_MATCH_ARG_PATH_LAST: {
964 char buf[sizeof("arg")-1 + 2 + sizeof("-slash-prefix")];
966 snprintf(buf, sizeof(buf), "arg%u-slash-prefix", c->type - BUS_MATCH_ARG_PATH);
967 bloom_add_pair(bloom, buf, c->value_str);
972 case BUS_MATCH_ARG_NAMESPACE...BUS_MATCH_ARG_NAMESPACE_LAST: {
973 char buf[sizeof("arg")-1 + 2 + sizeof("-dot-prefix")];
975 snprintf(buf, sizeof(buf), "arg%u-dot-prefix", c->type - BUS_MATCH_ARG_NAMESPACE);
976 bloom_add_pair(bloom, buf, c->value_str);
981 case BUS_MATCH_DESTINATION:
982 /* The bloom filter does not include
983 the destination, since it is only
984 available for broadcast messages
985 which do not carry a destination
986 since they are undirected. */
990 case BUS_MATCH_VALUE:
992 case _BUS_MATCH_NODE_TYPE_MAX:
993 case _BUS_MATCH_NODE_TYPE_INVALID:
994 assert_not_reached("Invalid match type?");
999 sz += ALIGN8(offsetof(struct kdbus_item, data64) + BLOOM_SIZE);
1009 item->size = offsetof(struct kdbus_item, data64) + BLOOM_SIZE;
1010 item->type = KDBUS_MATCH_BLOOM;
1011 memcpy(item->data64, bloom, BLOOM_SIZE);
1013 item = KDBUS_PART_NEXT(item);
1017 item->size = offsetof(struct kdbus_item, str) + sender_length + 1;
1018 item->type = KDBUS_MATCH_SRC_NAME;
1019 memcpy(item->str, sender, sender_length + 1);
1022 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
1026 if (matches_name_change) {
1028 /* If this match could theoretically match
1029 * NameOwnerChanged messages, we need to
1030 * install a second non-bloom filter explitly
1033 r = add_name_change_match(bus, cookie, name_change_arg[0], name_change_arg[1], name_change_arg[2]);
1041 static int bus_add_match_internal_dbus1(
1043 const char *match) {
1048 return sd_bus_call_method(
1050 "org.freedesktop.DBus",
1052 "org.freedesktop.DBus",
1060 int bus_add_match_internal(
1063 struct bus_match_component *components,
1064 unsigned n_components,
1071 return bus_add_match_internal_kernel(bus, match, components, n_components, cookie);
1073 return bus_add_match_internal_dbus1(bus, match);
1076 static int bus_remove_match_internal_kernel(
1081 struct kdbus_cmd_match m;
1088 m.size = offsetof(struct kdbus_cmd_match, items);
1091 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_REMOVE, &m);
1098 static int bus_remove_match_internal_dbus1(
1100 const char *match) {
1105 return sd_bus_call_method(
1107 "org.freedesktop.DBus",
1109 "org.freedesktop.DBus",
1117 int bus_remove_match_internal(
1126 return bus_remove_match_internal_kernel(bus, match, cookie);
1128 return bus_remove_match_internal_dbus1(bus, match);
1131 _public_ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine) {
1132 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
1136 assert_return(bus, -EINVAL);
1137 assert_return(name, -EINVAL);
1138 assert_return(machine, -EINVAL);
1139 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
1140 assert_return(!bus_pid_changed(bus), -ECHILD);
1142 if (streq_ptr(name, bus->unique_name))
1143 return sd_id128_get_machine(machine);
1145 r = sd_bus_message_new_method_call(
1149 "org.freedesktop.DBus.Peer",
1150 "GetMachineId", &m);
1154 r = sd_bus_message_set_no_auto_start(m, true);
1158 r = sd_bus_call(bus, m, 0, NULL, &reply);
1162 r = sd_bus_message_read(reply, "s", &mid);
1166 return sd_id128_from_string(mid, machine);