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, 0, 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, 0, 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;
118 r = sd_bus_message_new_method_call(
120 "org.freedesktop.DBus",
122 "org.freedesktop.DBus",
128 r = sd_bus_message_new_method_call(
130 "org.freedesktop.DBus",
132 "org.freedesktop.DBus",
133 "ListActivatableNames",
138 r = sd_bus_send_with_reply_and_block(bus, m1, 0, NULL, &reply1);
142 r = sd_bus_send_with_reply_and_block(bus, m2, 0, NULL, &reply2);
146 r = bus_message_read_strv_extend(reply1, &x);
152 r = bus_message_read_strv_extend(reply2, &x);
162 int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner) {
163 _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, 0, NULL, &reply);
190 r = sd_bus_message_read(reply, "s", &found);
207 int sd_bus_get_owner_uid(sd_bus *bus, const char *name, uid_t *uid) {
208 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
219 r = sd_bus_message_new_method_call(
221 "org.freedesktop.DBus",
223 "org.freedesktop.DBus",
224 "GetConnectionUnixUser",
229 r = sd_bus_message_append(m, "s", name);
233 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
237 r = sd_bus_message_read(reply, "u", &u);
245 int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid) {
246 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
257 r = sd_bus_message_new_method_call(
259 "org.freedesktop.DBus",
261 "org.freedesktop.DBus",
262 "GetConnectionUnixProcessID",
267 r = sd_bus_message_append(m, "s", name);
271 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
275 r = sd_bus_message_read(reply, "u", &u);
286 int sd_bus_add_match(sd_bus *bus, const char *match) {
287 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
295 r = sd_bus_message_new_method_call(
297 "org.freedesktop.DBus",
299 "org.freedesktop.DBus",
305 r = sd_bus_message_append(m, "s", match);
309 return sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
312 int sd_bus_remove_match(sd_bus *bus, const char *match) {
313 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
321 r = sd_bus_message_new_method_call(
323 "org.freedesktop.DBus",
325 "org.freedesktop.DBus",
331 r = sd_bus_message_append(m, "s", match);
335 return sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);