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/>.
28 #include "bus-internal.h"
29 #include "bus-message.h"
31 const char *sd_bus_get_unique_name(sd_bus *bus) {
35 return bus->unique_name;
38 int sd_bus_request_name(sd_bus *bus, const char *name, int flags) {
39 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
48 r = sd_bus_message_new_method_call(
50 "org.freedesktop.DBus",
52 "org.freedesktop.DBus",
58 r = sd_bus_message_append(m, "su", name, flags);
62 r = sd_bus_send_with_reply_and_block(bus, m, (uint64_t) -1, NULL, &reply);
66 r = sd_bus_message_read(reply, "u", &ret);
73 int sd_bus_release_name(sd_bus *bus, const char *name) {
74 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
83 r = sd_bus_message_new_method_call(
85 "org.freedesktop.DBus",
87 "org.freedesktop.DBus",
93 r = sd_bus_message_append(m, "s", name);
97 r = sd_bus_send_with_reply_and_block(bus, m, (uint64_t) -1, NULL, &reply);
101 r = sd_bus_message_read(reply, "u", &ret);
108 int sd_bus_list_names(sd_bus *bus, char ***l) {
109 _cleanup_bus_message_unref_ sd_bus_message *m1 = NULL, *reply1 = NULL, *m2 = NULL, *reply2 = NULL;
110 _cleanup_strv_free_ char **a = NULL, **b = NULL;
119 r = sd_bus_message_new_method_call(
121 "org.freedesktop.DBus",
123 "org.freedesktop.DBus",
129 r = sd_bus_message_new_method_call(
131 "org.freedesktop.DBus",
133 "org.freedesktop.DBus",
134 "ListActivatableNames",
139 r = sd_bus_send_with_reply_and_block(bus, m1, (uint64_t) -1, NULL, &reply1);
143 r = sd_bus_send_with_reply_and_block(bus, m2, (uint64_t) -1, NULL, &reply2);
147 r = sd_bus_message_read(reply1, "as", &a);
151 r = sd_bus_message_read(reply2, "as", &b);
155 x = strv_merge(a, b);
163 int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner) {
164 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
172 r = sd_bus_message_new_method_call(
174 "org.freedesktop.DBus",
176 "org.freedesktop.DBus",
182 r = sd_bus_message_append(m, "s", name);
186 r = sd_bus_send_with_reply_and_block(bus, m, (uint64_t) -1, NULL, &reply);
190 return sd_bus_message_read(reply, "s", owner);
193 int sd_bus_get_owner_uid(sd_bus *bus, const char *name, uid_t *uid) {
194 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
205 r = sd_bus_message_new_method_call(
207 "org.freedesktop.DBus",
209 "org.freedesktop.DBus",
210 "GetConnectionUnixUser",
215 r = sd_bus_message_append(m, "s", name);
219 r = sd_bus_send_with_reply_and_block(bus, m, (uint64_t) -1, NULL, &reply);
223 r = sd_bus_message_read(reply, "u", &u);
231 int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid) {
232 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
243 r = sd_bus_message_new_method_call(
245 "org.freedesktop.DBus",
247 "org.freedesktop.DBus",
248 "GetConnectionUnixUser",
253 r = sd_bus_message_append(m, "s", name);
257 r = sd_bus_send_with_reply_and_block(bus, m, (uint64_t) -1, NULL, &reply);
261 r = sd_bus_message_read(reply, "u", &u);
272 int sd_bus_add_match(sd_bus *bus, const char *match) {
273 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
281 r = sd_bus_message_new_method_call(
283 "org.freedesktop.DBus",
285 "org.freedesktop.DBus",
291 r = sd_bus_message_append(m, "s", match);
295 return sd_bus_send_with_reply_and_block(bus, m, (uint64_t) -1, NULL, &reply);
298 int sd_bus_remove_match(sd_bus *bus, const char *match) {
299 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
307 r = sd_bus_message_new_method_call(
309 "org.freedesktop.DBus",
311 "org.freedesktop.DBus",
317 r = sd_bus_message_append(m, "s", match);
321 return sd_bus_send_with_reply_and_block(bus, m, (uint64_t) -1, NULL, &reply);