src/initreq.h \
src/sd-daemon.h \
src/special.h \
- src/dbus-common.h
+ src/dbus-common.h \
+ src/bus-errors.h
MANPAGES = \
man/systemd.1 \
#include "load-dropin.h"
#include "unit-name.h"
#include "dbus-automount.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
[AUTOMOUNT_DEAD] = UNIT_INACTIVE,
static void automount_enter_runnning(Automount *a) {
int r;
struct stat st;
+ DBusError error;
assert(a);
assert(a->mount);
+ dbus_error_init(&error);
+
mkdir_p(a->where, a->directory_mode);
/* Before we do anything, let's see if somebody is playing games with us? */
if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_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) {
- log_warning("%s failed to queue mount startup job: %s", a->meta.id, strerror(-r));
+ 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, bus_error(&error, r));
goto fail;
}
fail:
automount_enter_dead(a, false);
+ dbus_error_free(&error);
}
static int automount_start(Unit *u) {
#include "log.h"
#include "dbus-manager.h"
#include "strv.h"
+#include "bus-errors.h"
#define BUS_MANAGER_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Manager\">\n" \
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if (!(u = manager_get_unit(m, name)))
- return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
+ if (!(u = manager_get_unit(m, name))) {
+ 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)))
goto oom;
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if ((r = manager_load_unit(m, name, NULL, &u)) < 0)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if (!(j = manager_get_job(m, id)))
- return bus_send_error_reply(m, connection, message, NULL, -ENOENT);
+ if (!(j = manager_get_job(m, id))) {
+ 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)))
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
char *client;
- 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);
+ if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
+ dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
+ return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ }
free(client);
if (name && name[0] == 0)
name = NULL;
- if ((r = snapshot_create(m, name, cleanup, &s)) < 0)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
- if (m->running_as == MANAGER_SYSTEM)
- return bus_send_error_reply(m, connection, message, NULL, -ENOTSUP);
+ if (m->running_as == MANAGER_SYSTEM) {
+ 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)))
goto oom;
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
- return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
+ if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
+ 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)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
- if (job_type == JOB_START && u->meta.only_by_dependency)
- return bus_send_error_reply(m, connection, message, NULL, -EPERM);
+ if (job_type == JOB_START && u->meta.only_by_dependency) {
+ 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)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
goto oom;
#include "dbus.h"
#include "log.h"
#include "dbus-unit.h"
+#include "bus-errors.h"
const char bus_unit_interface[] = BUS_UNIT_INTERFACE;
Job *j;
int r;
- if (job_type == JOB_START && u->meta.only_by_dependency)
- return bus_send_error_reply(m, connection, message, NULL, -EPERM);
+ if (job_type == JOB_START && u->meta.only_by_dependency) {
+ 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(
message,
DBUS_TYPE_INVALID))
return bus_send_error_reply(m, connection, message, &error, -EINVAL);
- if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID)
- return bus_send_error_reply(m, connection, message, NULL, -EINVAL);
+ if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
+ 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)
- return bus_send_error_reply(m, connection, message, NULL, r);
+ if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
+ return bus_send_error_reply(m, connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
#include "dbus-swap.h"
#include "dbus-timer.h"
#include "dbus-path.h"
+#include "bus-errors.h"
#define CONNECTIONS_MAX 52
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)
r = -EPERM;
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) {
const char *id, *text;
if (!(reply = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure")))
goto oom;
- id = error_to_dbus(r);
- text = strerror(-r);
+ id = error.name ? error.name : error_to_dbus(r);
+ text = bus_error(&error, r);
if (!dbus_message_set_destination(reply, DBUS_SERVICE_DBUS) ||
!dbus_message_append_args(reply,
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;
const char *name, *text;
- if (bus_error && dbus_error_is_set(bus_error)) {
- name = bus_error->name;
- text = bus_error->message;
+ if (berror && dbus_error_is_set(berror)) {
+ name = berror->name;
+ text = berror->message;
} else {
name = error_to_dbus(error);
text = strerror(-error);
dbus_message_unref(reply);
- if (bus_error)
- dbus_error_free(bus_error);
+ if (berror)
+ dbus_error_free(berror);
return DBUS_HANDLER_RESULT_HANDLED;
if (reply)
dbus_message_unref(reply);
- if (bus_error)
- dbus_error_free(bus_error);
+ if (berror)
+ dbus_error_free(berror);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
#include "securebits.h"
#include "missing.h"
#include "unit-name.h"
+#include "bus-errors.h"
#define COMMENTS "#;\n"
Timer *t = data;
int r;
+ DBusError error;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ dbus_error_init(&error);
if (endswith(rvalue, ".timer")) {
log_error("[%s:%u] Unit cannot be of type timer: %s", filename, line, rvalue);
return -EINVAL;
}
- if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &t->unit)) < 0) {
- log_error("[%s:%u] Failed to load unit: %s", filename, line, rvalue);
+ if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, NULL, &t->unit)) < 0) {
+ log_error("[%s:%u] Failed to load unit %s: %s", filename, line, rvalue, bus_error(&error, r));
+ dbus_error_free(&error);
return r;
}
Path *t = data;
int r;
+ DBusError error;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+
+ dbus_error_init(&error);
if (endswith(rvalue, ".path")) {
log_error("[%s:%u] Unit cannot be of type path: %s", filename, line, rvalue);
return -EINVAL;
}
- if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &t->unit)) < 0) {
- log_error("[%s:%u] Failed to load unit: %s", filename, line, rvalue);
+ if ((r = manager_load_unit(t->meta.manager, rvalue, NULL, &error, &t->unit)) < 0) {
+ log_error("[%s:%u] Failed to load unit %s: %s", filename, line, rvalue, bus_error(&error, r));
+ dbus_error_free(&error);
return r;
}
#include "fdset.h"
#include "special.h"
#include "conf-parser.h"
+#include "bus-errors.h"
static enum {
ACTION_RUN,
fclose(serialization);
serialization = NULL;
} else {
+ DBusError error;
+
+ dbus_error_init(&error);
+
log_debug("Activating default unit: %s", arg_default_unit);
- if ((r = manager_load_unit(m, arg_default_unit, NULL, &target)) < 0) {
- log_error("Failed to load default target: %s", strerror(-r));
+ if ((r = manager_load_unit(m, arg_default_unit, NULL, &error, &target)) < 0) {
+ log_error("Failed to load default target: %s", bus_error(&error, r));
+ dbus_error_free(&error);
log_info("Trying to load rescue target...");
- if ((r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &target)) < 0) {
- log_error("Failed to load rescue target: %s", strerror(-r));
+ if ((r = manager_load_unit(m, SPECIAL_RESCUE_TARGET, NULL, &error, &target)) < 0) {
+ log_error("Failed to load rescue target: %s", bus_error(&error, r));
+ dbus_error_free(&error);
goto finish;
}
}
manager_dump_units(m, stdout, "\t");
}
- if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &job)) < 0) {
- log_error("Failed to start default target: %s", strerror(-r));
+ if ((r = manager_add_job(m, JOB_START, target, JOB_REPLACE, false, &error, &job)) < 0) {
+ log_error("Failed to start default target: %s", bus_error(&error, r));
+ dbus_error_free(&error);
goto finish;
}
#include "missing.h"
#include "path-lookup.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 */
#define GC_QUEUE_ENTRIES_MAX 16
return -EINVAL;
}
-static int transaction_merge_jobs(Manager *m) {
+static int transaction_merge_jobs(Manager *m, DBusError *e) {
Job *j;
Iterator i;
int r;
return -EAGAIN;
/* 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 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;
Unit *u;
int r;
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;
}
if (!(o = u->meta.job))
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 0;
}
-static int transaction_verify_order(Manager *m, unsigned *generation) {
+static int transaction_verify_order(Manager *m, unsigned *generation, DBusError *e) {
Job *j;
int r;
Iterator i;
g = (*generation)++;
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 0;
} while (again);
}
-static int transaction_is_destructive(Manager *m) {
+static int transaction_is_destructive(Manager *m, DBusError *e) {
Iterator i;
Job *j;
if (j->unit->meta.job &&
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 0;
return r;
}
-static int transaction_activate(Manager *m, JobMode mode) {
+static int transaction_activate(Manager *m, JobMode mode, DBusError *e) {
int r;
unsigned generation = 1;
/* Fifth step: verify order makes sense and correct
* cycles if necessary and possible */
- if ((r = transaction_verify_order(m, &generation)) >= 0)
+ if ((r = transaction_verify_order(m, &generation, e)) >= 0)
break;
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;
}
/* Sixth step: let's drop unmergeable entries if
* necessary and possible, merge entries we can
* merge */
- if ((r = transaction_merge_jobs(m)) >= 0)
+ if ((r = transaction_merge_jobs(m, e)) >= 0)
break;
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;
}
/* Ninth step: check whether we can actually apply this */
if (mode == JOB_FAIL)
- if ((r = transaction_is_destructive(m)) < 0) {
- log_notice("Requested transaction contradicts existing jobs: %s", strerror(-r));
+ if ((r = transaction_is_destructive(m, e)) < 0) {
+ log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e, r));
goto rollback;
}
Job *by,
bool matters,
bool override,
+ DBusError *e,
Job **_ret) {
Job *ret;
Iterator i;
assert(type < _JOB_TYPE_MAX);
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;
+ }
- 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;
+ }
/* First add the job. */
if (!(ret = transaction_add_one_job(m, type, unit, override, &is_new)))
/* Finally, recursively add in all dependencies. */
if (type == JOB_START || type == JOB_RELOAD_OR_START) {
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;
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));
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));
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;
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));
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;
} else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
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;
}
if (hashmap_get(m->transaction_jobs, u))
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));
}
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;
Job *ret;
assert(unit);
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;
+ }
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);
return r;
}
return r;
}
- if ((r = transaction_activate(m, mode)) < 0)
+ if ((r = transaction_activate(m, mode, e)) < 0)
return r;
log_debug("Enqueued job %s/%s as %u", unit->meta.id, job_type_to_string(type), (unsigned) ret->id);
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;
int r;
assert(name);
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 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) {
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;
int r;
/* This will prepare the unit for loading, but not actually
* 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;
+ }
if (!name)
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;
+ }
if ((ret = manager_get_unit(m, name))) {
*_ret = ret;
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;
assert(m);
/* This will load the service information files, but not actually
* 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;
manager_dispatch_load_queue(m);
static int manager_start_target(Manager *m, const char *name, JobMode mode) {
int r;
+ DBusError error;
+
+ dbus_error_init(&error);
+
+ 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));
- if ((r = manager_add_job_by_name(m, JOB_START, name, mode, true, NULL)) < 0)
- log_error("Failed to enqueue %s job: %s", name, strerror(-r));
+ dbus_error_free(&error);
return r;
}
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;
if ((r = unit_deserialize(u, f, fds)) < 0)
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_load_unit_prepare(Manager *m, const char *name, const char *path, Unit **_ret);
-int manager_load_unit(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, DBusError *e, Unit **_ret);
-int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, 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(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, DBusError *e, Job **_ret);
void manager_dump_units(Manager *s, FILE *f, const char *prefix);
void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
else
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;
if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
#include "path.h"
#include "dbus-path.h"
#include "special.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
[PATH_DEAD] = UNIT_INACTIVE,
static void path_enter_running(Path *p) {
int r;
+ DBusError error;
+
assert(p);
+ dbus_error_init(&error);
- if ((r = manager_add_job(p->meta.manager, JOB_START, p->unit, JOB_REPLACE, true, NULL)) < 0)
+ if ((r = manager_add_job(p->meta.manager, JOB_START, p->unit, JOB_REPLACE, true, &error, NULL)) < 0)
goto fail;
path_set_state(p, PATH_RUNNING);
return;
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);
+
+ dbus_error_free(&error);
}
#include "unit-name.h"
#include "dbus-service.h"
#include "special.h"
+#include "bus-errors.h"
#define COMMENTS "#;\n"
#define NEWLINES "\n\r"
static void service_enter_restart(Service *s) {
int r;
+ DBusError error;
+
assert(s);
+ dbus_error_init(&error);
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;
log_debug("%s scheduled restart job.", s->meta.id);
return;
fail:
-
- log_warning("%s failed to schedule restart job: %s", s->meta.id, strerror(-r));
+ log_warning("%s failed to schedule restart job: %s", s->meta.id, bus_error(&error, -r));
service_enter_dead(s, false, false);
+
+ dbus_error_free(&error);
}
static void service_enter_reload(Service *s) {
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));
continue;
}
#include "snapshot.h"
#include "unit-name.h"
#include "dbus-snapshot.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_SNAPSHOT_STATE_MAX] = {
[SNAPSHOT_DEAD] = UNIT_INACTIVE,
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;
Unit *other, *u = NULL;
char *n = NULL;
assert(_s);
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;
+ }
- 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;
+ }
- 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;
+ }
} else {
name = n;
}
- r = manager_load_unit_prepare(m, name, NULL, &u);
+ r = manager_load_unit_prepare(m, name, NULL, e, &u);
free(n);
if (r < 0)
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);
const char* snapshot_state_to_string(SnapshotState i);
#include "dbus-socket.h"
#include "missing.h"
#include "special.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
[SOCKET_DEAD] = UNIT_INACTIVE,
static void socket_enter_running(Socket *s, int cfd) {
int r;
+ DBusError error;
assert(s);
+ dbus_error_init(&error);
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;
socket_set_state(s, SOCKET_RUNNING);
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);
if (r < 0)
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;
}
return;
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);
if (cfd >= 0)
close_nointr_nofail(cfd);
+
+ dbus_error_free(&error);
}
static void socket_run_next(Socket *s, bool success) {
else
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;
if (!p->noauto && p->handle && s->meta.manager->running_as == MANAGER_SYSTEM)
assert_se(manager_new(MANAGER_SYSTEM, &m) >= 0);
printf("Load1:\n");
- assert_se(manager_load_unit(m, "a.service", NULL, &a) >= 0);
- assert_se(manager_load_unit(m, "b.service", NULL, &b) >= 0);
- assert_se(manager_load_unit(m, "c.service", NULL, &c) >= 0);
+ assert_se(manager_load_unit(m, "a.service", NULL, NULL, &a) >= 0);
+ assert_se(manager_load_unit(m, "b.service", NULL, NULL, &b) >= 0);
+ assert_se(manager_load_unit(m, "c.service", NULL, NULL, &c) >= 0);
manager_dump_units(m, stdout, "\t");
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");
printf("Load2:\n");
manager_clear_jobs(m);
- assert_se(manager_load_unit(m, "d.service", NULL, &d) >= 0);
- assert_se(manager_load_unit(m, "e.service", NULL, &e) >= 0);
+ assert_se(manager_load_unit(m, "d.service", NULL, NULL, &d) >= 0);
+ assert_se(manager_load_unit(m, "e.service", NULL, NULL, &e) >= 0);
manager_dump_units(m, stdout, "\t");
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");
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");
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");
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");
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");
- 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");
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");
- 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");
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");
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");
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_free(m);
#include "timer.h"
#include "dbus-timer.h"
#include "special.h"
+#include "bus-errors.h"
static const UnitActiveState state_translation_table[_TIMER_STATE_MAX] = {
[TIMER_DEAD] = UNIT_INACTIVE,
}
static void timer_enter_running(Timer *t) {
+ DBusError error;
int r;
+
assert(t);
+ dbus_error_init(&error);
- if ((r = manager_add_job(t->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, NULL)) < 0)
+ if ((r = manager_add_job(t->meta.manager, JOB_START, t->unit, JOB_REPLACE, true, &error, NULL)) < 0)
goto fail;
timer_set_state(t, TIMER_RUNNING);
return;
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);
+
+ dbus_error_free(&error);
}
static int timer_start(Unit *u) {
log_info("Service %s is not needed anymore. Stopping.", u->meta.id);
/* 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) {
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
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)
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)
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)
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)
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) {
/* Pull down units need us recursively if enabled */
SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
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 */
if (!(name = resolve_template(u, name, path, &s)))
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;
r = unit_add_dependency(u, d, other, add_reference);
if (!(name = resolve_template(u, name, path, &s)))
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;
r = unit_add_two_dependencies(u, d, e, other, add_reference);
if (!(name = resolve_template(u, name, path, &s)))
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;
r = unit_add_dependency(other, d, u, add_reference);
if (!(name = resolve_template(u, name, path, &s)))
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;
if ((r = unit_add_two_dependencies(other, d, e, u, add_reference)) < 0)
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);
assert(r < 0 || *_found != u);
if (!(e = unit_name_build_escape(what+1, NULL, ".device")))
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);
if (r < 0)
return r;
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;
u->meta.deserialized_job = _JOB_TYPE_INVALID;