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"
30 #include "bus-control.h"
32 int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
40 r = bus_ensure_running(bus);
44 *unique = bus->unique_name;
48 int sd_bus_request_name(sd_bus *bus, const char *name, int flags) {
49 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
58 r = sd_bus_message_new_method_call(
60 "org.freedesktop.DBus",
62 "org.freedesktop.DBus",
68 r = sd_bus_message_append(m, "su", name, flags);
72 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
76 r = sd_bus_message_read(reply, "u", &ret);
83 int sd_bus_release_name(sd_bus *bus, const char *name) {
84 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
93 r = sd_bus_message_new_method_call(
95 "org.freedesktop.DBus",
97 "org.freedesktop.DBus",
103 r = sd_bus_message_append(m, "s", name);
107 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
111 r = sd_bus_message_read(reply, "u", &ret);
118 int sd_bus_list_names(sd_bus *bus, char ***l) {
119 _cleanup_bus_message_unref_ sd_bus_message *m1 = NULL, *reply1 = NULL, *m2 = NULL, *reply2 = NULL;
128 r = sd_bus_message_new_method_call(
130 "org.freedesktop.DBus",
132 "org.freedesktop.DBus",
138 r = sd_bus_message_new_method_call(
140 "org.freedesktop.DBus",
142 "org.freedesktop.DBus",
143 "ListActivatableNames",
148 r = sd_bus_send_with_reply_and_block(bus, m1, 0, NULL, &reply1);
152 r = sd_bus_send_with_reply_and_block(bus, m2, 0, NULL, &reply2);
156 r = bus_message_read_strv_extend(reply1, &x);
162 r = bus_message_read_strv_extend(reply2, &x);
172 int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner) {
173 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
182 r = sd_bus_message_new_method_call(
184 "org.freedesktop.DBus",
186 "org.freedesktop.DBus",
192 r = sd_bus_message_append(m, "s", name);
196 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
200 r = sd_bus_message_read(reply, "s", &found);
217 int sd_bus_get_owner_uid(sd_bus *bus, const char *name, uid_t *uid) {
218 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
229 r = sd_bus_message_new_method_call(
231 "org.freedesktop.DBus",
233 "org.freedesktop.DBus",
234 "GetConnectionUnixUser",
239 r = sd_bus_message_append(m, "s", name);
243 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
247 r = sd_bus_message_read(reply, "u", &u);
255 int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid) {
256 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
267 r = sd_bus_message_new_method_call(
269 "org.freedesktop.DBus",
271 "org.freedesktop.DBus",
272 "GetConnectionUnixProcessID",
277 r = sd_bus_message_append(m, "s", name);
281 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
285 r = sd_bus_message_read(reply, "u", &u);
296 int bus_add_match_internal(sd_bus *bus, const char *match) {
297 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
303 r = sd_bus_message_new_method_call(
305 "org.freedesktop.DBus",
307 "org.freedesktop.DBus",
313 r = sd_bus_message_append(m, "s", match);
317 return sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
320 int bus_remove_match_internal(sd_bus *bus, const char *match) {
321 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
327 r = sd_bus_message_new_method_call(
329 "org.freedesktop.DBus",
331 "org.freedesktop.DBus",
337 r = sd_bus_message_append(m, "s", match);
341 return sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);