machine-dbus.c revision 5b12334d35eadf1f45cc3d631fd1a2e72ffaea0a
/*-*- 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 "strv.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 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;
}
const char *swho;
int r;
assert(m);
if (r < 0)
return r;
else {
if (who < 0)
}
if (r < 0)
return r;
}
const sd_bus_vtable machine_vtable[] = {
};
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 = sd_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 = sd_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_push(&l, p);
if (r < 0) {
free(p);
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);
}