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 int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
39 r = bus_ensure_running(bus);
43 *unique = bus->unique_name;
47 int sd_bus_request_name(sd_bus *bus, const char *name, int flags) {
48 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
57 r = sd_bus_message_new_method_call(
59 "org.freedesktop.DBus",
61 "org.freedesktop.DBus",
67 r = sd_bus_message_append(m, "su", name, flags);
71 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
75 r = sd_bus_message_read(reply, "u", &ret);
82 int sd_bus_release_name(sd_bus *bus, const char *name) {
83 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
92 r = sd_bus_message_new_method_call(
94 "org.freedesktop.DBus",
96 "org.freedesktop.DBus",
102 r = sd_bus_message_append(m, "s", name);
106 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
110 r = sd_bus_message_read(reply, "u", &ret);
117 int sd_bus_list_names(sd_bus *bus, char ***l) {
118 _cleanup_bus_message_unref_ sd_bus_message *m1 = NULL, *reply1 = NULL, *m2 = NULL, *reply2 = NULL;
127 r = sd_bus_message_new_method_call(
129 "org.freedesktop.DBus",
131 "org.freedesktop.DBus",
137 r = sd_bus_message_new_method_call(
139 "org.freedesktop.DBus",
141 "org.freedesktop.DBus",
142 "ListActivatableNames",
147 r = sd_bus_send_with_reply_and_block(bus, m1, 0, NULL, &reply1);
151 r = sd_bus_send_with_reply_and_block(bus, m2, 0, NULL, &reply2);
155 r = bus_message_read_strv_extend(reply1, &x);
161 r = bus_message_read_strv_extend(reply2, &x);
171 int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner) {
172 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
181 r = sd_bus_message_new_method_call(
183 "org.freedesktop.DBus",
185 "org.freedesktop.DBus",
191 r = sd_bus_message_append(m, "s", name);
195 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
199 r = sd_bus_message_read(reply, "s", &found);
216 int sd_bus_get_owner_uid(sd_bus *bus, const char *name, uid_t *uid) {
217 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
228 r = sd_bus_message_new_method_call(
230 "org.freedesktop.DBus",
232 "org.freedesktop.DBus",
233 "GetConnectionUnixUser",
238 r = sd_bus_message_append(m, "s", name);
242 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
246 r = sd_bus_message_read(reply, "u", &u);
254 int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid) {
255 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
266 r = sd_bus_message_new_method_call(
268 "org.freedesktop.DBus",
270 "org.freedesktop.DBus",
271 "GetConnectionUnixProcessID",
276 r = sd_bus_message_append(m, "s", name);
280 r = sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
284 r = sd_bus_message_read(reply, "u", &u);
295 int sd_bus_add_match(sd_bus *bus, const char *match) {
296 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
304 r = sd_bus_message_new_method_call(
306 "org.freedesktop.DBus",
308 "org.freedesktop.DBus",
314 r = sd_bus_message_append(m, "s", match);
318 return sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);
321 int sd_bus_remove_match(sd_bus *bus, const char *match) {
322 _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
330 r = sd_bus_message_new_method_call(
332 "org.freedesktop.DBus",
334 "org.freedesktop.DBus",
340 r = sd_bus_message_append(m, "s", match);
344 return sd_bus_send_with_reply_and_block(bus, m, 0, NULL, &reply);