machine-dbus.c revision 9bb0c7cfbb253c5b983efaed51a65bcbf422d8d7
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 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 <errno.h>
#include <string.h>
#include "bus-util.h"
#include "bus-label.h"
#include "strv.h"
#include "bus-common-errors.h"
#include "copy.h"
#include "fileio.h"
#include "in-addr-util.h"
#include "local-addresses.h"
#include "path-util.h"
#include "bus-internal.h"
#include "machine.h"
static int property_get_id(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
int r;
assert(m);
if (r < 0)
return r;
return 1;
}
static int property_get_state(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
const char *state;
int r;
assert(m);
if (r < 0)
return r;
return 1;
}
static int property_get_netif(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
int r;
assert(m);
if (r < 0)
return r;
return 1;
}
int bus_machine_method_terminate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int r;
assert(m);
r = machine_stop(m);
if (r < 0)
return r;
}
int bus_machine_method_kill(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *swho;
int r;
assert(m);
if (r < 0)
return r;
else {
if (who < 0)
}
if (r < 0)
return r;
}
int bus_machine_method_get_addresses(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *p;
int r;
assert(m);
if (r < 0)
return sd_bus_error_set_errno(error, r);
r = readlink_malloc(p, &them);
if (r < 0)
return sd_bus_error_set_errno(error, r);
return sd_bus_error_setf(error, BUS_ERROR_NO_PRIVATE_NETWORKING, "Machine %s does not use private networking", m->name);
if (r < 0)
return sd_bus_error_set_errno(error, r);
if (child < 0)
if (child == 0) {
struct local_address *a;
int i, n;
if (r < 0)
if (n < 0)
for (a = addresses, i = 0; i < n; a++, i++) {
};
if (r < 0)
}
}
if (r < 0)
return sd_bus_error_set_errno(error, r);
if (r < 0)
return sd_bus_error_set_errno(error, r);
for (;;) {
int family;
ssize_t n;
union in_addr_union in_addr;
.msg_iovlen = 2,
};
if (n < 0)
break;
if (r < 0)
return sd_bus_error_set_errno(error, r);
if (r < 0)
return sd_bus_error_set_errno(error, r);
switch (family) {
case AF_INET:
break;
case AF_INET6:
break;
}
if (r < 0)
return sd_bus_error_set_errno(error, r);
if (r < 0)
return sd_bus_error_set_errno(error, r);
}
if (r < 0)
return sd_bus_error_set_errno(error, r);
if (r < 0)
return sd_bus_error_set_errno(error, r);
}
int bus_machine_method_get_os_release(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
char **k, **v;
int r;
assert(m);
if (r < 0)
return r;
return -errno;
if (child < 0)
return -errno;
if (child == 0) {
if (r < 0)
if (fd < 0) {
if (fd < 0)
}
if (r < 0)
}
if (!f)
return -errno;
pair[0] = -1;
if (r < 0)
return r;
if (r < 0)
return r;
return -EIO;
if (r < 0)
return r;
if (r < 0)
return r;
STRV_FOREACH_PAIR(k, v, l) {
if (r < 0)
return r;
}
if (r < 0)
return r;
}
int bus_machine_method_open_pty(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int r;
assert(m);
if (master < 0)
return master;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
}
int bus_machine_method_open_login(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *p;
int r;
"org.freedesktop.machine1.login",
false,
&m->manager->polkit_registry,
error);
if (r < 0)
return r;
if (r == 0)
return 1; /* Will call us back */
if (master < 0)
return master;
if (r < 0)
return r;
if (!p)
return -errno;
r = sd_bus_new(&container_bus);
if (r < 0)
return r;
#ifdef ENABLE_KDBUS
asprintf(&container_bus->address, "x-container-kernel:pid=" PID_FMT ";x-container-unix:pid=" PID_FMT, m->leader, m->leader);
#else
#endif
if (!container_bus->address)
return -ENOMEM;
container_bus->bus_client = true;
container_bus->trusted = false;
container_bus->is_system = true;
r = sd_bus_start(container_bus);
if (r < 0)
return r;
if (!getty)
return -ENOMEM;
r = sd_bus_call_method(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartUnit",
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
}
const sd_bus_vtable machine_vtable[] = {
BUS_PROPERTY_DUAL_TIMESTAMP("Timestamp", offsetof(Machine, timestamp), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Scope", "s", NULL, offsetof(Machine, unit), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN),
SD_BUS_PROPERTY("Class", "s", property_get_class, offsetof(Machine, class), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("RootDirectory", "s", NULL, offsetof(Machine, root_directory), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_METHOD("Terminate", NULL, NULL, bus_machine_method_terminate, SD_BUS_VTABLE_CAPABILITY(CAP_KILL)),
SD_BUS_METHOD("GetAddresses", NULL, "a(iay)", bus_machine_method_get_addresses, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("GetOSRelease", NULL, "a{ss}", bus_machine_method_get_os_release, SD_BUS_VTABLE_UNPRIVILEGED),
};
int machine_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
int r;
assert(m);
if (!message)
return 0;
if (r < 0)
return r;
if (r < 0)
return r;
if (r <= 0)
return 0;
} else {
_cleanup_free_ char *e = NULL;
const char *p;
if (!p)
return 0;
e = bus_label_unescape(p);
if (!e)
return -ENOMEM;
if (!machine)
return 0;
}
return 1;
}
char *machine_bus_path(Machine *m) {
_cleanup_free_ char *e = NULL;
assert(m);
e = bus_label_escape(m->name);
if (!e)
return NULL;
return strappend("/org/freedesktop/machine1/machine/", e);
}
int machine_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
_cleanup_strv_free_ char **l = NULL;
Iterator i;
int r;
char *p;
p = machine_bus_path(machine);
if (!p)
return -ENOMEM;
r = strv_consume(&l, p);
if (r < 0)
return r;
}
*nodes = l;
l = NULL;
return 1;
}
_cleanup_free_ char *p = NULL;
assert(m);
p = machine_bus_path(m);
if (!p)
return -ENOMEM;
return sd_bus_emit_signal(
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
"so", m->name, p);
}
_cleanup_free_ char *p = NULL;
assert(m);
if (!m->create_message)
return 0;
c = m->create_message;
m->create_message = NULL;
if (error)
return sd_bus_reply_method_error(c, error);
/* Update the machine state file before we notify the client
* about the result. */
machine_save(m);
p = machine_bus_path(m);
if (!p)
return -ENOMEM;
return sd_bus_reply_method_return(c, "o", p);
}