dbus-unit.c revision 8fe914ec81d9f57bcc083036f528b00119ed2e3b
/*-*- Mode: C; c-basic-offset: 8 -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include "dbus.h"
#include "log.h"
#include "dbus-unit.h"
#include "bus-errors.h"
const char bus_unit_interface[] = BUS_UNIT_INTERFACE;
char *t;
Iterator j;
return -ENOMEM;
return -ENOMEM;
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
const char *d;
assert(m);
assert(i);
assert(u);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
return -ENOMEM;
return 0;
}
int bus_unit_append_dependencies(Manager *m, DBusMessageIter *i, const char *property, void *data) {
Unit *u;
Iterator j;
return -ENOMEM;
SET_FOREACH(u, s, j)
return -ENOMEM;
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
const char *d;
assert(m);
assert(i);
assert(u);
d = unit_description(u);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
return -ENOMEM;
return 0;
}
int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *property, void *data) {
const char *state;
assert(m);
assert(i);
assert(u);
return -ENOMEM;
return 0;
}
const char *state;
assert(m);
assert(i);
assert(u);
return -ENOMEM;
return 0;
}
dbus_bool_t b;
assert(m);
assert(i);
assert(u);
b = unit_can_start(u) &&
!u->meta.only_by_dependency;
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
return -ENOMEM;
return 0;
}
dbus_bool_t b;
assert(m);
assert(i);
assert(u);
b = unit_can_reload(u);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
return -ENOMEM;
return 0;
}
char *p;
assert(m);
assert(i);
assert(u);
return -ENOMEM;
return -ENOMEM;
free(p);
return -ENOMEM;
}
} else {
/* No job, so let's fill in some placeholder
* data. Since we need to fill in a valid path we
* simple point to ourselves. */
if (!(p = unit_dbus_path(u)))
return -ENOMEM;
free(p);
return -ENOMEM;
}
}
free(p);
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *property, void *data) {
char *t;
bool success;
assert(m);
assert(i);
assert(u);
if ((cgb = unit_get_default_cgroup(u))) {
if (!(t = cgroup_bonding_to_string(cgb)))
return -ENOMEM;
} else
t = (char*) "";
if (cgb)
free(t);
}
return -ENOMEM;
char *t;
bool success;
if (!(t = cgroup_bonding_to_string(cgb)))
return -ENOMEM;
free(t);
if (!success)
return -ENOMEM;
}
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
int bus_unit_append_need_daemon_reload(Manager *m, DBusMessageIter *i, const char *property, void *data) {
dbus_bool_t b;
assert(m);
assert(i);
assert(u);
b = unit_need_daemon_reload(u);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
return -ENOMEM;
return 0;
}
static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *connection, DBusMessage *message) {
bool reload_if_possible = false;
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ReloadOrRestart")) {
reload_if_possible = true;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ReloadOrTryRestart")) {
reload_if_possible = true;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ResetMaintenance")) {
goto oom;
} else if (UNIT_VTABLE(u)->bus_message_handler)
else
if (job_type != _JOB_TYPE_INVALID) {
const char *smode;
Job *j;
int r;
}
if (!dbus_message_get_args(
&error,
if (reload_if_possible && unit_can_reload(u)) {
if (job_type == JOB_RESTART)
else if (job_type == JOB_TRY_RESTART)
}
}
goto oom;
if (!(path = job_dbus_path(j)))
goto oom;
if (!dbus_message_append_args(
goto oom;
}
if (reply) {
goto oom;
}
return DBUS_HANDLER_RESULT_HANDLED;
oom:
if (reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
Unit *u;
int r;
assert(m);
if (r == -ENOMEM)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (r == -ENOENT)
}
}
const DBusObjectPathVTable bus_unit_vtable = {
};
void bus_unit_send_change_signal(Unit *u) {
char *p = NULL;
DBusMessage *m = NULL;
assert(u);
if (u->meta.in_dbus_queue) {
u->meta.in_dbus_queue = false;
}
u->meta.sent_dbus_new_signal = true;
return;
}
if (!(p = unit_dbus_path(u)))
goto oom;
if (u->meta.sent_dbus_new_signal) {
/* Send a change signal */
goto oom;
} else {
/* Send a new signal */
if (!(m = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitNew")))
goto oom;
if (!dbus_message_append_args(m,
goto oom;
}
goto oom;
free(p);
u->meta.sent_dbus_new_signal = true;
return;
oom:
free(p);
if (m)
}
void bus_unit_send_removed_signal(Unit *u) {
char *p = NULL;
DBusMessage *m = NULL;
assert(u);
return;
if (!u->meta.sent_dbus_new_signal)
if (!(p = unit_dbus_path(u)))
goto oom;
if (!(m = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "UnitRemoved")))
goto oom;
if (!dbus_message_append_args(m,
goto oom;
goto oom;
free(p);
return;
oom:
free(p);
if (m)
log_error("Failed to allocate unit remove signal.");
}