machine-dbus.c revision 76e665855edef5b7103cb09d114377d477bfae02
/*-*- 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 "machined.h"
#include "machine.h"
#include "dbus-common.h"
#define BUS_MACHINE_INTERFACE \
" <interface name=\"org.freedesktop.machine1.Machine\">\n" \
" <method name=\"Terminate\"/>\n" \
" <method name=\"Kill\">\n" \
" <arg name=\"who\" type=\"s\"/>\n" \
" <arg name=\"signal\" type=\"s\"/>\n" \
" </method>\n" \
" <property name=\"Name\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Id\" type=\"ay\" access=\"read\"/>\n" \
" <property name=\"Timestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"TimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"Service\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Scope\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Leader\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"Class\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"State\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"RootDirectory\" type=\"s\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION \
"<node>\n" \
"</node>\n"
#define INTERFACES_LIST \
"org.freedesktop.machine1.Machine\0"
dbus_bool_t b;
void *p;
assert(i);
assert(m);
return -ENOMEM;
p = &m->id;
if (!b)
return -ENOMEM;
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
const char *state;
assert(i);
assert(m);
return -ENOMEM;
return 0;
}
_cleanup_free_ char *e = NULL;
assert(m);
return -EINVAL;
if (!e)
return -ENOMEM;
if (!machine)
return -ENOENT;
return 0;
}
static const BusProperty bus_machine_machine_properties[] = {
{ NULL, }
};
Machine *m,
DBusMessage *message) {
int r;
assert(m);
r = machine_stop(m);
if (r < 0)
if (!reply)
goto oom;
const char *swho;
if (!dbus_message_get_args(
&error,
else {
if (who < 0)
}
if (r < 0)
if (!reply)
goto oom;
} else {
const BusBoundProperties bps[] = {
{ "org.freedesktop.machine1.Machine", bus_machine_machine_properties, m },
{ NULL, }
};
}
if (reply) {
goto oom;
}
return DBUS_HANDLER_RESULT_HANDLED;
oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
void *userdata) {
Machine *m;
int r;
if (r < 0) {
if (r == -ENOMEM)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (r == -ENOENT) {
DBusError e;
dbus_error_init(&e);
}
}
}
const DBusObjectPathVTable bus_machine_vtable = {
};
char *machine_bus_path(Machine *m) {
_cleanup_free_ char *e = NULL;
assert(m);
e = bus_path_escape(m->name);
if (!e)
return NULL;
return strappend("/org/freedesktop/machine1/machine/", e);
}
_cleanup_free_ char *p = NULL;
assert(m);
"org.freedesktop.machine1.Manager",
if (!m)
return -ENOMEM;
p = machine_bus_path(m);
if (!p)
return -ENOMEM;
if (!dbus_message_append_args(
msg,
DBUS_TYPE_STRING, &m->name,
return -ENOMEM;
return -ENOMEM;
return 0;
}
_cleanup_free_ char *p = NULL;
assert(m);
if (!m->started)
return 0;
p = machine_bus_path(m);
if (!p)
return -ENOMEM;
if (!msg)
return -ENOMEM;
return -ENOMEM;
return 0;
}
assert(m);
if (!m->create_message)
return 0;
if (error) {
}
if (!reply)
return log_oom();
} else {
_cleanup_free_ char *p = NULL;
p = machine_bus_path(m);
if (!p)
return log_oom();
if (!reply)
return log_oom();
return log_oom();
}
/* Update the machine state file before we notify the client
* about the result. */
machine_save(m);
return log_oom();
m->create_message = NULL;
return 0;
}