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;
208 /* Caller will free half-constructed list on failure... */
212 r = ioctl(bus->input_fd, KDBUS_CMD_NAME_LIST, &cmd);
216 name_list = (struct kdbus_name_list *) ((uint8_t *) bus->kdbus_buffer + cmd.offset);
218 KDBUS_ITEM_FOREACH(name, name_list, names) {
220 if (name->size > sizeof(*name)) {
221 r = strv_extend(x, name->name);
227 if (asprintf(&n, ":1.%llu", (unsigned long long) name->id) < 0)
239 r = ioctl(sd_bus_get_fd(bus), KDBUS_CMD_FREE, &cmd.offset);
246 static int bus_list_names_kernel(sd_bus *bus, char ***acquired, char ***activatable) {
247 _cleanup_strv_free_ char **x = NULL, **y = NULL;
251 r = kernel_get_list(bus, KDBUS_NAME_LIST_UNIQUE | KDBUS_NAME_LIST_NAMES, &x);
257 r = kernel_get_list(bus, KDBUS_NAME_LIST_STARTERS, &y);
273 static int bus_list_names_dbus1(sd_bus *bus, char ***acquired, char ***activatable) {
274 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
275 _cleanup_strv_free_ char **x = NULL, **y = NULL;
279 r = sd_bus_call_method(
281 "org.freedesktop.DBus",
283 "org.freedesktop.DBus",
291 r = sd_bus_message_read_strv(reply, &x);
295 reply = sd_bus_message_unref(reply);
299 r = sd_bus_call_method(
301 "org.freedesktop.DBus",
303 "org.freedesktop.DBus",
304 "ListActivatableNames",
311 r = sd_bus_message_read_strv(reply, &y);
327 _public_ int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatable) {
328 assert_return(bus, -EINVAL);
329 assert_return(acquired || activatable, -EINVAL);
330 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
331 assert_return(!bus_pid_changed(bus), -ECHILD);
334 return bus_list_names_kernel(bus, acquired, activatable);
336 return bus_list_names_dbus1(bus, acquired, activatable);
339 static int bus_get_owner_kdbus(
343 sd_bus_creds **creds) {
345 _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
346 struct kdbus_cmd_conn_info *cmd;
347 struct kdbus_conn_info *conn_info;
348 struct kdbus_item *item;
353 r = bus_kernel_parse_unique_name(name, &id);
357 size = offsetof(struct kdbus_cmd_conn_info, name);
361 size = offsetof(struct kdbus_cmd_conn_info, name) + strlen(name) + 1;
363 strcpy(cmd->name, name);
365 cmd->flags = KDBUS_ATTACH_NAMES;
368 r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd);
372 conn_info = (struct kdbus_conn_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
378 if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
379 if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0)
382 c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
385 KDBUS_ITEM_FOREACH(item, conn_info, items) {
387 switch (item->type) {
389 case KDBUS_ITEM_CREDS:
390 m = (SD_BUS_CREDS_UID | SD_BUS_CREDS_GID | SD_BUS_CREDS_PID |
391 SD_BUS_CREDS_TID | SD_BUS_CREDS_PID_STARTTIME) & mask;
394 c->uid = item->creds.uid;
395 c->pid = item->creds.pid;
396 c->gid = item->creds.gid;
397 c->tid = item->creds.tid;
398 c->pid_starttime = item->creds.starttime;
403 case KDBUS_ITEM_PID_COMM:
404 if (mask & SD_BUS_CREDS_COMM) {
405 c->comm = strdup(item->str);
411 c->mask |= SD_BUS_CREDS_COMM;
415 case KDBUS_ITEM_TID_COMM:
416 if (mask & SD_BUS_CREDS_TID_COMM) {
417 c->tid_comm = strdup(item->str);
423 c->mask |= SD_BUS_CREDS_TID_COMM;
428 if (mask & SD_BUS_CREDS_EXE) {
429 c->exe = strdup(item->str);
435 c->mask |= SD_BUS_CREDS_EXE;
439 case KDBUS_ITEM_CMDLINE:
440 if (mask & SD_BUS_CREDS_CMDLINE) {
441 c->cmdline_size = item->size - KDBUS_ITEM_HEADER_SIZE;
442 c->cmdline = memdup(item->data, c->cmdline_size);
448 c->mask |= SD_BUS_CREDS_CMDLINE;
452 case KDBUS_ITEM_CGROUP:
453 m = (SD_BUS_CREDS_CGROUP | SD_BUS_CREDS_UNIT |
454 SD_BUS_CREDS_USER_UNIT | SD_BUS_CREDS_SLICE |
455 SD_BUS_CREDS_SESSION | SD_BUS_CREDS_OWNER_UID) & mask;
458 c->cgroup = strdup(item->str);
468 case KDBUS_ITEM_CAPS:
469 m = (SD_BUS_CREDS_EFFECTIVE_CAPS | SD_BUS_CREDS_PERMITTED_CAPS |
470 SD_BUS_CREDS_INHERITABLE_CAPS | SD_BUS_CREDS_BOUNDING_CAPS) & mask;
473 c->capability_size = item->size - KDBUS_ITEM_HEADER_SIZE;
474 c->capability = memdup(item->data, c->capability_size);
475 if (!c->capability) {
484 case KDBUS_ITEM_SECLABEL:
485 if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
486 c->label = strdup(item->str);
492 c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
496 case KDBUS_ITEM_AUDIT:
497 m = (SD_BUS_CREDS_AUDIT_SESSION_ID | SD_BUS_CREDS_AUDIT_LOGIN_UID) & mask;
500 c->audit_session_id = item->audit.sessionid;
501 c->audit_login_uid = item->audit.loginuid;
506 case KDBUS_ITEM_NAME:
507 if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) {
508 r = strv_extend(&c->well_known_names, item->name.name);
512 c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES;
526 ioctl(bus->input_fd, KDBUS_CMD_FREE, &cmd->offset);
530 static int bus_get_owner_dbus1(
534 sd_bus_creds **creds) {
536 _cleanup_bus_message_unref_ sd_bus_message *reply_unique = NULL, *reply = NULL;
537 _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
538 const char *unique = NULL;
542 /* Only query the owner if the caller wants to know it or if
543 * the caller just wants to check whether a name exists */
544 if ((mask & SD_BUS_CREDS_UNIQUE_NAME) || mask == 0) {
545 r = sd_bus_call_method(
547 "org.freedesktop.DBus",
549 "org.freedesktop.DBus",
558 r = sd_bus_message_read(reply_unique, "s", &unique);
568 if ((mask & SD_BUS_CREDS_UNIQUE_NAME) && unique) {
569 c->unique_name = strdup(unique);
573 c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
576 if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_GID|
577 SD_BUS_CREDS_COMM|SD_BUS_CREDS_EXE|SD_BUS_CREDS_CMDLINE|
578 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|
579 SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS|
580 SD_BUS_CREDS_AUDIT_SESSION_ID|SD_BUS_CREDS_AUDIT_LOGIN_UID)) {
583 r = sd_bus_call_method(
585 "org.freedesktop.DBus",
587 "org.freedesktop.DBus",
588 "GetConnectionUnixProcessID",
592 unique ? unique : name);
596 r = sd_bus_message_read(reply, "u", &u);
601 if (mask & SD_BUS_CREDS_PID) {
603 c->mask |= SD_BUS_CREDS_PID;
606 reply = sd_bus_message_unref(reply);
609 if (mask & SD_BUS_CREDS_UID) {
612 r = sd_bus_call_method(
614 "org.freedesktop.DBus",
616 "org.freedesktop.DBus",
617 "GetConnectionUnixUser",
621 unique ? unique : name);
625 r = sd_bus_message_read(reply, "u", &u);
630 c->mask |= SD_BUS_CREDS_UID;
632 reply = sd_bus_message_unref(reply);
635 if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
639 r = sd_bus_call_method(
641 "org.freedesktop.DBus",
643 "org.freedesktop.DBus",
644 "GetConnectionSELinuxSecurityContext",
648 unique ? unique : name);
652 r = sd_bus_message_read_array(reply, 'y', &p, &sz);
656 c->label = strndup(p, sz);
660 c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
663 r = bus_creds_add_more(c, mask, pid, 0);
676 _public_ int sd_bus_get_owner(
680 sd_bus_creds **creds) {
682 assert_return(bus, -EINVAL);
683 assert_return(name, -EINVAL);
684 assert_return(mask <= _SD_BUS_CREDS_ALL, -ENOTSUP);
685 assert_return(mask == 0 || creds, -EINVAL);
686 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
687 assert_return(!bus_pid_changed(bus), -ECHILD);
690 return bus_get_owner_kdbus(bus, name, mask, creds);
692 return bus_get_owner_dbus1(bus, name, mask, creds);
695 static int add_name_change_match(sd_bus *bus,
698 const char *old_owner,
699 const char *new_owner) {
701 uint64_t name_id = 0, old_owner_id = 0, new_owner_id = 0;
702 int is_name_id = -1, r;
703 struct kdbus_item *item;
707 /* If we encounter a match that could match against
708 * NameOwnerChanged messages, then we need to create
709 * KDBUS_MATCH_NAME_{ADD,REMOVE,CHANGE} and
710 * KDBUS_MATCH_ID_{ADD,REMOVE} matches for it, possibly
711 * multiple if the match is underspecified.
713 * The NameOwnerChanged signals take three parameters with
714 * unique or well-known names, but only some forms actually
717 * WELLKNOWN, "", UNIQUE → KDBUS_MATCH_NAME_ADD
718 * WELLKNOWN, UNIQUE, "" → KDBUS_MATCH_NAME_REMOVE
719 * WELLKNOWN, UNIQUE, UNIQUE → KDBUS_MATCH_NAME_CHANGE
720 * UNIQUE, "", UNIQUE → KDBUS_MATCH_ID_ADD
721 * UNIQUE, UNIQUE, "" → KDBUS_MATCH_ID_REMOVE
723 * For the latter two the two unique names must be identical.
728 is_name_id = bus_kernel_parse_unique_name(name, &name_id);
734 r = bus_kernel_parse_unique_name(old_owner, &old_owner_id);
739 if (is_name_id > 0 && old_owner_id != name_id)
744 r = bus_kernel_parse_unique_name(new_owner, &new_owner_id);
749 if (is_name_id > 0 && new_owner_id != name_id)
753 if (is_name_id <= 0) {
754 struct kdbus_cmd_match *m;
757 /* If the name argument is missing or is a well-known
758 * name, then add KDBUS_MATCH_NAME_{ADD,REMOVE,CHANGE}
761 l = name ? strlen(name) : 0;
763 sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) +
764 offsetof(struct kdbus_item, name_change) +
765 offsetof(struct kdbus_notify_name_change, name) +
771 m->src_id = KDBUS_SRC_ID_KERNEL;
775 offsetof(struct kdbus_item, name_change) +
776 offsetof(struct kdbus_notify_name_change, name) +
779 item->name_change.old_id = old_owner_id;
780 item->name_change.new_id = new_owner_id;
783 strcpy(item->name_change.name, name);
785 /* If the old name is unset or empty, then
786 * this can match against added names */
787 if (!old_owner || old_owner[0] == 0) {
788 item->type = KDBUS_MATCH_NAME_ADD;
790 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
795 /* If the new name is unset or empty, then
796 * this can match against removed names */
797 if (!new_owner || new_owner[0] == 0) {
798 item->type = KDBUS_MATCH_NAME_REMOVE;
800 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
805 /* If the neither name is explicitly set to
806 * the empty string, then this can match
807 * agains changed names */
808 if (!(old_owner && old_owner[0] == 0) &&
809 !(new_owner && new_owner[0] == 0)) {
810 item->type = KDBUS_MATCH_NAME_CHANGE;
812 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
818 if (is_name_id != 0) {
819 struct kdbus_cmd_match *m;
822 /* If the name argument is missing or is a unique
823 * name, then add KDBUS_MATCH_ID_{ADD,REMOVE} matches
826 sz = ALIGN8(offsetof(struct kdbus_cmd_match, items) +
827 offsetof(struct kdbus_item, id_change) +
828 sizeof(struct kdbus_notify_id_change));
833 m->src_id = KDBUS_SRC_ID_KERNEL;
836 item->size = offsetof(struct kdbus_item, id_change) + sizeof(struct kdbus_notify_id_change);
837 item->id_change.id = name_id;
839 /* If the old name is unset or empty, then this can
840 * match against added ids */
841 if (!old_owner || old_owner[0] == 0) {
842 item->type = KDBUS_MATCH_ID_ADD;
844 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
849 /* If thew new name is unset or empty, then this can
850 match against removed ids */
851 if (!new_owner || new_owner[0] == 0) {
852 item->type = KDBUS_MATCH_ID_REMOVE;
854 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
863 static int bus_add_match_internal_kernel(
866 struct bus_match_component *components,
867 unsigned n_components,
870 struct kdbus_cmd_match *m;
871 struct kdbus_item *item;
872 uint64_t bloom[BLOOM_SIZE/8];
874 const char *sender = NULL;
875 size_t sender_length = 0;
876 uint64_t src_id = KDBUS_MATCH_SRC_ID_ANY;
877 bool using_bloom = false;
879 bool matches_name_change = true;
880 const char *name_change_arg[3] = {};
888 sz = offsetof(struct kdbus_cmd_match, items);
890 for (i = 0; i < n_components; i++) {
891 struct bus_match_component *c = &components[i];
895 case BUS_MATCH_SENDER:
896 if (!streq(c->value_str, "org.freedesktop.DBus"))
897 matches_name_change = false;
899 r = bus_kernel_parse_unique_name(c->value_str, &src_id);
904 sender = c->value_str;
905 sender_length = strlen(sender);
906 sz += ALIGN8(offsetof(struct kdbus_item, str) + sender_length + 1);
911 case BUS_MATCH_MESSAGE_TYPE:
912 if (c->value_u8 != SD_BUS_MESSAGE_SIGNAL)
913 matches_name_change = false;
915 bloom_add_pair(bloom, "message-type", bus_message_type_to_string(c->value_u8));
919 case BUS_MATCH_INTERFACE:
920 if (!streq(c->value_str, "org.freedesktop.DBus"))
921 matches_name_change = false;
923 bloom_add_pair(bloom, "interface", c->value_str);
927 case BUS_MATCH_MEMBER:
928 if (!streq(c->value_str, "NameOwnerChanged"))
929 matches_name_change = false;
931 bloom_add_pair(bloom, "member", c->value_str);
936 if (!streq(c->value_str, "/org/freedesktop/DBus"))
937 matches_name_change = false;
939 bloom_add_pair(bloom, "path", c->value_str);
943 case BUS_MATCH_PATH_NAMESPACE:
944 if (!streq(c->value_str, "/")) {
945 bloom_add_pair(bloom, "path-slash-prefix", c->value_str);
950 case BUS_MATCH_ARG...BUS_MATCH_ARG_LAST: {
951 char buf[sizeof("arg")-1 + 2 + 1];
953 if (c->type - BUS_MATCH_ARG < 3)
954 name_change_arg[c->type - BUS_MATCH_ARG] = c->value_str;
956 snprintf(buf, sizeof(buf), "arg%u", c->type - BUS_MATCH_ARG);
957 bloom_add_pair(bloom, buf, c->value_str);
962 case BUS_MATCH_ARG_PATH...BUS_MATCH_ARG_PATH_LAST: {
963 char buf[sizeof("arg")-1 + 2 + sizeof("-slash-prefix")];
965 snprintf(buf, sizeof(buf), "arg%u-slash-prefix", c->type - BUS_MATCH_ARG_PATH);
966 bloom_add_pair(bloom, buf, c->value_str);
971 case BUS_MATCH_ARG_NAMESPACE...BUS_MATCH_ARG_NAMESPACE_LAST: {
972 char buf[sizeof("arg")-1 + 2 + sizeof("-dot-prefix")];
974 snprintf(buf, sizeof(buf), "arg%u-dot-prefix", c->type - BUS_MATCH_ARG_NAMESPACE);
975 bloom_add_pair(bloom, buf, c->value_str);
980 case BUS_MATCH_DESTINATION:
981 /* The bloom filter does not include
982 the destination, since it is only
983 available for broadcast messages
984 which do not carry a destination
985 since they are undirected. */
989 case BUS_MATCH_VALUE:
991 case _BUS_MATCH_NODE_TYPE_MAX:
992 case _BUS_MATCH_NODE_TYPE_INVALID:
993 assert_not_reached("Invalid match type?");
998 sz += ALIGN8(offsetof(struct kdbus_item, data64) + BLOOM_SIZE);
1008 item->size = offsetof(struct kdbus_item, data64) + BLOOM_SIZE;
1009 item->type = KDBUS_MATCH_BLOOM;
1010 memcpy(item->data64, bloom, BLOOM_SIZE);
1012 item = KDBUS_ITEM_NEXT(item);
1016 item->size = offsetof(struct kdbus_item, str) + sender_length + 1;
1017 item->type = KDBUS_MATCH_SRC_NAME;
1018 memcpy(item->str, sender, sender_length + 1);
1021 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_ADD, m);
1025 if (matches_name_change) {
1027 /* If this match could theoretically match
1028 * NameOwnerChanged messages, we need to
1029 * install a second non-bloom filter explitly
1032 r = add_name_change_match(bus, cookie, name_change_arg[0], name_change_arg[1], name_change_arg[2]);
1040 static int bus_add_match_internal_dbus1(
1042 const char *match) {
1047 return sd_bus_call_method(
1049 "org.freedesktop.DBus",
1051 "org.freedesktop.DBus",
1059 int bus_add_match_internal(
1062 struct bus_match_component *components,
1063 unsigned n_components,
1070 return bus_add_match_internal_kernel(bus, match, components, n_components, cookie);
1072 return bus_add_match_internal_dbus1(bus, match);
1075 static int bus_remove_match_internal_kernel(
1080 struct kdbus_cmd_match m;
1087 m.size = offsetof(struct kdbus_cmd_match, items);
1090 r = ioctl(bus->input_fd, KDBUS_CMD_MATCH_REMOVE, &m);
1097 static int bus_remove_match_internal_dbus1(
1099 const char *match) {
1104 return sd_bus_call_method(
1106 "org.freedesktop.DBus",
1108 "org.freedesktop.DBus",
1116 int bus_remove_match_internal(
1125 return bus_remove_match_internal_kernel(bus, match, cookie);
1127 return bus_remove_match_internal_dbus1(bus, match);
1130 _public_ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine) {
1131 _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
1135 assert_return(bus, -EINVAL);
1136 assert_return(name, -EINVAL);
1137 assert_return(machine, -EINVAL);
1138 assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
1139 assert_return(!bus_pid_changed(bus), -ECHILD);
1141 if (streq_ptr(name, bus->unique_name))
1142 return sd_id128_get_machine(machine);
1144 r = sd_bus_message_new_method_call(
1148 "org.freedesktop.DBus.Peer",
1149 "GetMachineId", &m);
1153 r = sd_bus_message_set_no_auto_start(m, true);
1157 r = sd_bus_call(bus, m, 0, NULL, &reply);
1161 r = sd_bus_message_read(reply, "s", &mid);
1165 return sd_id128_from_string(mid, machine);