mirror of
https://github.com/systemd/systemd.git
synced 2024-12-26 03:22:00 +03:00
dbus: make errors reported via D-Bus more useful
This commit is contained in:
parent
2105e76a77
commit
398ef8ba02
@ -311,7 +311,8 @@ EXTRA_DIST += \
|
|||||||
src/initreq.h \
|
src/initreq.h \
|
||||||
src/sd-daemon.h \
|
src/sd-daemon.h \
|
||||||
src/special.h \
|
src/special.h \
|
||||||
src/dbus-common.h
|
src/dbus-common.h \
|
||||||
|
src/bus-errors.h
|
||||||
|
|
||||||
MANPAGES = \
|
MANPAGES = \
|
||||||
man/systemd.1 \
|
man/systemd.1 \
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "load-dropin.h"
|
#include "load-dropin.h"
|
||||||
#include "unit-name.h"
|
#include "unit-name.h"
|
||||||
#include "dbus-automount.h"
|
#include "dbus-automount.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
|
static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
|
||||||
[AUTOMOUNT_DEAD] = UNIT_INACTIVE,
|
[AUTOMOUNT_DEAD] = UNIT_INACTIVE,
|
||||||
@ -533,10 +534,13 @@ fail:
|
|||||||
static void automount_enter_runnning(Automount *a) {
|
static void automount_enter_runnning(Automount *a) {
|
||||||
int r;
|
int r;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
assert(a);
|
assert(a);
|
||||||
assert(a->mount);
|
assert(a->mount);
|
||||||
|
|
||||||
|
dbus_error_init(&error);
|
||||||
|
|
||||||
mkdir_p(a->where, a->directory_mode);
|
mkdir_p(a->where, a->directory_mode);
|
||||||
|
|
||||||
/* Before we do anything, let's see if somebody is playing games with us? */
|
/* Before we do anything, let's see if somebody is playing games with us? */
|
||||||
@ -547,8 +551,8 @@ static void automount_enter_runnning(Automount *a) {
|
|||||||
|
|
||||||
if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_id)
|
if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_id)
|
||||||
log_info("%s's automount point already active?", a->meta.id);
|
log_info("%s's automount point already active?", a->meta.id);
|
||||||
else if ((r = manager_add_job(a->meta.manager, JOB_START, UNIT(a->mount), JOB_REPLACE, true, NULL)) < 0) {
|
else if ((r = manager_add_job(a->meta.manager, JOB_START, UNIT(a->mount), JOB_REPLACE, true, &error, NULL)) < 0) {
|
||||||
log_warning("%s failed to queue mount startup job: %s", a->meta.id, strerror(-r));
|
log_warning("%s failed to queue mount startup job: %s", a->meta.id, bus_error(&error, r));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,6 +561,7 @@ static void automount_enter_runnning(Automount *a) {
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
automount_enter_dead(a, false);
|
automount_enter_dead(a, false);
|
||||||
|
dbus_error_free(&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int automount_start(Unit *u) {
|
static int automount_start(Unit *u) {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "dbus-manager.h"
|
#include "dbus-manager.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
#define BUS_MANAGER_INTERFACE \
|
#define BUS_MANAGER_INTERFACE \
|
||||||
" <interface name=\"org.freedesktop.systemd1.Manager\">\n" \
|
" <interface name=\"org.freedesktop.systemd1.Manager\">\n" \
|
||||||
@ -254,8 +255,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
|
|||||||
DBUS_TYPE_INVALID))
|
DBUS_TYPE_INVALID))
|
||||||
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
||||||
|
|
||||||
if (!(u = manager_get_unit(m, name)))
|
if (!(u = manager_get_unit(m, name))) {
|
||||||
return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
|
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
|
||||||
|
return bus_send_error_reply(m, connection, message, &error, -ENOENT);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(reply = dbus_message_new_method_return(message)))
|
if (!(reply = dbus_message_new_method_return(message)))
|
||||||
goto oom;
|
goto oom;
|
||||||
@ -280,8 +283,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
|
|||||||
DBUS_TYPE_INVALID))
|
DBUS_TYPE_INVALID))
|
||||||
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
||||||
|
|
||||||
if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
|
if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
|
||||||
return bus_send_error_reply(m, connection, message, NULL, r);
|
return bus_send_error_reply(m, connection, message, &error, r);
|
||||||
|
|
||||||
if (!(reply = dbus_message_new_method_return(message)))
|
if (!(reply = dbus_message_new_method_return(message)))
|
||||||
goto oom;
|
goto oom;
|
||||||
@ -316,8 +319,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
|
|||||||
DBUS_TYPE_INVALID))
|
DBUS_TYPE_INVALID))
|
||||||
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
||||||
|
|
||||||
if (!(j = manager_get_job(m, id)))
|
if (!(j = manager_get_job(m, id))) {
|
||||||
return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
|
dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
|
||||||
|
return bus_send_error_reply(m, connection, message, &error, -ENOENT);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(reply = dbus_message_new_method_return(message)))
|
if (!(reply = dbus_message_new_method_return(message)))
|
||||||
goto oom;
|
goto oom;
|
||||||
@ -496,8 +501,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
|
|||||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
|
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
|
||||||
char *client;
|
char *client;
|
||||||
|
|
||||||
if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message))))
|
if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
|
||||||
return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
|
dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
|
||||||
|
return bus_send_error_reply(m, connection, message, &error, -ENOENT);
|
||||||
|
}
|
||||||
|
|
||||||
free(client);
|
free(client);
|
||||||
|
|
||||||
@ -548,8 +555,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
|
|||||||
if (name && name[0] == 0)
|
if (name && name[0] == 0)
|
||||||
name = NULL;
|
name = NULL;
|
||||||
|
|
||||||
if ((r = snapshot_create(m, name, cleanup, &s)) < 0)
|
if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
|
||||||
return bus_send_error_reply(m, connection, message, NULL, r);
|
return bus_send_error_reply(m, connection, message, &error, r);
|
||||||
|
|
||||||
if (!(reply = dbus_message_new_method_return(message)))
|
if (!(reply = dbus_message_new_method_return(message)))
|
||||||
goto oom;
|
goto oom;
|
||||||
@ -648,8 +655,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
|
|||||||
|
|
||||||
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
|
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
|
||||||
|
|
||||||
if (m->running_as == MANAGER_SYSTEM)
|
if (m->running_as == MANAGER_SYSTEM) {
|
||||||
return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP);
|
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for session managers.");
|
||||||
|
return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
|
||||||
|
}
|
||||||
|
|
||||||
if (!(reply = dbus_message_new_method_return(message)))
|
if (!(reply = dbus_message_new_method_return(message)))
|
||||||
goto oom;
|
goto oom;
|
||||||
@ -720,17 +729,21 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
|
|||||||
DBUS_TYPE_INVALID))
|
DBUS_TYPE_INVALID))
|
||||||
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
||||||
|
|
||||||
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
|
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
|
||||||
return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
|
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
|
||||||
|
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
|
if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
|
||||||
return bus_send_error_reply(m, connection, message, NULL, r);
|
return bus_send_error_reply(m, connection, message, &error, r);
|
||||||
|
|
||||||
if (job_type == JOB_START && u->meta.only_by_dependency)
|
if (job_type == JOB_START && u->meta.only_by_dependency) {
|
||||||
return bus_send_error_reply(m, connection, message, NULL, -EPERM);
|
dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Unit may be activated by dependency only.");
|
||||||
|
return bus_send_error_reply(m, connection, message, &error, -EPERM);
|
||||||
|
}
|
||||||
|
|
||||||
if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
|
if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
|
||||||
return bus_send_error_reply(m, connection, message, NULL, r);
|
return bus_send_error_reply(m, connection, message, &error, r);
|
||||||
|
|
||||||
if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
|
if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
|
||||||
goto oom;
|
goto oom;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "dbus.h"
|
#include "dbus.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "dbus-unit.h"
|
#include "dbus-unit.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
const char bus_unit_interface[] = BUS_UNIT_INTERFACE;
|
const char bus_unit_interface[] = BUS_UNIT_INTERFACE;
|
||||||
|
|
||||||
@ -285,8 +286,10 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
|
|||||||
Job *j;
|
Job *j;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (job_type == JOB_START && u->meta.only_by_dependency)
|
if (job_type == JOB_START && u->meta.only_by_dependency) {
|
||||||
return bus_send_error_reply(m, connection, message, NULL, -EPERM);
|
dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Unit may be activated by dependency only.");
|
||||||
|
return bus_send_error_reply(m, connection, message, &error, -EPERM);
|
||||||
|
}
|
||||||
|
|
||||||
if (!dbus_message_get_args(
|
if (!dbus_message_get_args(
|
||||||
message,
|
message,
|
||||||
@ -295,11 +298,13 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn
|
|||||||
DBUS_TYPE_INVALID))
|
DBUS_TYPE_INVALID))
|
||||||
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
||||||
|
|
||||||
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
|
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
|
||||||
return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
|
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
|
||||||
|
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
if ((r = manager_add_job(m, job_type, u, mode, true, &j)) < 0)
|
if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
|
||||||
return bus_send_error_reply(m, connection, message, NULL, r);
|
return bus_send_error_reply(m, connection, message, &error, r);
|
||||||
|
|
||||||
if (!(reply = dbus_message_new_method_return(message)))
|
if (!(reply = dbus_message_new_method_return(message)))
|
||||||
goto oom;
|
goto oom;
|
||||||
|
25
src/dbus.c
25
src/dbus.c
@ -42,6 +42,7 @@
|
|||||||
#include "dbus-swap.h"
|
#include "dbus-swap.h"
|
||||||
#include "dbus-timer.h"
|
#include "dbus-timer.h"
|
||||||
#include "dbus-path.h"
|
#include "dbus-path.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
#define CONNECTIONS_MAX 52
|
#define CONNECTIONS_MAX 52
|
||||||
|
|
||||||
@ -380,13 +381,13 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus
|
|||||||
|
|
||||||
log_debug("Got D-Bus activation request for %s", name);
|
log_debug("Got D-Bus activation request for %s", name);
|
||||||
|
|
||||||
r = manager_load_unit(m, name, NULL, &u);
|
r = manager_load_unit(m, name, NULL, &error, &u);
|
||||||
|
|
||||||
if (r >= 0 && u->meta.only_by_dependency)
|
if (r >= 0 && u->meta.only_by_dependency)
|
||||||
r = -EPERM;
|
r = -EPERM;
|
||||||
|
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, NULL);
|
r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, &error, NULL);
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
const char *id, *text;
|
const char *id, *text;
|
||||||
@ -396,8 +397,8 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBus
|
|||||||
if (!(reply = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure")))
|
if (!(reply = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure")))
|
||||||
goto oom;
|
goto oom;
|
||||||
|
|
||||||
id = error_to_dbus(r);
|
id = error.name ? error.name : error_to_dbus(r);
|
||||||
text = strerror(-r);
|
text = bus_error(&error, r);
|
||||||
|
|
||||||
if (!dbus_message_set_destination(reply, DBUS_SERVICE_DBUS) ||
|
if (!dbus_message_set_destination(reply, DBUS_SERVICE_DBUS) ||
|
||||||
!dbus_message_append_args(reply,
|
!dbus_message_append_args(reply,
|
||||||
@ -1324,13 +1325,13 @@ static const char *error_to_dbus(int error) {
|
|||||||
return DBUS_ERROR_FAILED;
|
return DBUS_ERROR_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error) {
|
DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *berror, int error) {
|
||||||
DBusMessage *reply = NULL;
|
DBusMessage *reply = NULL;
|
||||||
const char *name, *text;
|
const char *name, *text;
|
||||||
|
|
||||||
if (bus_error && dbus_error_is_set(bus_error)) {
|
if (berror && dbus_error_is_set(berror)) {
|
||||||
name = bus_error->name;
|
name = berror->name;
|
||||||
text = bus_error->message;
|
text = berror->message;
|
||||||
} else {
|
} else {
|
||||||
name = error_to_dbus(error);
|
name = error_to_dbus(error);
|
||||||
text = strerror(-error);
|
text = strerror(-error);
|
||||||
@ -1344,8 +1345,8 @@ DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessag
|
|||||||
|
|
||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
|
|
||||||
if (bus_error)
|
if (berror)
|
||||||
dbus_error_free(bus_error);
|
dbus_error_free(berror);
|
||||||
|
|
||||||
return DBUS_HANDLER_RESULT_HANDLED;
|
return DBUS_HANDLER_RESULT_HANDLED;
|
||||||
|
|
||||||
@ -1353,8 +1354,8 @@ oom:
|
|||||||
if (reply)
|
if (reply)
|
||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
|
|
||||||
if (bus_error)
|
if (berror)
|
||||||
dbus_error_free(bus_error);
|
dbus_error_free(berror);
|
||||||
|
|
||||||
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
return DBUS_HANDLER_RESULT_NEED_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include "securebits.h"
|
#include "securebits.h"
|
||||||
#include "missing.h"
|
#include "missing.h"
|
||||||
#include "unit-name.h"
|
#include "unit-name.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
#define COMMENTS "#;\n"
|
#define COMMENTS "#;\n"
|
||||||
|
|
||||||
@ -1057,14 +1058,23 @@ static int config_parse_timer_unit(
|
|||||||
|
|
||||||
Timer *t = data;
|
Timer *t = data;
|
||||||
int r;
|
int r;
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
|
assert(filename);
|
||||||
|
assert(lvalue);
|
||||||
|
assert(rvalue);
|
||||||
|
assert(data);
|
||||||
|
|
||||||
|
dbus_error_init(&error);
|
||||||
|
|
||||||
if (endswith(rvalue, ".timer")) {
|
if (endswith(rvalue, ".timer")) {
|
||||||
log_error("[%s:%u] Unit cannot be of type timer: %s", filename, line, rvalue);
|
log_error("[%s:%u] Unit cannot be of type timer: %s", filename, line, rvalue);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &t->unit)) < 0) {
|
if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) {
|
||||||
log_error("[%s:%u] Failed to load unit: %s", filename, line, rvalue);
|
log_error("[%s:%u] Failed to load unit %s: %s", filename, line, rvalue, bus_error(&error, r));
|
||||||
|
dbus_error_free(&error);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1128,14 +1138,23 @@ static int config_parse_path_unit(
|
|||||||
|
|
||||||
Path *t = data;
|
Path *t = data;
|
||||||
int r;
|
int r;
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
|
assert(filename);
|
||||||
|
assert(lvalue);
|
||||||
|
assert(rvalue);
|
||||||
|
assert(data);
|
||||||
|
|
||||||
|
dbus_error_init(&error);
|
||||||
|
|
||||||
if (endswith(rvalue, ".path")) {
|
if (endswith(rvalue, ".path")) {
|
||||||
log_error("[%s:%u] Unit cannot be of type path: %s", filename, line, rvalue);
|
log_error("[%s:%u] Unit cannot be of type path: %s", filename, line, rvalue);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &t->unit)) < 0) {
|
if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &t->unit)) < 0) {
|
||||||
log_error("[%s:%u] Failed to load unit: %s", filename, line, rvalue);
|
log_error("[%s:%u] Failed to load unit %s: %s", filename, line, rvalue, bus_error(&error, r));
|
||||||
|
dbus_error_free(&error);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
src/main.c
20
src/main.c
@ -43,6 +43,7 @@
|
|||||||
#include "fdset.h"
|
#include "fdset.h"
|
||||||
#include "special.h"
|
#include "special.h"
|
||||||
#include "conf-parser.h"
|
#include "conf-parser.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
static enum {
|
static enum {
|
||||||
ACTION_RUN,
|
ACTION_RUN,
|
||||||
@ -963,14 +964,20 @@ int main(int argc, char *argv[]) {
|
|||||||
fclose(serialization);
|
fclose(serialization);
|
||||||
serialization = NULL;
|
serialization = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
|
dbus_error_init(&error);
|
||||||
|
|
||||||
log_debug("Activating default unit: %s", arg_default_unit);
|
log_debug("Activating default unit: %s", arg_default_unit);
|
||||||
|
|
||||||
if ((r = manager_load_unit(m, arg_default_unit, NULL, &target)) < 0) {
|
if ((r = manager_load_unit(m, arg_default_unit, NULL, &error, &target)) < 0) {
|
||||||
log_error("Failed to load default target: %s", strerror(-r));
|
log_error("Failed to load default target: %s", bus_error(&error, r));
|
||||||
|
dbus_error_free(&error);
|
||||||
|
|
||||||
log_info("Trying to load rescue target...");
|
log_info("Trying to load rescue target...");
|
||||||
if ((r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &target)) < 0) {
|
if ((r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &error, &target)) < 0) {
|
||||||
log_error("Failed to load rescue target: %s", strerror(-r));
|
log_error("Failed to load rescue target: %s", bus_error(&error, r));
|
||||||
|
dbus_error_free(&error);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -980,8 +987,9 @@ int main(int argc, char *argv[]) {
|
|||||||
manager_dump_units(m, stdout, "\t");
|
manager_dump_units(m, stdout, "\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &job)) < 0) {
|
if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, &job)) < 0) {
|
||||||
log_error("Failed to start default target: %s", strerror(-r));
|
log_error("Failed to start default target: %s", bus_error(&error, r));
|
||||||
|
dbus_error_free(&error);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
101
src/manager.c
101
src/manager.c
@ -53,6 +53,7 @@
|
|||||||
#include "missing.h"
|
#include "missing.h"
|
||||||
#include "path-lookup.h"
|
#include "path-lookup.h"
|
||||||
#include "special.h"
|
#include "special.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
/* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
|
/* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
|
||||||
#define GC_QUEUE_ENTRIES_MAX 16
|
#define GC_QUEUE_ENTRIES_MAX 16
|
||||||
@ -697,7 +698,7 @@ static int delete_one_unmergeable_job(Manager *m, Job *j) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int transaction_merge_jobs(Manager *m) {
|
static int transaction_merge_jobs(Manager *m, DBusError *e) {
|
||||||
Job *j;
|
Job *j;
|
||||||
Iterator i;
|
Iterator i;
|
||||||
int r;
|
int r;
|
||||||
@ -726,6 +727,8 @@ static int transaction_merge_jobs(Manager *m) {
|
|||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
|
|
||||||
/* We couldn't merge anything. Failure */
|
/* We couldn't merge anything. Failure */
|
||||||
|
dbus_set_error(e, BUS_ERROR_TRANSACTION_JOBS_CONFLICTING, "Transaction contains conflicting jobs '%s' and '%s' for %s. Probably contradicting requirement dependencies configured.",
|
||||||
|
job_type_to_string(t), job_type_to_string(k->type), k->unit->meta.id);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -812,7 +815,7 @@ static bool unit_matters_to_anchor(Unit *u, Job *j) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned generation) {
|
static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned generation, DBusError *e) {
|
||||||
Iterator i;
|
Iterator i;
|
||||||
Unit *u;
|
Unit *u;
|
||||||
int r;
|
int r;
|
||||||
@ -863,6 +866,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
|
|||||||
|
|
||||||
log_error("Unable to break cycle");
|
log_error("Unable to break cycle");
|
||||||
|
|
||||||
|
dbus_set_error(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC, "Transaction order is cyclic. See logs for details.");
|
||||||
return -ENOEXEC;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -887,7 +891,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
|
|||||||
if (!(o = u->meta.job))
|
if (!(o = u->meta.job))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((r = transaction_verify_order_one(m, o, j, generation)) < 0)
|
if ((r = transaction_verify_order_one(m, o, j, generation, e)) < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -898,7 +902,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int transaction_verify_order(Manager *m, unsigned *generation) {
|
static int transaction_verify_order(Manager *m, unsigned *generation, DBusError *e) {
|
||||||
Job *j;
|
Job *j;
|
||||||
int r;
|
int r;
|
||||||
Iterator i;
|
Iterator i;
|
||||||
@ -913,7 +917,7 @@ static int transaction_verify_order(Manager *m, unsigned *generation) {
|
|||||||
g = (*generation)++;
|
g = (*generation)++;
|
||||||
|
|
||||||
HASHMAP_FOREACH(j, m->transaction_jobs, i)
|
HASHMAP_FOREACH(j, m->transaction_jobs, i)
|
||||||
if ((r = transaction_verify_order_one(m, j, NULL, g)) < 0)
|
if ((r = transaction_verify_order_one(m, j, NULL, g, e)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -945,7 +949,7 @@ static void transaction_collect_garbage(Manager *m) {
|
|||||||
} while (again);
|
} while (again);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int transaction_is_destructive(Manager *m) {
|
static int transaction_is_destructive(Manager *m, DBusError *e) {
|
||||||
Iterator i;
|
Iterator i;
|
||||||
Job *j;
|
Job *j;
|
||||||
|
|
||||||
@ -962,8 +966,11 @@ static int transaction_is_destructive(Manager *m) {
|
|||||||
|
|
||||||
if (j->unit->meta.job &&
|
if (j->unit->meta.job &&
|
||||||
j->unit->meta.job != j &&
|
j->unit->meta.job != j &&
|
||||||
!job_type_is_superset(j->type, j->unit->meta.job->type))
|
!job_type_is_superset(j->type, j->unit->meta.job->type)) {
|
||||||
|
|
||||||
|
dbus_set_error(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE, "Transaction is destructive.");
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1080,7 +1087,7 @@ rollback:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int transaction_activate(Manager *m, JobMode mode) {
|
static int transaction_activate(Manager *m, JobMode mode, DBusError *e) {
|
||||||
int r;
|
int r;
|
||||||
unsigned generation = 1;
|
unsigned generation = 1;
|
||||||
|
|
||||||
@ -1107,11 +1114,11 @@ static int transaction_activate(Manager *m, JobMode mode) {
|
|||||||
|
|
||||||
/* Fifth step: verify order makes sense and correct
|
/* Fifth step: verify order makes sense and correct
|
||||||
* cycles if necessary and possible */
|
* cycles if necessary and possible */
|
||||||
if ((r = transaction_verify_order(m, &generation)) >= 0)
|
if ((r = transaction_verify_order(m, &generation, e)) >= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (r != -EAGAIN) {
|
if (r != -EAGAIN) {
|
||||||
log_warning("Requested transaction contains an unfixable cyclic ordering dependency: %s", strerror(-r));
|
log_warning("Requested transaction contains an unfixable cyclic ordering dependency: %s", bus_error(e, r));
|
||||||
goto rollback;
|
goto rollback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1123,11 +1130,11 @@ static int transaction_activate(Manager *m, JobMode mode) {
|
|||||||
/* Sixth step: let's drop unmergeable entries if
|
/* Sixth step: let's drop unmergeable entries if
|
||||||
* necessary and possible, merge entries we can
|
* necessary and possible, merge entries we can
|
||||||
* merge */
|
* merge */
|
||||||
if ((r = transaction_merge_jobs(m)) >= 0)
|
if ((r = transaction_merge_jobs(m, e)) >= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (r != -EAGAIN) {
|
if (r != -EAGAIN) {
|
||||||
log_warning("Requested transaction contains unmergable jobs: %s", strerror(-r));
|
log_warning("Requested transaction contains unmergable jobs: %s", bus_error(e, r));
|
||||||
goto rollback;
|
goto rollback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1144,8 +1151,8 @@ static int transaction_activate(Manager *m, JobMode mode) {
|
|||||||
|
|
||||||
/* Ninth step: check whether we can actually apply this */
|
/* Ninth step: check whether we can actually apply this */
|
||||||
if (mode == JOB_FAIL)
|
if (mode == JOB_FAIL)
|
||||||
if ((r = transaction_is_destructive(m)) < 0) {
|
if ((r = transaction_is_destructive(m, e)) < 0) {
|
||||||
log_notice("Requested transaction contradicts existing jobs: %s", strerror(-r));
|
log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e, r));
|
||||||
goto rollback;
|
goto rollback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1253,6 +1260,7 @@ static int transaction_add_job_and_dependencies(
|
|||||||
Job *by,
|
Job *by,
|
||||||
bool matters,
|
bool matters,
|
||||||
bool override,
|
bool override,
|
||||||
|
DBusError *e,
|
||||||
Job **_ret) {
|
Job **_ret) {
|
||||||
Job *ret;
|
Job *ret;
|
||||||
Iterator i;
|
Iterator i;
|
||||||
@ -1264,11 +1272,15 @@ static int transaction_add_job_and_dependencies(
|
|||||||
assert(type < _JOB_TYPE_MAX);
|
assert(type < _JOB_TYPE_MAX);
|
||||||
assert(unit);
|
assert(unit);
|
||||||
|
|
||||||
if (unit->meta.load_state != UNIT_LOADED)
|
if (unit->meta.load_state != UNIT_LOADED) {
|
||||||
|
dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s failed to load.", unit->meta.id);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!unit_job_is_applicable(unit, type))
|
if (!unit_job_is_applicable(unit, type)) {
|
||||||
|
dbus_set_error(e, BUS_ERROR_JOB_TYPE_NOT_APPLICABLE, "Job type %s is not applicable for unit %s.", job_type_to_string(type), unit->meta.id);
|
||||||
return -EBADR;
|
return -EBADR;
|
||||||
|
}
|
||||||
|
|
||||||
/* First add the job. */
|
/* First add the job. */
|
||||||
if (!(ret = transaction_add_one_job(m, type, unit, override, &is_new)))
|
if (!(ret = transaction_add_one_job(m, type, unit, override, &is_new)))
|
||||||
@ -1282,33 +1294,33 @@ static int transaction_add_job_and_dependencies(
|
|||||||
/* Finally, recursively add in all dependencies. */
|
/* Finally, recursively add in all dependencies. */
|
||||||
if (type == JOB_START || type == JOB_RELOAD_OR_START) {
|
if (type == JOB_START || type == JOB_RELOAD_OR_START) {
|
||||||
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES], i)
|
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES], i)
|
||||||
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, override, NULL)) < 0 && r != -EBADR)
|
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
|
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
|
||||||
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !override, override, NULL)) < 0 && r != -EBADR)
|
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !override, override, e, NULL)) < 0 && r != -EBADR)
|
||||||
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
|
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
|
||||||
|
|
||||||
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_WANTS], i)
|
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_WANTS], i)
|
||||||
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, false, NULL)) < 0)
|
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, false, e, NULL)) < 0)
|
||||||
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
|
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
|
||||||
|
|
||||||
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE], i)
|
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE], i)
|
||||||
if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, true, override, NULL)) < 0 && r != -EBADR)
|
if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE_OVERRIDABLE], i)
|
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE_OVERRIDABLE], i)
|
||||||
if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, !override, override, NULL)) < 0 && r != -EBADR)
|
if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, !override, override, e, NULL)) < 0 && r != -EBADR)
|
||||||
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
|
log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r));
|
||||||
|
|
||||||
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_CONFLICTS], i)
|
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_CONFLICTS], i)
|
||||||
if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, override, NULL)) < 0 && r != -EBADR)
|
if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
} else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
|
} else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
|
||||||
|
|
||||||
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRED_BY], i)
|
SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRED_BY], i)
|
||||||
if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, NULL)) < 0 && r != -EBADR)
|
if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1349,14 +1361,14 @@ static int transaction_add_isolate_jobs(Manager *m) {
|
|||||||
if (hashmap_get(m->transaction_jobs, u))
|
if (hashmap_get(m->transaction_jobs, u))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, u, NULL, true, false, NULL)) < 0)
|
if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, u, NULL, true, false, NULL, NULL)) < 0)
|
||||||
log_warning("Cannot add isolate job for unit %s, ignoring: %s", u->meta.id, strerror(-r));
|
log_warning("Cannot add isolate job for unit %s, ignoring: %s", u->meta.id, strerror(-r));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, Job **_ret) {
|
int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, DBusError *e, Job **_ret) {
|
||||||
int r;
|
int r;
|
||||||
Job *ret;
|
Job *ret;
|
||||||
|
|
||||||
@ -1365,12 +1377,14 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
|
|||||||
assert(unit);
|
assert(unit);
|
||||||
assert(mode < _JOB_MODE_MAX);
|
assert(mode < _JOB_MODE_MAX);
|
||||||
|
|
||||||
if (mode == JOB_ISOLATE && type != JOB_START)
|
if (mode == JOB_ISOLATE && type != JOB_START) {
|
||||||
|
dbus_set_error(e, BUS_ERROR_INVALID_JOB_MODE, "Isolate is only valid for start.");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
log_debug("Trying to enqueue job %s/%s", unit->meta.id, job_type_to_string(type));
|
log_debug("Trying to enqueue job %s/%s", unit->meta.id, job_type_to_string(type));
|
||||||
|
|
||||||
if ((r = transaction_add_job_and_dependencies(m, type, unit, NULL, true, override, &ret)) < 0) {
|
if ((r = transaction_add_job_and_dependencies(m, type, unit, NULL, true, override, e, &ret)) < 0) {
|
||||||
transaction_abort(m);
|
transaction_abort(m);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -1381,7 +1395,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r = transaction_activate(m, mode)) < 0)
|
if ((r = transaction_activate(m, mode, e)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
log_debug("Enqueued job %s/%s as %u", unit->meta.id, job_type_to_string(type), (unsigned) ret->id);
|
log_debug("Enqueued job %s/%s as %u", unit->meta.id, job_type_to_string(type), (unsigned) ret->id);
|
||||||
@ -1392,7 +1406,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool override, Job **_ret) {
|
int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool override, DBusError *e, Job **_ret) {
|
||||||
Unit *unit;
|
Unit *unit;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -1401,10 +1415,10 @@ int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode
|
|||||||
assert(name);
|
assert(name);
|
||||||
assert(mode < _JOB_MODE_MAX);
|
assert(mode < _JOB_MODE_MAX);
|
||||||
|
|
||||||
if ((r = manager_load_unit(m, name, NULL, &unit)) < 0)
|
if ((r = manager_load_unit(m, name, NULL, NULL, &unit)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
return manager_add_job(m, type, unit, mode, override, _ret);
|
return manager_add_job(m, type, unit, mode, override, e, _ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
Job *manager_get_job(Manager *m, uint32_t id) {
|
Job *manager_get_job(Manager *m, uint32_t id) {
|
||||||
@ -1446,7 +1460,7 @@ unsigned manager_dispatch_load_queue(Manager *m) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Unit **_ret) {
|
int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
|
||||||
Unit *ret;
|
Unit *ret;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -1456,14 +1470,18 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Un
|
|||||||
/* This will prepare the unit for loading, but not actually
|
/* This will prepare the unit for loading, but not actually
|
||||||
* load anything from disk. */
|
* load anything from disk. */
|
||||||
|
|
||||||
if (path && !is_path(path))
|
if (path && !is_path(path)) {
|
||||||
|
dbus_set_error(e, BUS_ERROR_INVALID_PATH, "Path %s is not absolute.", path);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!name)
|
if (!name)
|
||||||
name = file_name_from_path(path);
|
name = file_name_from_path(path);
|
||||||
|
|
||||||
if (!unit_name_is_valid(name))
|
if (!unit_name_is_valid(name)) {
|
||||||
|
dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if ((ret = manager_get_unit(m, name))) {
|
if ((ret = manager_get_unit(m, name))) {
|
||||||
*_ret = ret;
|
*_ret = ret;
|
||||||
@ -1494,7 +1512,7 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Un
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manager_load_unit(Manager *m, const char *name, const char *path, Unit **_ret) {
|
int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
@ -1502,7 +1520,7 @@ int manager_load_unit(Manager *m, const char *name, const char *path, Unit **_re
|
|||||||
/* This will load the service information files, but not actually
|
/* This will load the service information files, but not actually
|
||||||
* start any services or anything. */
|
* start any services or anything. */
|
||||||
|
|
||||||
if ((r = manager_load_unit_prepare(m, name, path, _ret)) != 0)
|
if ((r = manager_load_unit_prepare(m, name, path, e, _ret)) != 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
manager_dispatch_load_queue(m);
|
manager_dispatch_load_queue(m);
|
||||||
@ -1746,9 +1764,14 @@ static int manager_dispatch_sigchld(Manager *m) {
|
|||||||
|
|
||||||
static int manager_start_target(Manager *m, const char *name, JobMode mode) {
|
static int manager_start_target(Manager *m, const char *name, JobMode mode) {
|
||||||
int r;
|
int r;
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, NULL)) < 0)
|
dbus_error_init(&error);
|
||||||
log_error("Failed to enqueue %s job: %s", name, strerror(-r));
|
|
||||||
|
if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL)) < 0)
|
||||||
|
log_error("Failed to enqueue %s job: %s", name, bus_error(&error, r));
|
||||||
|
|
||||||
|
dbus_error_free(&error);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -2266,7 +2289,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
|
|||||||
|
|
||||||
char_array_0(name);
|
char_array_0(name);
|
||||||
|
|
||||||
if ((r = manager_load_unit(m, strstrip(name), NULL, &u)) < 0)
|
if ((r = manager_load_unit(m, strstrip(name), NULL, NULL, &u)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if ((r = unit_deserialize(u, f, fds)) < 0)
|
if ((r = unit_deserialize(u, f, fds)) < 0)
|
||||||
|
@ -210,11 +210,11 @@ Unit *manager_get_unit(Manager *m, const char *name);
|
|||||||
int manager_get_unit_from_dbus_path(Manager *m, const char *s, Unit **_u);
|
int manager_get_unit_from_dbus_path(Manager *m, const char *s, Unit **_u);
|
||||||
int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
|
int manager_get_job_from_dbus_path(Manager *m, const char *s, Job **_j);
|
||||||
|
|
||||||
int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Unit **_ret);
|
int manager_load_unit_prepare(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret);
|
||||||
int manager_load_unit(Manager *m, const char *name, const char *path, Unit **_ret);
|
int manager_load_unit(Manager *m, const char *name, const char *path, DBusError *e, Unit **_ret);
|
||||||
|
|
||||||
int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret);
|
int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, DBusError *e, Job **_ret);
|
||||||
int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, Job **_ret);
|
int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode mode, bool force, DBusError *e, Job **_ret);
|
||||||
|
|
||||||
void manager_dump_units(Manager *s, FILE *f, const char *prefix);
|
void manager_dump_units(Manager *s, FILE *f, const char *prefix);
|
||||||
void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
|
void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
|
||||||
|
@ -253,7 +253,7 @@ static int mount_add_target_links(Mount *m) {
|
|||||||
else
|
else
|
||||||
target = SPECIAL_LOCAL_FS_TARGET;
|
target = SPECIAL_LOCAL_FS_TARGET;
|
||||||
|
|
||||||
if ((r = manager_load_unit(m->meta.manager, target, NULL, &tu)) < 0)
|
if ((r = manager_load_unit(m->meta.manager, target, NULL, NULL, &tu)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
|
if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
|
||||||
|
12
src/path.c
12
src/path.c
@ -30,6 +30,7 @@
|
|||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "dbus-path.h"
|
#include "dbus-path.h"
|
||||||
#include "special.h"
|
#include "special.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
|
static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
|
||||||
[PATH_DEAD] = UNIT_INACTIVE,
|
[PATH_DEAD] = UNIT_INACTIVE,
|
||||||
@ -298,17 +299,22 @@ static void path_enter_dead(Path *p, bool success) {
|
|||||||
|
|
||||||
static void path_enter_running(Path *p) {
|
static void path_enter_running(Path *p) {
|
||||||
int r;
|
int r;
|
||||||
assert(p);
|
DBusError error;
|
||||||
|
|
||||||
if ((r = manager_add_job(p->meta.manager, JOB_START, p->unit, JOB_REPLACE, true, NULL)) < 0)
|
assert(p);
|
||||||
|
dbus_error_init(&error);
|
||||||
|
|
||||||
|
if ((r = manager_add_job(p->meta.manager, JOB_START, p->unit, JOB_REPLACE, true, &error, NULL)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
path_set_state(p, PATH_RUNNING);
|
path_set_state(p, PATH_RUNNING);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
log_warning("%s failed to queue unit startup job: %s", p->meta.id, strerror(-r));
|
log_warning("%s failed to queue unit startup job: %s", p->meta.id, bus_error(&error, r));
|
||||||
path_enter_dead(p, false);
|
path_enter_dead(p, false);
|
||||||
|
|
||||||
|
dbus_error_free(&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "unit-name.h"
|
#include "unit-name.h"
|
||||||
#include "dbus-service.h"
|
#include "dbus-service.h"
|
||||||
#include "special.h"
|
#include "special.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
#define COMMENTS "#;\n"
|
#define COMMENTS "#;\n"
|
||||||
#define NEWLINES "\n\r"
|
#define NEWLINES "\n\r"
|
||||||
@ -1763,20 +1764,24 @@ fail:
|
|||||||
|
|
||||||
static void service_enter_restart(Service *s) {
|
static void service_enter_restart(Service *s) {
|
||||||
int r;
|
int r;
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
|
dbus_error_init(&error);
|
||||||
|
|
||||||
service_enter_dead(s, true, false);
|
service_enter_dead(s, true, false);
|
||||||
|
|
||||||
if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL)) < 0)
|
if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s), JOB_FAIL, false, NULL, NULL)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
log_debug("%s scheduled restart job.", s->meta.id);
|
log_debug("%s scheduled restart job.", s->meta.id);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
log_warning("%s failed to schedule restart job: %s", s->meta.id, bus_error(&error, -r));
|
||||||
log_warning("%s failed to schedule restart job: %s", s->meta.id, strerror(-r));
|
|
||||||
service_enter_dead(s, false, false);
|
service_enter_dead(s, false, false);
|
||||||
|
|
||||||
|
dbus_error_free(&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void service_enter_reload(Service *s) {
|
static void service_enter_reload(Service *s) {
|
||||||
@ -2538,7 +2543,7 @@ static int service_enumerate(Manager *m) {
|
|||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r = manager_load_unit_prepare(m, name, NULL, &service)) < 0) {
|
if ((r = manager_load_unit_prepare(m, name, NULL, NULL, &service)) < 0) {
|
||||||
log_warning("Failed to prepare unit %s: %s", name, strerror(-r));
|
log_warning("Failed to prepare unit %s: %s", name, strerror(-r));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "snapshot.h"
|
#include "snapshot.h"
|
||||||
#include "unit-name.h"
|
#include "unit-name.h"
|
||||||
#include "dbus-snapshot.h"
|
#include "dbus-snapshot.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
static const UnitActiveState state_translation_table[_SNAPSHOT_STATE_MAX] = {
|
static const UnitActiveState state_translation_table[_SNAPSHOT_STATE_MAX] = {
|
||||||
[SNAPSHOT_DEAD] = UNIT_INACTIVE,
|
[SNAPSHOT_DEAD] = UNIT_INACTIVE,
|
||||||
@ -174,7 +175,7 @@ static const char *snapshot_sub_state_to_string(Unit *u) {
|
|||||||
return snapshot_state_to_string(SNAPSHOT(u)->state);
|
return snapshot_state_to_string(SNAPSHOT(u)->state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) {
|
int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Snapshot **_s) {
|
||||||
Iterator i;
|
Iterator i;
|
||||||
Unit *other, *u = NULL;
|
Unit *other, *u = NULL;
|
||||||
char *n = NULL;
|
char *n = NULL;
|
||||||
@ -185,14 +186,20 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) {
|
|||||||
assert(_s);
|
assert(_s);
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
if (!unit_name_is_valid(name))
|
if (!unit_name_is_valid(name)) {
|
||||||
|
dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (unit_name_to_type(name) != UNIT_SNAPSHOT)
|
if (unit_name_to_type(name) != UNIT_SNAPSHOT) {
|
||||||
|
dbus_set_error(e, BUS_ERROR_UNIT_TYPE_MISMATCH, "Unit name %s lacks snapshot suffix.", name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if (manager_get_unit(m, name))
|
if (manager_get_unit(m, name)) {
|
||||||
|
dbus_set_error(e, BUS_ERROR_UNIT_EXISTS, "Snapshot %s exists already.", name);
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -209,7 +216,7 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) {
|
|||||||
name = n;
|
name = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = manager_load_unit_prepare(m, name, NULL, &u);
|
r = manager_load_unit_prepare(m, name, NULL, e, &u);
|
||||||
free(n);
|
free(n);
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -44,7 +44,7 @@ struct Snapshot {
|
|||||||
|
|
||||||
extern const UnitVTable snapshot_vtable;
|
extern const UnitVTable snapshot_vtable;
|
||||||
|
|
||||||
int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **s);
|
int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Snapshot **s);
|
||||||
void snapshot_remove(Snapshot *s);
|
void snapshot_remove(Snapshot *s);
|
||||||
|
|
||||||
const char* snapshot_state_to_string(SnapshotState i);
|
const char* snapshot_state_to_string(SnapshotState i);
|
||||||
|
13
src/socket.c
13
src/socket.c
@ -38,6 +38,7 @@
|
|||||||
#include "dbus-socket.h"
|
#include "dbus-socket.h"
|
||||||
#include "missing.h"
|
#include "missing.h"
|
||||||
#include "special.h"
|
#include "special.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
|
static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
|
||||||
[SOCKET_DEAD] = UNIT_INACTIVE,
|
[SOCKET_DEAD] = UNIT_INACTIVE,
|
||||||
@ -1025,11 +1026,13 @@ fail:
|
|||||||
|
|
||||||
static void socket_enter_running(Socket *s, int cfd) {
|
static void socket_enter_running(Socket *s, int cfd) {
|
||||||
int r;
|
int r;
|
||||||
|
DBusError error;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
|
dbus_error_init(&error);
|
||||||
|
|
||||||
if (cfd < 0) {
|
if (cfd < 0) {
|
||||||
if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s->service), JOB_REPLACE, true, NULL)) < 0)
|
if ((r = manager_add_job(s->meta.manager, JOB_START, UNIT(s->service), JOB_REPLACE, true, &error, NULL)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
socket_set_state(s, SOCKET_RUNNING);
|
socket_set_state(s, SOCKET_RUNNING);
|
||||||
@ -1061,7 +1064,7 @@ static void socket_enter_running(Socket *s, int cfd) {
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = manager_load_unit(s->meta.manager, name, NULL, &u);
|
r = manager_load_unit(s->meta.manager, name, NULL, NULL, &u);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -1074,18 +1077,20 @@ static void socket_enter_running(Socket *s, int cfd) {
|
|||||||
|
|
||||||
s->n_connections ++;
|
s->n_connections ++;
|
||||||
|
|
||||||
if ((r = manager_add_job(u->meta.manager, JOB_START, u, JOB_REPLACE, true, NULL)) < 0)
|
if ((r = manager_add_job(u->meta.manager, JOB_START, u, JOB_REPLACE, true, &error, NULL)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
log_warning("%s failed to queue socket startup job: %s", s->meta.id, strerror(-r));
|
log_warning("%s failed to queue socket startup job: %s", s->meta.id, bus_error(&error, r));
|
||||||
socket_enter_stop_pre(s, false);
|
socket_enter_stop_pre(s, false);
|
||||||
|
|
||||||
if (cfd >= 0)
|
if (cfd >= 0)
|
||||||
close_nointr_nofail(cfd);
|
close_nointr_nofail(cfd);
|
||||||
|
|
||||||
|
dbus_error_free(&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void socket_run_next(Socket *s, bool success) {
|
static void socket_run_next(Socket *s, bool success) {
|
||||||
|
@ -110,7 +110,7 @@ static int swap_add_target_links(Swap *s) {
|
|||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, &tu)) < 0)
|
if ((r = manager_load_unit(s->meta.manager, SPECIAL_SWAP_TARGET, NULL, NULL, &tu)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (!p->noauto && p->handle && s->meta.manager->running_as == MANAGER_SYSTEM)
|
if (!p->noauto && p->handle && s->meta.manager->running_as == MANAGER_SYSTEM)
|
||||||
|
@ -36,61 +36,61 @@ int main(int argc, char *argv[]) {
|
|||||||
assert_se(manager_new(MANAGER_SYSTEM, &m) >= 0);
|
assert_se(manager_new(MANAGER_SYSTEM, &m) >= 0);
|
||||||
|
|
||||||
printf("Load1:\n");
|
printf("Load1:\n");
|
||||||
assert_se(manager_load_unit(m, "a.service", NULL, &a) >= 0);
|
assert_se(manager_load_unit(m, "a.service", NULL, NULL, &a) >= 0);
|
||||||
assert_se(manager_load_unit(m, "b.service", NULL, &b) >= 0);
|
assert_se(manager_load_unit(m, "b.service", NULL, NULL, &b) >= 0);
|
||||||
assert_se(manager_load_unit(m, "c.service", NULL, &c) >= 0);
|
assert_se(manager_load_unit(m, "c.service", NULL, NULL, &c) >= 0);
|
||||||
manager_dump_units(m, stdout, "\t");
|
manager_dump_units(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Test1: (Trivial)\n");
|
printf("Test1: (Trivial)\n");
|
||||||
assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, &j) == 0);
|
assert_se(manager_add_job(m, JOB_START, c, JOB_REPLACE, false, NULL, &j) == 0);
|
||||||
manager_dump_jobs(m, stdout, "\t");
|
manager_dump_jobs(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Load2:\n");
|
printf("Load2:\n");
|
||||||
manager_clear_jobs(m);
|
manager_clear_jobs(m);
|
||||||
assert_se(manager_load_unit(m, "d.service", NULL, &d) >= 0);
|
assert_se(manager_load_unit(m, "d.service", NULL, NULL, &d) >= 0);
|
||||||
assert_se(manager_load_unit(m, "e.service", NULL, &e) >= 0);
|
assert_se(manager_load_unit(m, "e.service", NULL, NULL, &e) >= 0);
|
||||||
manager_dump_units(m, stdout, "\t");
|
manager_dump_units(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Test2: (Cyclic Order, Unfixable)\n");
|
printf("Test2: (Cyclic Order, Unfixable)\n");
|
||||||
assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, &j) == -ENOEXEC);
|
assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, NULL, &j) == -ENOEXEC);
|
||||||
manager_dump_jobs(m, stdout, "\t");
|
manager_dump_jobs(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Test3: (Cyclic Order, Fixable, Garbage Collector)\n");
|
printf("Test3: (Cyclic Order, Fixable, Garbage Collector)\n");
|
||||||
assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, false, &j) == 0);
|
assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, false, NULL, &j) == 0);
|
||||||
manager_dump_jobs(m, stdout, "\t");
|
manager_dump_jobs(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Test4: (Identical transaction)\n");
|
printf("Test4: (Identical transaction)\n");
|
||||||
assert_se(manager_add_job(m, JOB_START, e, JOB_FAIL, false, &j) == 0);
|
assert_se(manager_add_job(m, JOB_START, e, JOB_FAIL, false, NULL, &j) == 0);
|
||||||
manager_dump_jobs(m, stdout, "\t");
|
manager_dump_jobs(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Load3:\n");
|
printf("Load3:\n");
|
||||||
assert_se(manager_load_unit(m, "g.service", NULL, &g) >= 0);
|
assert_se(manager_load_unit(m, "g.service", NULL, NULL, &g) >= 0);
|
||||||
manager_dump_units(m, stdout, "\t");
|
manager_dump_units(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Test5: (Colliding transaction, fail)\n");
|
printf("Test5: (Colliding transaction, fail)\n");
|
||||||
assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, false, &j) == -EEXIST);
|
assert_se(manager_add_job(m, JOB_START, g, JOB_FAIL, false, NULL, &j) == -EEXIST);
|
||||||
|
|
||||||
printf("Test6: (Colliding transaction, replace)\n");
|
printf("Test6: (Colliding transaction, replace)\n");
|
||||||
assert_se(manager_add_job(m, JOB_START, g, JOB_REPLACE, false, &j) == 0);
|
assert_se(manager_add_job(m, JOB_START, g, JOB_REPLACE, false, NULL, &j) == 0);
|
||||||
manager_dump_jobs(m, stdout, "\t");
|
manager_dump_jobs(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Test7: (Unmeargable job type, fail)\n");
|
printf("Test7: (Unmeargable job type, fail)\n");
|
||||||
assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, false, &j) == -EEXIST);
|
assert_se(manager_add_job(m, JOB_STOP, g, JOB_FAIL, false, NULL, &j) == -EEXIST);
|
||||||
|
|
||||||
printf("Test8: (Mergeable job type, fail)\n");
|
printf("Test8: (Mergeable job type, fail)\n");
|
||||||
assert_se(manager_add_job(m, JOB_RESTART, g, JOB_FAIL, false, &j) == 0);
|
assert_se(manager_add_job(m, JOB_RESTART, g, JOB_FAIL, false, NULL, &j) == 0);
|
||||||
manager_dump_jobs(m, stdout, "\t");
|
manager_dump_jobs(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Test9: (Unmeargable job type, replace)\n");
|
printf("Test9: (Unmeargable job type, replace)\n");
|
||||||
assert_se(manager_add_job(m, JOB_STOP, g, JOB_REPLACE, false, &j) == 0);
|
assert_se(manager_add_job(m, JOB_STOP, g, JOB_REPLACE, false, NULL, &j) == 0);
|
||||||
manager_dump_jobs(m, stdout, "\t");
|
manager_dump_jobs(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Load4:\n");
|
printf("Load4:\n");
|
||||||
assert_se(manager_load_unit(m, "h.service", NULL, &h) >= 0);
|
assert_se(manager_load_unit(m, "h.service", NULL, NULL, &h) >= 0);
|
||||||
manager_dump_units(m, stdout, "\t");
|
manager_dump_units(m, stdout, "\t");
|
||||||
|
|
||||||
printf("Test10: (Unmeargable job type of auxiliary job, fail)\n");
|
printf("Test10: (Unmeargable job type of auxiliary job, fail)\n");
|
||||||
assert_se(manager_add_job(m, JOB_START, h, JOB_FAIL, false, &j) == 0);
|
assert_se(manager_add_job(m, JOB_START, h, JOB_FAIL, false, NULL, &j) == 0);
|
||||||
manager_dump_jobs(m, stdout, "\t");
|
manager_dump_jobs(m, stdout, "\t");
|
||||||
|
|
||||||
manager_free(m);
|
manager_free(m);
|
||||||
|
12
src/timer.c
12
src/timer.c
@ -26,6 +26,7 @@
|
|||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "dbus-timer.h"
|
#include "dbus-timer.h"
|
||||||
#include "special.h"
|
#include "special.h"
|
||||||
|
#include "bus-errors.h"
|
||||||
|
|
||||||
static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
|
static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
|
||||||
[TIMER_DEAD] = UNIT_INACTIVE,
|
[TIMER_DEAD] = UNIT_INACTIVE,
|
||||||
@ -261,18 +262,23 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void timer_enter_running(Timer *t) {
|
static void timer_enter_running(Timer *t) {
|
||||||
|
DBusError error;
|
||||||
int r;
|
int r;
|
||||||
assert(t);
|
|
||||||
|
|
||||||
if ((r = manager_add_job(t->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, NULL)) < 0)
|
assert(t);
|
||||||
|
dbus_error_init(&error);
|
||||||
|
|
||||||
|
if ((r = manager_add_job(t->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, &error, NULL)) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
timer_set_state(t, TIMER_RUNNING);
|
timer_set_state(t, TIMER_RUNNING);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
log_warning("%s failed to queue unit startup job: %s", t->meta.id, strerror(-r));
|
log_warning("%s failed to queue unit startup job: %s", t->meta.id, bus_error(&error, r));
|
||||||
timer_enter_dead(t, false);
|
timer_enter_dead(t, false);
|
||||||
|
|
||||||
|
dbus_error_free(&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int timer_start(Unit *u) {
|
static int timer_start(Unit *u) {
|
||||||
|
28
src/unit.c
28
src/unit.c
@ -881,7 +881,7 @@ static void unit_check_uneeded(Unit *u) {
|
|||||||
log_info("Service %s is not needed anymore. Stopping.", u->meta.id);
|
log_info("Service %s is not needed anymore. Stopping.", u->meta.id);
|
||||||
|
|
||||||
/* Ok, nobody needs us anymore. Sniff. Then let's commit suicide */
|
/* Ok, nobody needs us anymore. Sniff. Then let's commit suicide */
|
||||||
manager_add_job(u->meta.manager, JOB_STOP, u, JOB_FAIL, true, NULL);
|
manager_add_job(u->meta.manager, JOB_STOP, u, JOB_FAIL, true, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void retroactively_start_dependencies(Unit *u) {
|
static void retroactively_start_dependencies(Unit *u) {
|
||||||
@ -893,23 +893,23 @@ static void retroactively_start_dependencies(Unit *u) {
|
|||||||
|
|
||||||
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
|
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
|
||||||
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
||||||
manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL);
|
manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
|
||||||
|
|
||||||
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
|
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
|
||||||
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
||||||
manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL);
|
manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL, NULL);
|
||||||
|
|
||||||
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE], i)
|
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUISITE], i)
|
||||||
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
||||||
manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL);
|
manager_add_job(u->meta.manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
|
||||||
|
|
||||||
SET_FOREACH(other, u->meta.dependencies[UNIT_WANTS], i)
|
SET_FOREACH(other, u->meta.dependencies[UNIT_WANTS], i)
|
||||||
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
||||||
manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL);
|
manager_add_job(u->meta.manager, JOB_START, other, JOB_FAIL, false, NULL, NULL);
|
||||||
|
|
||||||
SET_FOREACH(other, u->meta.dependencies[UNIT_CONFLICTS], i)
|
SET_FOREACH(other, u->meta.dependencies[UNIT_CONFLICTS], i)
|
||||||
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
if (!UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(other)))
|
||||||
manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL);
|
manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void retroactively_stop_dependencies(Unit *u) {
|
static void retroactively_stop_dependencies(Unit *u) {
|
||||||
@ -923,7 +923,7 @@ static void retroactively_stop_dependencies(Unit *u) {
|
|||||||
/* Pull down units need us recursively if enabled */
|
/* Pull down units need us recursively if enabled */
|
||||||
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
|
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
|
||||||
if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
|
if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
|
||||||
manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL);
|
manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Garbage collect services that might not be needed anymore, if enabled */
|
/* Garbage collect services that might not be needed anymore, if enabled */
|
||||||
@ -1391,7 +1391,7 @@ int unit_add_dependency_by_name(Unit *u, UnitDependency d, const char *name, con
|
|||||||
if (!(name = resolve_template(u, name, path, &s)))
|
if (!(name = resolve_template(u, name, path, &s)))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
|
if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
r = unit_add_dependency(u, d, other, add_reference);
|
r = unit_add_dependency(u, d, other, add_reference);
|
||||||
@ -1412,7 +1412,7 @@ int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency
|
|||||||
if (!(name = resolve_template(u, name, path, &s)))
|
if (!(name = resolve_template(u, name, path, &s)))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
|
if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
r = unit_add_two_dependencies(u, d, e, other, add_reference);
|
r = unit_add_two_dependencies(u, d, e, other, add_reference);
|
||||||
@ -1433,7 +1433,7 @@ int unit_add_dependency_by_name_inverse(Unit *u, UnitDependency d, const char *n
|
|||||||
if (!(name = resolve_template(u, name, path, &s)))
|
if (!(name = resolve_template(u, name, path, &s)))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
|
if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
r = unit_add_dependency(other, d, u, add_reference);
|
r = unit_add_dependency(other, d, u, add_reference);
|
||||||
@ -1454,7 +1454,7 @@ int unit_add_two_dependencies_by_name_inverse(Unit *u, UnitDependency d, UnitDep
|
|||||||
if (!(name = resolve_template(u, name, path, &s)))
|
if (!(name = resolve_template(u, name, path, &s)))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if ((r = manager_load_unit(u->meta.manager, name, path, &other)) < 0)
|
if ((r = manager_load_unit(u->meta.manager, name, path, NULL, &other)) < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
if ((r = unit_add_two_dependencies(other, d, e, u, add_reference)) < 0)
|
if ((r = unit_add_two_dependencies(other, d, e, u, add_reference)) < 0)
|
||||||
@ -1682,7 +1682,7 @@ int unit_load_related_unit(Unit *u, const char *type, Unit **_found) {
|
|||||||
|
|
||||||
assert(!unit_has_name(u, t));
|
assert(!unit_has_name(u, t));
|
||||||
|
|
||||||
r = manager_load_unit(u->meta.manager, t, NULL, _found);
|
r = manager_load_unit(u->meta.manager, t, NULL, NULL, _found);
|
||||||
free(t);
|
free(t);
|
||||||
|
|
||||||
assert(r < 0 || *_found != u);
|
assert(r < 0 || *_found != u);
|
||||||
@ -1967,7 +1967,7 @@ int unit_add_node_link(Unit *u, const char *what, bool wants) {
|
|||||||
if (!(e = unit_name_build_escape(what+1, NULL, ".device")))
|
if (!(e = unit_name_build_escape(what+1, NULL, ".device")))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
r = manager_load_unit(u->meta.manager, e, NULL, &device);
|
r = manager_load_unit(u->meta.manager, e, NULL, NULL, &device);
|
||||||
free(e);
|
free(e);
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -1993,7 +1993,7 @@ int unit_coldplug(Unit *u) {
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (u->meta.deserialized_job >= 0) {
|
if (u->meta.deserialized_job >= 0) {
|
||||||
if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_FAIL, false, NULL)) < 0)
|
if ((r = manager_add_job(u->meta.manager, u->meta.deserialized_job, u, JOB_FAIL, false, NULL, NULL)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
u->meta.deserialized_job = _JOB_TYPE_INVALID;
|
u->meta.deserialized_job = _JOB_TYPE_INVALID;
|
||||||
|
Loading…
Reference in New Issue
Block a user