bus-control.c revision c78196699d3d805b2237896a1d2b8efeec6068d0
/*-*- 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/>.
***/
#ifdef HAVE_VALGRIND_MEMCHECK_H
#include <valgrind/memcheck.h>
#endif
#include <stddef.h>
#include <errno.h>
#include "strv.h"
#include "sd-bus.h"
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-control.h"
#include "bus-bloom.h"
int r;
if (!bus)
return -EINVAL;
if (!unique)
return -EINVAL;
if (bus_pid_changed(bus))
return -ECHILD;
r = bus_ensure_running(bus);
if (r < 0)
return r;
return 0;
}
int r;
if (!bus)
return -EINVAL;
if (!name)
return -EINVAL;
if (!bus->bus_client)
return -EINVAL;
return -ENOTCONN;
if (bus_pid_changed(bus))
return -ECHILD;
struct kdbus_cmd_name *n;
size_t l;
n->name_flags = flags;
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(n, n->size);
#endif
if (r < 0)
return -errno;
return n->name_flags;
} else {
r = sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"RequestName",
NULL,
&reply,
"su",
name,
flags);
if (r < 0)
return r;
if (r < 0)
return r;
return ret;
}
}
int r;
if (!bus)
return -EINVAL;
if (!name)
return -EINVAL;
if (!bus->bus_client)
return -EINVAL;
return -ENOTCONN;
if (bus_pid_changed(bus))
return -ECHILD;
struct kdbus_cmd_name *n;
size_t l;
#ifdef HAVE_VALGRIND_MEMCHECK_H
VALGRIND_MAKE_MEM_DEFINED(n, n->size);
#endif
if (r < 0)
return -errno;
return n->name_flags;
} else {
r = sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"ReleaseName",
NULL,
&reply,
"s",
name);
if (r < 0)
return r;
if (r < 0)
return r;
}
return ret;
}
char **x = NULL;
int r;
if (!bus)
return -EINVAL;
if (!l)
return -EINVAL;
return -ENOTCONN;
if (bus_pid_changed(bus))
return -ECHILD;
r = sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"ListNames",
NULL,
&reply1,
NULL);
if (r < 0)
return r;
r = sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"ListActivatableNames",
NULL,
&reply2,
NULL);
if (r < 0)
return r;
r = bus_message_read_strv_extend(reply1, &x);
if (r < 0) {
strv_free(x);
return r;
}
r = bus_message_read_strv_extend(reply2, &x);
if (r < 0) {
strv_free(x);
return r;
}
*l = strv_uniq(x);
return 0;
}
const char *found;
int r;
if (!bus)
return -EINVAL;
if (!name)
return -EINVAL;
return -ENOTCONN;
if (bus_pid_changed(bus))
return -ECHILD;
r = sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"GetNameOwner",
NULL,
&reply,
"s",
name);
if (r < 0)
return r;
if (r < 0)
return r;
if (owner) {
char *t;
if (!t)
return -ENOMEM;
*owner = t;
}
return 0;
}
uint32_t u;
int r;
if (!bus)
return -EINVAL;
if (!name)
return -EINVAL;
if (!uid)
return -EINVAL;
return -ENOTCONN;
if (bus_pid_changed(bus))
return -ECHILD;
r = sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"GetConnectionUnixUser",
NULL,
&reply,
"s",
name);
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
}
uint32_t u;
int r;
if (!bus)
return -EINVAL;
if (!name)
return -EINVAL;
if (!pid)
return -EINVAL;
return -ENOTCONN;
if (bus_pid_changed(bus))
return -ECHILD;
r = sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"GetConnectionUnixProcessID",
NULL,
&reply,
"s",
name);
if (r < 0)
return r;
if (r < 0)
return r;
if (u == 0)
return -EIO;
return 0;
}
const char *match,
struct bus_match_component *components,
unsigned n_components,
int r;
struct kdbus_cmd_match *m;
struct kdbus_item *item;
size_t sender_length = 0;
bool using_bloom = false;
unsigned i;
for (i = 0; i < n_components; i++) {
struct bus_match_component *c = &components[i];
switch (c->type) {
case BUS_MATCH_SENDER:
if (r < 0)
return r;
if (r > 0) {
}
break;
case BUS_MATCH_DESTINATION:
/* The bloom filter does not include
the destination, since it is only
available for broadcast messages
which do not carry a destination
since they are undirected. */
break;
case BUS_MATCH_INTERFACE:
using_bloom = true;
break;
case BUS_MATCH_MEMBER:
using_bloom = true;
break;
case BUS_MATCH_PATH:
using_bloom = true;
break;
case BUS_MATCH_PATH_NAMESPACE:
using_bloom = true;
break;
case BUS_MATCH_ARG...BUS_MATCH_ARG_LAST:
case BUS_MATCH_MESSAGE_TYPE:
assert_not_reached("FIXME!");
break;
case BUS_MATCH_ROOT:
case BUS_MATCH_VALUE:
case BUS_MATCH_LEAF:
case _BUS_MATCH_NODE_TYPE_MAX:
assert_not_reached("Invalid match type?");
}
}
if (using_bloom)
if (using_bloom) {
}
if (sender) {
}
if (r < 0)
return -errno;
} else {
return sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"AddMatch",
NULL,
NULL,
"s",
match);
}
return 0;
}
const char *match,
int r;
struct kdbus_cmd_match m;
zero(m);
if (r < 0)
return -errno;
} else {
return sd_bus_call_method(
bus,
"org.freedesktop.DBus",
"/",
"org.freedesktop.DBus",
"RemoveMatch",
NULL,
NULL,
"s",
match);
}
return 0;
}
const char *mid;
int r;
if (!bus)
return -EINVAL;
if (!name)
return -EINVAL;
return -ENOTCONN;
if (bus_pid_changed(bus))
return -ECHILD;
return sd_id128_get_machine(machine);
r = sd_bus_call_method(bus,
name,
"/",
"org.freedesktop.DBus.Peer",
"GetMachineId",
NULL,
&reply,
NULL);
if (r < 0)
return r;
if (r < 0)
return r;
}