sd-bus.c revision 5b12334d35eadf1f45cc3d631fd1a2e72ffaea0a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <endian.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <byteswap.h>
#include <pthread.h>
#include "util.h"
#include "macro.h"
#include "strv.h"
#include "set.h"
#include "missing.h"
#include "sd-bus.h"
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-type.h"
#include "bus-socket.h"
#include "bus-kernel.h"
#include "bus-control.h"
#include "bus-introspect.h"
#include "bus-signature.h"
#include "bus-objects.h"
#include "bus-util.h"
#include "bus-container.h"
static void bus_close_fds(sd_bus *b) {
assert(b);
if (b->input_fd >= 0)
}
struct node_callback *c;
struct node_vtable *v;
struct node_enumerator *e;
assert(b);
if (!n)
return;
while (n->child)
bus_node_destroy(b, n->child);
while ((c = n->callbacks)) {
free(c);
}
while ((v = n->vtables)) {
free(v);
}
while ((e = n->enumerators)) {
free(e);
}
if (n->parent)
free(n);
}
static void bus_reset_queues(sd_bus *b) {
unsigned i;
assert(b);
for (i = 0; i < b->rqueue_size; i++)
sd_bus_message_unref(b->rqueue[i]);
for (i = 0; i < b->wqueue_size; i++)
sd_bus_message_unref(b->wqueue[i]);
b->rqueue_size = b->wqueue_size = 0;
}
struct filter_callback *f;
struct node *n;
assert(b);
bus_close_fds(b);
if (b->kdbus_buffer)
free(b->unique_name);
free(b->auth_buffer);
bus_reset_queues(b);
while ((f = b->filter_callbacks)) {
free(f);
}
while ((n = hashmap_first(b->nodes)))
bus_node_destroy(b, n);
hashmap_free(b->nodes);
free(b);
}
sd_bus *r;
if (!r)
return -ENOMEM;
r->n_ref = REFCNT_INIT;
r->message_version = 1;
r->original_pid = getpid();
/* We guarantee that wqueue always has space for at least one
* entry */
if (!r->wqueue) {
free(r);
return -ENOMEM;
}
*ret = r;
return 0;
}
char *a;
if (!a)
return -ENOMEM;
return 0;
}
return 0;
}
char *p, **a;
if (!p)
return -ENOMEM;
if (!a) {
free(p);
return -ENOMEM;
}
return 0;
}
bus->bus_client = !!b;
return 0;
}
return 0;
}
return 0;
}
!!(mask & (SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID)));
!!(mask & SD_BUS_CREDS_EXE));
!!(mask & SD_BUS_CREDS_CMDLINE));
!!(mask & (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)));
!!(mask & (SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS)));
!!(mask & SD_BUS_CREDS_SELINUX_CONTEXT));
return 0;
}
return 0;
}
bus->anonymous_auth = !!b;
return 0;
}
static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
const char *s;
int r;
if (r < 0)
return r;
if (r > 0)
return -r;
if (r < 0)
return r;
if (!service_name_is_valid(s) || s[0] != ':')
return -EBADMSG;
if (!bus->unique_name)
return -ENOMEM;
return 1;
}
int r;
return 0;
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"Hello",
&m);
if (r < 0)
return r;
}
return 1;
}
return 1;
}
size_t l, n = 0;
const char *a;
char *r = NULL;
assert(p);
assert(*p);
if (key) {
return 0;
if ((*p)[l] != '=')
return 0;
if (*value)
return -EINVAL;
a = *p + l + 1;
} else
a = *p;
while (*a != ';' && *a != ',' && *a != 0) {
char c, *t;
if (*a == '%') {
int x, y;
x = unhexchar(a[1]);
if (x < 0) {
free(r);
return x;
}
y = unhexchar(a[2]);
if (y < 0) {
free(r);
return y;
}
c = (char) ((x << 4) | y);
a += 3;
} else {
c = *a;
a++;
}
t = realloc(r, n + 2);
if (!t) {
free(r);
return -ENOMEM;
}
r = t;
r[n++] = c;
}
if (!r) {
r = strdup("");
if (!r)
return -ENOMEM;
} else
r[n] = 0;
if (*a == ',')
a++;
*p = a;
*value = r;
return 1;
}
static void skip_address_key(const char **p) {
assert(p);
assert(*p);
*p += strcspn(*p, ",");
if (**p == ',')
(*p) ++;
}
size_t l;
int r;
assert(b);
assert(p);
assert(*p);
while (**p != 0 && **p != ';') {
if (r < 0)
return r;
else if (r > 0)
continue;
if (r < 0)
return r;
else if (r > 0)
continue;
if (r < 0)
return r;
else if (r > 0)
continue;
skip_address_key(p);
}
return -EINVAL;
return -EINVAL;
if (path) {
return -E2BIG;
} else if (abstract) {
return -E2BIG;
}
return 0;
}
int r;
};
assert(b);
assert(p);
assert(*p);
while (**p != 0 && **p != ';') {
if (r < 0)
return r;
else if (r > 0)
continue;
if (r < 0)
return r;
else if (r > 0)
continue;
if (r < 0)
return r;
else if (r > 0)
continue;
if (r < 0)
return r;
else if (r > 0)
continue;
skip_address_key(p);
}
return -EINVAL;
if (family) {
else
return -EINVAL;
}
if (r == EAI_SYSTEM)
return -errno;
else if (r != 0)
return -EADDRNOTAVAIL;
return 0;
}
unsigned n_argv = 0, j;
int r;
assert(b);
assert(p);
assert(*p);
while (**p != 0 && **p != ';') {
if (r < 0)
goto fail;
else if (r > 0)
continue;
if (r < 0)
goto fail;
else if (r > 0)
continue;
if (startswith(*p, "argv")) {
unsigned ul;
errno = 0;
r = -EINVAL;
goto fail;
}
(*p) ++;
char **x;
if (!x) {
r = -ENOMEM;
goto fail;
}
argv = x;
}
if (r < 0)
goto fail;
continue;
}
skip_address_key(p);
}
if (!path) {
r = -EINVAL;
goto fail;
}
/* Make sure there are no holes in the array, with the
* exception of argv[0] */
for (j = 1; j < n_argv; j++)
if (!argv[j]) {
r = -EINVAL;
goto fail;
}
if (!argv[0]) {
r = -ENOMEM;
goto fail;
}
}
return 0;
fail:
for (j = 0; j < n_argv; j++)
return r;
}
int r;
assert(b);
assert(p);
assert(*p);
while (**p != 0 && **p != ';') {
if (r < 0)
return r;
else if (r > 0)
continue;
if (r < 0)
return r;
else if (r > 0)
continue;
skip_address_key(p);
}
if (!path)
return -EINVAL;
return 0;
}
int r;
assert(b);
assert(p);
assert(*p);
while (**p != 0 && **p != ';') {
if (r < 0)
return r;
else if (r > 0)
continue;
if (r < 0)
return r;
else if (r > 0)
continue;
skip_address_key(p);
}
if (!machine)
return -EINVAL;
strncpy(b->sockaddr.un.sun_path, "/var/run/dbus/system_bus_socket", sizeof(b->sockaddr.un.sun_path));
b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + sizeof("/var/run/dbus/system_bus_socket") - 1;
return 0;
}
static void bus_reset_parsed_address(sd_bus *b) {
assert(b);
b->sockaddr_size = 0;
b->server_id = SD_ID128_NULL;
}
static int bus_parse_next_address(sd_bus *b) {
const char *a;
int r;
assert(b);
if (!b->address)
return 0;
if (b->address[b->address_index] == 0)
return 0;
a = b->address + b->address_index;
while (*a != 0) {
if (*a == ';') {
a++;
continue;
}
if (startswith(a, "unix:")) {
a += 5;
r = parse_unix_address(b, &a, &guid);
if (r < 0)
return r;
break;
} else if (startswith(a, "tcp:")) {
a += 4;
r = parse_tcp_address(b, &a, &guid);
if (r < 0)
return r;
break;
} else if (startswith(a, "unixexec:")) {
a += 9;
r = parse_exec_address(b, &a, &guid);
if (r < 0)
return r;
break;
} else if (startswith(a, "kernel:")) {
a += 7;
r = parse_kernel_address(b, &a, &guid);
if (r < 0)
return r;
break;
} else if (startswith(a, "x-container:")) {
a += 12;
r = parse_container_address(b, &a, &guid);
if (r < 0)
return r;
break;
}
a = strchr(a, ';');
if (!a)
return 0;
}
if (guid) {
if (r < 0)
return r;
}
b->address_index = a - b->address;
return 1;
}
static int bus_start_address(sd_bus *b) {
int r;
assert(b);
for (;;) {
sd_bus_close(b);
if (b->exec_path) {
r = bus_socket_exec(b);
if (r >= 0)
return r;
b->last_connect_error = -r;
} else if (b->kernel) {
r = bus_kernel_connect(b);
if (r >= 0)
return r;
b->last_connect_error = -r;
} else if (b->machine) {
r = bus_container_connect(b);
if (r >= 0)
return r;
b->last_connect_error = -r;
r = bus_socket_connect(b);
if (r >= 0)
return r;
b->last_connect_error = -r;
}
r = bus_parse_next_address(b);
if (r < 0)
return r;
if (r == 0)
}
}
int bus_next_address(sd_bus *b) {
assert(b);
return bus_start_address(b);
}
static int bus_start_fd(sd_bus *b) {
int r;
assert(b);
r = fd_nonblock(b->input_fd, true);
if (r < 0)
return r;
r = fd_cloexec(b->input_fd, true);
if (r < 0)
return r;
r = fd_nonblock(b->output_fd, true);
if (r < 0)
return r;
r = fd_cloexec(b->output_fd, true);
if (r < 0)
return r;
}
return -errno;
return bus_kernel_take_fd(b);
else
return bus_socket_take_fd(b);
}
int r;
return -EINVAL;
r = bus_start_fd(bus);
else if (bus->address || bus->sockaddr.sa.sa_family != AF_UNSPEC || bus->exec_path || bus->kernel || bus->machine)
r = bus_start_address(bus);
else
return -EINVAL;
if (r < 0)
return r;
return bus_send_hello(bus);
}
const char *e;
sd_bus *b;
int r;
r = sd_bus_new(&b);
if (r < 0)
return r;
e = secure_getenv("DBUS_SYSTEM_BUS_ADDRESS");
if (e) {
r = sd_bus_set_address(b, e);
if (r < 0)
goto fail;
} else {
b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + sizeof("/run/dbus/system_bus_socket") - 1;
}
b->bus_client = true;
r = sd_bus_start(b);
if (r < 0)
goto fail;
*ret = b;
return 0;
fail:
bus_free(b);
return r;
}
const char *e;
sd_bus *b;
size_t l;
int r;
r = sd_bus_new(&b);
if (r < 0)
return r;
e = secure_getenv("DBUS_SESSION_BUS_ADDRESS");
if (e) {
r = sd_bus_set_address(b, e);
if (r < 0)
goto fail;
} else {
e = secure_getenv("XDG_RUNTIME_DIR");
if (!e) {
r = -ENOENT;
goto fail;
}
l = strlen(e);
r = -E2BIG;
goto fail;
}
}
b->bus_client = true;
r = sd_bus_start(b);
if (r < 0)
goto fail;
*ret = b;
return 0;
fail:
bus_free(b);
return r;
}
_cleanup_free_ char *e = NULL;
char *p = NULL;
int r;
e = bus_address_escape(host);
if (!e)
return -ENOMEM;
if (!p)
return -ENOMEM;
r = sd_bus_new(&bus);
if (r < 0) {
free(p);
return r;
}
bus->bus_client = true;
r = sd_bus_start(bus);
if (r < 0) {
return r;
}
return 0;
}
_cleanup_free_ char *e = NULL;
char *p;
int r;
e = bus_address_escape(machine);
if (!e)
return -ENOMEM;
if (!p)
return -ENOMEM;
r = sd_bus_new(&bus);
if (r < 0) {
free(p);
return r;
}
bus->bus_client = true;
r = sd_bus_start(bus);
if (r < 0) {
return r;
}
return 0;
}
if (!bus)
return;
return;
if (bus_pid_changed(bus))
return;
/* Drop all queued messages so that they drop references to
* the bus object and the bus may be freed */
/* We'll leave the fd open in case this is a kernel bus, since
* there might still be memblocks around that reference this
* bus, and they might need to invoke the
* KDBUS_CMD_MSG_RELEASE ioctl on the fd when they are
* freed. */
}
return;
}
return bus;
}
return NULL;
}
}
int r;
if (type == SD_BUS_TYPE_UNIX_FD) {
return 0;
r = bus_ensure_running(bus);
if (r < 0)
return r;
}
return bus_type_is_valid(type);
}
int r;
r = bus_ensure_running(bus);
if (r < 0)
return r;
return 0;
}
assert(m);
return -EPERM;
if (m->sealed) {
/* If we copy the same message to multiple
* destinations, avoid using the same serial
* numbers. */
return 0;
}
return bus_message_seal(m, ++b->serial);
}
int r;
else
return r;
}
int r, ret = 0;
while (bus->wqueue_size > 0) {
if (r < 0)
return r;
else if (r == 0)
/* Didn't do anything this time */
return ret;
/* Fully written. Let's drop the entry from
* the queue.
*
* This isn't particularly optimized, but
* well, this is supposed to be our worst-case
* buffer only, and the socket buffer is
* supposed to be our primary buffer, and if
* it got full, then all bets are off
* anyway. */
bus->wqueue_size --;
ret = 1;
}
}
return ret;
}
int r;
assert(m);
r = bus_kernel_read_message(bus, m);
else
r = bus_socket_read_message(bus, m);
return r;
}
sd_bus_message *z = NULL;
int r, ret = 0;
assert(m);
if (bus->rqueue_size > 0) {
/* Dispatch a queued message */
bus->rqueue_size --;
return 1;
}
/* Try to read a new message */
do {
r = bus_read_message(bus, &z);
if (r < 0)
return r;
if (r == 0)
return ret;
ret = 1;
} while (!z);
*m = z;
return ret;
}
int r;
assert_return(m, -EINVAL);
if (m->n_fds > 0) {
if (r < 0)
return r;
if (r == 0)
return -ENOTSUP;
}
/* If the serial number isn't kept, then we know that no reply
* is expected */
r = bus_seal_message(bus, m);
if (r < 0)
return r;
/* If this is a reply and no reply was requested, then let's
* suppress this, if we can */
return 1;
if (r < 0)
return r;
/* Wasn't fully written. So let's remember how
* much was written. Note that the first entry
* of the wqueue array is always allocated so
* that we always can remember how much was
* written. */
}
} else {
sd_bus_message **q;
/* Just append it to the queue. */
return -ENOBUFS;
if (!q)
return -ENOMEM;
}
if (serial)
*serial = BUS_MESSAGE_SERIAL(m);
return 1;
}
_public_ int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destination, uint64_t *serial) {
int r;
assert_return(m, -EINVAL);
if (!destination)
return -EEXIST;
if (r < 0)
return r;
}
}
return 0;
if (usec == 0)
}
static int timeout_compare(const void *a, const void *b) {
const struct reply_callback *x = a, *y = b;
return -1;
return 1;
return -1;
return 1;
return 0;
}
sd_bus_message *m,
void *userdata,
struct reply_callback *c;
int r;
assert_return(m, -EINVAL);
if (r < 0)
return r;
if (r < 0)
return r;
}
r = bus_seal_message(bus, m);
if (r < 0)
return r;
if (!c)
return -ENOMEM;
c->serial = BUS_MESSAGE_SERIAL(m);
if (r < 0) {
free(c);
return r;
}
if (c->timeout != 0) {
if (r < 0) {
c->timeout = 0;
return r;
}
}
if (r < 0) {
return r;
}
return r;
}
struct reply_callback *c;
if (!c)
return 0;
if (c->timeout != 0)
free(c);
return 1;
}
int r;
return -ENOTCONN;
return 1;
for (;;) {
if (r < 0)
return r;
return 1;
if (r > 0)
continue;
if (r < 0)
return r;
}
}
_public_ int sd_bus_call(
sd_bus_message *m,
sd_bus_message **reply) {
int r;
bool room = false;
assert_return(m, -EINVAL);
r = bus_ensure_running(bus);
if (r < 0)
return r;
if (r < 0)
return r;
for (;;) {
if (!room) {
sd_bus_message **q;
return -ENOBUFS;
/* Make sure there's room for queuing this
* locally, before we read the message */
if (!q)
return -ENOMEM;
room = true;
}
if (r < 0)
return r;
if (incoming) {
/* Found a match! */
if (reply)
else
return 1;
}
int k;
if (r < 0) {
return r;
}
return -k;
}
return -EIO;
bus->unique_name &&
/* Our own message? Somebody is trying
* to send its own client a message,
* let's not dead-lock, let's fail
* immediately. */
return -ELOOP;
}
/* There's already guaranteed to be room for
* this, so need to resize things here */
room = false;
/* Try to read more, right-away */
continue;
}
if (r != 0)
continue;
if (timeout > 0) {
usec_t n;
n = now(CLOCK_MONOTONIC);
if (n >= timeout)
return -ETIMEDOUT;
} else
if (r < 0)
return r;
r = dispatch_wqueue(bus);
if (r < 0)
return r;
}
}
}
int flags = 0;
if (bus->rqueue_size <= 0)
if (bus->wqueue_size > 0)
}
return flags;
}
struct reply_callback *c;
*timeout_usec = 0;
return 1;
}
return 1;
}
return 0;
}
if (bus->rqueue_size > 0) {
*timeout_usec = 0;
return 1;
}
if (!c) {
return 0;
}
*timeout_usec = c->timeout;
return 1;
}
struct reply_callback *c;
usec_t n;
int r;
if (!c)
return 0;
n = now(CLOCK_MONOTONIC);
if (c->timeout > n)
return 0;
bus,
c->serial,
&m);
if (r < 0)
return r;
r = bus_seal_message(bus, m);
if (r < 0)
return r;
bus->iteration_counter ++;
r = bus_maybe_reply_error(m, r, &error_buffer);
free(c);
return r;
}
assert(m);
return 0;
/* Let's make sure the first message on the bus is the HELLO
* reply. But note that we don't actually parse the message
* here (we leave that to the usual handling), we just verify
* we don't let any earlier msg through. */
return -EIO;
return -EIO;
return 0;
}
struct reply_callback *c;
int r;
assert(m);
return 0;
if (!c)
return 0;
if (c->timeout != 0)
r = sd_bus_message_rewind(m, true);
if (r < 0)
return r;
r = bus_maybe_reply_error(m, r, &error_buffer);
free(c);
return r;
}
struct filter_callback *l;
int r;
assert(m);
do {
bus->filter_callbacks_modified = false;
if (bus->filter_callbacks_modified)
break;
/* Don't run this more than once per iteration */
continue;
r = sd_bus_message_rewind(m, true);
if (r < 0)
return r;
r = bus_maybe_reply_error(m, r, &error_buffer);
if (r != 0)
return r;
}
} while (bus->filter_callbacks_modified);
return 0;
}
int r;
assert(m);
do {
bus->match_callbacks_modified = false;
if (r != 0)
return r;
} while (bus->match_callbacks_modified);
return 0;
}
int r;
assert(m);
return 0;
return 0;
return 1;
r = sd_bus_message_new_method_return(m, &reply);
char sid[33];
r = sd_id128_get_machine(&id);
if (r < 0)
return r;
r = sd_bus_message_new_method_return(m, &reply);
if (r < 0)
return r;
} else {
m, &reply,
}
if (r < 0)
return r;
if (r < 0)
return r;
return 1;
}
int r;
assert(m);
bus->iteration_counter++;
log_debug("Got message sender=%s object=%s interface=%s member=%s",
r = process_hello(bus, m);
if (r != 0)
goto finish;
r = process_reply(bus, m);
if (r != 0)
goto finish;
r = process_filter(bus, m);
if (r != 0)
goto finish;
r = process_match(bus, m);
if (r != 0)
goto finish;
r = process_builtin(bus, m);
if (r != 0)
goto finish;
r = bus_process_object(bus, m);
return r;
}
int r;
r = process_timeout(bus);
if (r != 0)
goto null_message;
r = dispatch_wqueue(bus);
if (r != 0)
goto null_message;
r = dispatch_rqueue(bus, &m);
if (r < 0)
return r;
if (!m)
goto null_message;
r = process_message(bus, m);
if (r != 0)
goto null_message;
if (ret) {
r = sd_bus_message_rewind(m, true);
if (r < 0)
return r;
*ret = m;
m = NULL;
return 1;
}
m,
"Unknown object '%s'.", m->path);
if (r < 0)
return r;
}
return 1;
if (r >= 0 && ret)
return r;
}
struct reply_callback *c;
int r;
if (c) {
/* First, fail all outstanding method calls */
bus,
c->serial,
&m);
if (r < 0)
return r;
r = bus_seal_message(bus, m);
if (r < 0)
return r;
if (c->timeout != 0)
bus->iteration_counter++;
r = bus_maybe_reply_error(m, r, &error_buffer);
free(c);
goto finish;
}
/* Then, synthesize a Disconnected message */
bus,
"/org/freedesktop/DBus/Local",
"org.freedesktop.DBus.Local",
"Disconnected",
&m);
if (r < 0)
return r;
r = bus_seal_message(bus, m);
if (r < 0)
return r;
bus->iteration_counter++;
r = process_filter(bus, m);
if (r != 0)
goto finish;
r = process_match(bus, m);
if (r != 0)
goto finish;
if (ret) {
*ret = m;
m = NULL;
}
r = 1;
return r;
}
int r;
/* Returns 0 when we didn't do anything. This should cause the
* caller to invoke sd_bus_wait() before returning the next
* time. Returns > 0 when we did something, which possibly
* means *ret is filled in with an unprocessed message. */
/* We don't allow recursively invoking sd_bus_process(). */
case BUS_UNSET:
case BUS_CLOSED:
return -ENOTCONN;
case BUS_OPENING:
if (r == -ECONNRESET || r == -EPIPE) {
r = 1;
} else if (r < 0)
return r;
if (ret)
return r;
case BUS_AUTHENTICATING:
if (r == -ECONNRESET || r == -EPIPE) {
r = 1;
} else if (r < 0)
return r;
if (ret)
return r;
case BUS_RUNNING:
case BUS_HELLO:
if (r == -ECONNRESET || r == -EPIPE) {
r = 1;
if (ret)
}
return r;
case BUS_CLOSING:
}
assert_not_reached("Unknown state");
}
struct pollfd p[2] = {};
int r, e, n;
return 1;
e = sd_bus_get_events(bus);
if (e < 0)
return e;
if (need_more)
/* The caller really needs some more data, he doesn't
* care about what's already read, or any timeouts
* except its own.*/
e |= POLLIN;
else {
/* The caller wants to process if there's something to
* process, but doesn't care otherwise */
if (r < 0)
return r;
if (r > 0) {
}
}
m = timeout_usec;
p[0].events = e;
n = 1;
} else {
n = 2;
}
if (r < 0)
return -errno;
return r > 0 ? 1 : 0;
}
return 0;
if (bus->rqueue_size > 0)
return 0;
}
int r;
return 0;
r = bus_ensure_running(bus);
if (r < 0)
return r;
if (bus->wqueue_size <= 0)
return 0;
for (;;) {
r = dispatch_wqueue(bus);
if (r < 0)
return r;
if (bus->wqueue_size <= 0)
return 0;
if (r < 0)
return r;
}
}
void *userdata) {
struct filter_callback *f;
if (!f)
return -ENOMEM;
bus->filter_callbacks_modified = true;
return 0;
}
void *userdata) {
struct filter_callback *f;
bus->filter_callbacks_modified = true;
free(f);
return 1;
}
}
return 0;
}
const char *match,
void *userdata) {
unsigned n_components = 0;
int r = 0;
if (r < 0)
goto finish;
if (bus->bus_client) {
if (r < 0)
goto finish;
}
bus->match_callbacks_modified = true;
r = bus_match_add(&bus->match_callbacks, components, n_components, callback, userdata, cookie, NULL);
if (r < 0) {
if (bus->bus_client)
}
return r;
}
const char *match,
void *userdata) {
unsigned n_components = 0;
int r = 0, q = 0;
if (r < 0)
return r;
bus->match_callbacks_modified = true;
if (bus->bus_client)
return r < 0 ? r : q;
}
/* We don't support people creating a bus connection and
* keeping it around over a fork(). Let's complain. */
}
int r;
if (r < 0)
return r;
return 1;
}
int r;
if (r < 0)
return r;
return 1;
}
int r, e;
assert(s);
e = sd_bus_get_events(bus);
if (e < 0)
return e;
if (r < 0)
return r;
if (r < 0)
return r;
} else {
if (r < 0)
return r;
}
if (r < 0)
return r;
if (r > 0) {
int j;
if (j < 0)
return j;
}
if (r < 0)
return r;
return 1;
}
return 1;
}
int r;
if (event)
else {
if (r < 0)
return r;
}
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
}
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
if (r < 0)
goto fail;
return 0;
fail:
return r;
}
if (bus->input_io_event_source) {
}
if (bus->output_io_event_source) {
}
if (bus->time_event_source) {
}
if (bus->quit_event_source) {
}
return 0;
}
}
}
int r;
if (!ret)
return !!*default_bus;
if (*default_bus) {
return 0;
}
r = bus_open(&b);
if (r < 0)
return r;
b->default_bus_ptr = default_bus;
*default_bus = b;
*ret = b;
return 1;
}
}
}
assert_return(b, -EINVAL);
if (b->tid != 0) {
return 0;
}
if (b->event)
return -ENXIO;
}
_public_ char *sd_bus_label_escape(const char *s) {
char *r, *t;
const char *f;
assert_return(s, NULL);
/* Escapes all chars that D-Bus' object path cannot deal
* with. Can be reversed with bus_path_unescape(). We special
* case the empty string. */
if (*s == 0)
return strdup("_");
if (!r)
return NULL;
for (f = s, t = r; *f; f++) {
/* Escape everything that is not a-zA-Z0-9. We also
* escape 0-9 if it's the first character */
if (!(*f >= 'A' && *f <= 'Z') &&
!(*f >= 'a' && *f <= 'z') &&
!(f > s && *f >= '0' && *f <= '9')) {
*(t++) = '_';
*(t++) = hexchar(*f >> 4);
*(t++) = hexchar(*f);
} else
*(t++) = *f;
}
*t = 0;
return r;
}
_public_ char *sd_bus_label_unescape(const char *f) {
char *r, *t;
assert_return(f, NULL);
/* Special case for the empty string */
if (streq(f, "_"))
return strdup("");
if (!r)
return NULL;
for (t = r; *f; f++) {
if (*f == '_') {
int a, b;
if ((a = unhexchar(f[1])) < 0 ||
(b = unhexchar(f[2])) < 0) {
/* Invalid escape code, let's take it literal then */
*(t++) = '_';
} else {
*(t++) = (char) ((a << 4) | b);
f += 2;
}
} else
*(t++) = *f;
}
*t = 0;
return r;
}
sd_bus_creds *c;
int r;
return -ENODATA;
c = bus_creds_new();
if (!c)
return -ENOMEM;
if (bus->ucred_valid) {
}
if (!c->label) {
return -ENOMEM;
}
}
if (r < 0)
return r;
*ret = c;
return 0;
}