sd-bus.c revision 40ca29a1370379d43e44c0ed425eecc7218dcbca
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering This file is part of systemd.
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering Copyright 2013 Lennart Poettering
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering systemd is free software; you can redistribute it and/or modify it
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering under the terms of the GNU Lesser General Public License as published by
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering (at your option) any later version.
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering systemd is distributed in the hope that it will be useful, but
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering Lesser General Public License for more details.
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering You should have received a copy of the GNU Lesser General Public License
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
#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"
assert(b);
if (b->input_fd >= 0)
struct node_callback *c;
struct node_vtable *v;
struct node_enumerator *e;
assert(b);
while (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);
struct filter_callback *f;
struct node *n;
assert(b);
bus_close_fds(b);
if (b->kdbus_buffer)
for (i = 0; i < b->rqueue_size; i++)
for (i = 0; i < b->wqueue_size; i++)
while ((f = b->filter_callbacks)) {
free(f);
bus_node_destroy(b, n);
free(b);
sd_bus *r;
return -ENOMEM;
if (!r->wqueue) {
free(r);
return -ENOMEM;
*ret = r;
return -ENOMEM;
return -ENOMEM;
free(p);
return -ENOMEM;
return -EBADMSG;
return -ENOMEM;
bus,
size_t l, n = 0;
char *r = NULL;
assert(p);
assert(*p);
if (key) {
if (*value)
return -EINVAL;
free(r);
free(r);
free(r);
return -ENOMEM;
return -ENOMEM;
*value = r;
static void skip_address_key(const char **p) {
assert(p);
assert(*p);
size_t l;
assert(b);
assert(p);
assert(*p);
skip_address_key(p);
return -EINVAL;
return -EINVAL;
if (path) {
return -E2BIG;
} else if (abstract) {
return -E2BIG;
assert(b);
assert(p);
assert(*p);
skip_address_key(p);
return -EINVAL;
if (family) {
return -EINVAL;
if (r == EAI_SYSTEM)
return -errno;
return -EADDRNOTAVAIL;
unsigned n_argv = 0, j;
assert(b);
assert(p);
assert(*p);
goto fail;
goto fail;
unsigned ul;
errno = 0;
r = -EINVAL;
goto fail;
r = -ENOMEM;
goto fail;
argv = x;
goto fail;
skip_address_key(p);
if (!path) {
r = -EINVAL;
goto fail;
if (!argv[j]) {
r = -EINVAL;
goto fail;
if (!argv[0]) {
r = -ENOMEM;
goto fail;
fail:
for (j = 0; j < n_argv; j++)
assert(b);
assert(p);
assert(*p);
skip_address_key(p);
if (!path)
return -EINVAL;
assert(b);
b->sockaddr_size = 0;
assert(b);
if (!b->address)
if (guid) {
assert(b);
sd_bus_close(b);
r = bus_socket_connect(b);
b->last_connect_error = -r;
} else if (b->exec_path) {
r = bus_socket_exec(b);
b->last_connect_error = -r;
} else if (b->kernel) {
r = bus_kernel_connect(b);
b->last_connect_error = -r;
r = bus_parse_next_address(b);
assert(b);
return bus_start_address(b);
assert(b);
return -errno;
return bus_kernel_take_fd(b);
return bus_socket_take_fd(b);
return -EINVAL;
return -EINVAL;
sd_bus *b;
r = sd_bus_new(&b);
r = sd_bus_set_address(b, e);
goto fail;
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);
goto fail;
*ret = b;
fail:
bus_free(b);
sd_bus *b;
size_t l;
r = sd_bus_new(&b);
r = sd_bus_set_address(b, e);
goto fail;
r = -ENOENT;
goto fail;
l = strlen(e);
r = -E2BIG;
goto fail;
b->bus_client = true;
r = sd_bus_start(b);
goto fail;
*ret = b;
fail:
bus_free(b);
if (!bus)
if (!bus)
return NULL;
return bus;
if (!bus)
return NULL;
return NULL;
assert(m);
return -EPERM;
if (m->sealed)
int r, ret = 0;
return ret;
return ret;
int r, ret = 0;
assert(m);
return ret;
return ret;
if (m->n_fds > 0) {
return -ENOTSUP;
sd_bus_message **q;
return -ENOBUFS;
return -ENOMEM;
if (serial)
if (usec == 0)
static int timeout_compare(const void *a, const void *b) {
const struct reply_callback *x = a, *y = b;
sd_bus_message *m,
void *userdata,
struct reply_callback *c;
return -ENOMEM;
free(c);
if (c->timeout != 0) {
c->timeout = 0;
struct reply_callback *c;
if (c->timeout != 0)
free(c);
return -ENOTCONN;
sd_bus_message *m,
bool room = false;
if (!room) {
sd_bus_message **q;
return -ENOBUFS;
return -ENOMEM;
room = true;
if (incoming) {
if (reply)
return -EIO;
room = false;
if (timeout > 0) {
usec_t n;
if (n >= timeout)
return -ETIMEDOUT;
int flags = 0;
return flags;
struct reply_callback *c;
*timeout_usec = 0;
struct reply_callback *c;
usec_t n;
if (c->timeout > n)
bus,
c->serial,
free(c);
assert(m);
return -EIO;
return -EIO;
struct reply_callback *c;
assert(m);
if (c->timeout != 0)
r = sd_bus_message_rewind(m, true);
free(c);
struct filter_callback *l;
assert(m);
r = sd_bus_message_rewind(m, true);
assert(m);
assert(m);
assert(m);
goto null_message;
goto null_message;
goto null_message;
goto null_message;
if (ret) {
r = sd_bus_message_rewind(m, true);
*ret = m;
m = NULL;
bus, m,
if (r >= 0 && ret)
case BUS_UNSET:
case BUS_CLOSED:
return -ENOTCONN;
case BUS_OPENING:
if (ret)
case BUS_AUTHENTICATING:
if (ret)
case BUS_RUNNING:
case BUS_HELLO:
if (need_more)
e |= POLLIN;
m = timeout_usec;
p[0].events = e;
return -errno;
struct filter_callback *f;
return -ENOMEM;
struct filter_callback *f;
free(f);
int sd_bus_add_match(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata) {
unsigned n_components = 0;
goto finish;
goto finish;
r = bus_match_add(&bus->match_callbacks, components, n_components, callback, userdata, cookie, NULL);
int sd_bus_remove_match(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata) {
unsigned n_components = 0;
assert(s);
goto fail;
goto fail;
goto fail;
goto fail;
goto fail;
goto fail;
goto fail;
fail: