diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-07-08 02:43:18 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-07-08 02:43:18 +0200 |
commit | 398ef8ba0266cca453d90a90b3a2aa1caa44189f (patch) | |
tree | c2724108ae05922768b1f57acc0372bb58d955cb | |
parent | 2105e76a7725d6a29ebfe0af0bf23b3279e466a2 (diff) |
dbus: make errors reported via D-Bus more useful
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | src/automount.c | 9 | ||||
-rw-r--r-- | src/dbus-manager.c | 53 | ||||
-rw-r--r-- | src/dbus-unit.c | 17 | ||||
-rw-r--r-- | src/dbus.c | 25 | ||||
-rw-r--r-- | src/load-fragment.c | 27 | ||||
-rw-r--r-- | src/main.c | 20 | ||||
-rw-r--r-- | src/manager.c | 101 | ||||
-rw-r--r-- | src/manager.h | 8 | ||||
-rw-r--r-- | src/mount.c | 2 | ||||
-rw-r--r-- | src/path.c | 10 | ||||
-rw-r--r-- | src/service.c | 13 | ||||
-rw-r--r-- | src/snapshot.c | 17 | ||||
-rw-r--r-- | src/snapshot.h | 2 | ||||
-rw-r--r-- | src/socket.c | 13 | ||||
-rw-r--r-- | src/swap.c | 2 | ||||
-rw-r--r-- | src/test-engine.c | 34 | ||||
-rw-r--r-- | src/timer.c | 10 | ||||
-rw-r--r-- | src/unit.c | 28 |
19 files changed, 249 insertions, 145 deletions
diff --git a/Makefile.am b/Makefile.am index b444c02f30..dfea23df4f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -311,7 +311,8 @@ EXTRA_DIST += \ 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 \ diff --git a/src/automount.c b/src/automount.c index 0689ec7789..39eb3dd01a 100644 --- a/src/automount.c +++ b/src/automount.c @@ -35,6 +35,7 @@ #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, @@ -533,10 +534,13 @@ fail: 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? */ @@ -547,8 +551,8 @@ static void automount_enter_runnning(Automount *a) { 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; } @@ -557,6 +561,7 @@ static void automount_enter_runnning(Automount *a) { fail: automount_enter_dead(a, false); + dbus_error_free(&error); } static int automount_start(Unit *u) { diff --git a/src/dbus-manager.c b/src/dbus-manager.c index dda7c771a5..5daccb14e8 100644 --- a/src/dbus-manager.c +++ b/src/dbus-manager.c @@ -25,6 +25,7 @@ #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" \ @@ -254,8 +255,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, 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; @@ -280,8 +283,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, 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; @@ -316,8 +319,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, 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; @@ -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")) { 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); @@ -548,8 +555,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, 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; @@ -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")) { - 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; @@ -720,17 +729,21 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, 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; diff --git a/src/dbus-unit.c b/src/dbus-unit.c index 85125c9633..840eaa571f 100644 --- a/src/dbus-unit.c +++ b/src/dbus-unit.c @@ -24,6 +24,7 @@ #include "dbus.h" #include "log.h" #include "dbus-unit.h" +#include "bus-errors.h" const char bus_unit_interface[] = BUS_UNIT_INTERFACE; @@ -285,8 +286,10 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn 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, @@ -295,11 +298,13 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *conn 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; diff --git a/src/dbus.c b/src/dbus.c index 0008cfd303..2998c58178 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -42,6 +42,7 @@ #include "dbus-swap.h" #include "dbus-timer.h" #include "dbus-path.h" +#include "bus-errors.h" #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); - 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; @@ -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"))) 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, @@ -1324,13 +1325,13 @@ static const char *error_to_dbus(int error) { 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); @@ -1344,8 +1345,8 @@ DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessag dbus_message_unref(reply); - if (bus_error) - dbus_error_free(bus_error); + if (berror) + dbus_error_free(berror); return DBUS_HANDLER_RESULT_HANDLED; @@ -1353,8 +1354,8 @@ oom: 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; } diff --git a/src/load-fragment.c b/src/load-fragment.c index c3909e9563..d474c9a88c 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -39,6 +39,7 @@ #include "securebits.h" #include "missing.h" #include "unit-name.h" +#include "bus-errors.h" #define COMMENTS "#;\n" @@ -1057,14 +1058,23 @@ static int config_parse_timer_unit( 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; } @@ -1128,14 +1138,23 @@ static int config_parse_path_unit( 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; } diff --git a/src/main.c b/src/main.c index d5902b354f..3124b7644e 100644 --- a/src/main.c +++ b/src/main.c @@ -43,6 +43,7 @@ #include "fdset.h" #include "special.h" #include "conf-parser.h" +#include "bus-errors.h" static enum { ACTION_RUN, @@ -963,14 +964,20 @@ int main(int argc, char *argv[]) { 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; } } @@ -980,8 +987,9 @@ int main(int argc, char *argv[]) { 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; } diff --git a/src/manager.c b/src/manager.c index c1f70e815c..9cbf9c8748 100644 --- a/src/manager.c +++ b/src/manager.c @@ -53,6 +53,7 @@ #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 @@ -697,7 +698,7 @@ static int delete_one_unmergeable_job(Manager *m, Job *j) { return -EINVAL; } -static int transaction_merge_jobs(Manager *m) { +static int transaction_merge_jobs(Manager *m, DBusError *e) { Job *j; Iterator i; int r; @@ -726,6 +727,8 @@ static int transaction_merge_jobs(Manager *m) { 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; } } @@ -812,7 +815,7 @@ static bool unit_matters_to_anchor(Unit *u, Job *j) { 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; @@ -863,6 +866,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned 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; } @@ -887,7 +891,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned 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; } @@ -898,7 +902,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned 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; @@ -913,7 +917,7 @@ static int transaction_verify_order(Manager *m, unsigned *generation) { 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; @@ -945,7 +949,7 @@ static void transaction_collect_garbage(Manager *m) { } while (again); } -static int transaction_is_destructive(Manager *m) { +static int transaction_is_destructive(Manager *m, DBusError *e) { Iterator i; Job *j; @@ -962,8 +966,11 @@ static int transaction_is_destructive(Manager *m) { 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; @@ -1080,7 +1087,7 @@ rollback: 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; @@ -1107,11 +1114,11 @@ static int transaction_activate(Manager *m, JobMode mode) { /* 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; } @@ -1123,11 +1130,11 @@ static int transaction_activate(Manager *m, JobMode mode) { /* 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; } @@ -1144,8 +1151,8 @@ static int transaction_activate(Manager *m, JobMode mode) { /* 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; } @@ -1253,6 +1260,7 @@ static int transaction_add_job_and_dependencies( Job *by, bool matters, bool override, + DBusError *e, Job **_ret) { Job *ret; Iterator i; @@ -1264,11 +1272,15 @@ static int transaction_add_job_and_dependencies( 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))) @@ -1282,33 +1294,33 @@ static int transaction_add_job_and_dependencies( /* 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; } @@ -1349,14 +1361,14 @@ static int transaction_add_isolate_jobs(Manager *m) { 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; @@ -1365,12 +1377,14 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove 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; } @@ -1381,7 +1395,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove 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); @@ -1392,7 +1406,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove 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; @@ -1401,10 +1415,10 @@ int manager_add_job_by_name(Manager *m, JobType type, const char *name, JobMode 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) { @@ -1446,7 +1460,7 @@ unsigned manager_dispatch_load_queue(Manager *m) { 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; @@ -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 * 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; @@ -1494,7 +1512,7 @@ int manager_load_unit_prepare(Manager *m, const char *name, const char *path, Un 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); @@ -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 * 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); @@ -1746,9 +1764,14 @@ static int manager_dispatch_sigchld(Manager *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; } @@ -2266,7 +2289,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) { 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) diff --git a/src/manager.h b/src/manager.h index 5b3aaf3364..e5cf3a1c52 100644 --- a/src/manager.h +++ b/src/manager.h @@ -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_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); diff --git a/src/mount.c b/src/mount.c index 49081d1d97..50fe85cb7c 100644 --- a/src/mount.c +++ b/src/mount.c @@ -253,7 +253,7 @@ static int mount_add_target_links(Mount *m) { 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) { diff --git a/src/path.c b/src/path.c index 30d946d788..27c4544729 100644 --- a/src/path.c +++ b/src/path.c @@ -30,6 +30,7 @@ #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, @@ -298,17 +299,22 @@ static void path_enter_dead(Path *p, bool success) { 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); } diff --git a/src/service.c b/src/service.c index 35f2e9ad2c..75439be376 100644 --- a/src/service.c +++ b/src/service.c @@ -33,6 +33,7 @@ #include "unit-name.h" #include "dbus-service.h" #include "special.h" +#include "bus-errors.h" #define COMMENTS "#;\n" #define NEWLINES "\n\r" @@ -1763,20 +1764,24 @@ fail: 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) { @@ -2538,7 +2543,7 @@ static int service_enumerate(Manager *m) { 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; } diff --git a/src/snapshot.c b/src/snapshot.c index ba72edc255..fe8a43dd3a 100644 --- a/src/snapshot.c +++ b/src/snapshot.c @@ -25,6 +25,7 @@ #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, @@ -174,7 +175,7 @@ static const char *snapshot_sub_state_to_string(Unit *u) { 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; @@ -185,14 +186,20 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) { 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 { @@ -209,7 +216,7 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, Snapshot **_s) { 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) diff --git a/src/snapshot.h b/src/snapshot.h index 2561790639..2b5f3c338a 100644 --- a/src/snapshot.h +++ b/src/snapshot.h @@ -44,7 +44,7 @@ struct Snapshot { 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); diff --git a/src/socket.c b/src/socket.c index 00e0685aad..b8643d9f43 100644 --- a/src/socket.c +++ b/src/socket.c @@ -38,6 +38,7 @@ #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, @@ -1025,11 +1026,13 @@ fail: 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); @@ -1061,7 +1064,7 @@ static void socket_enter_running(Socket *s, int cfd) { 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) @@ -1074,18 +1077,20 @@ static void socket_enter_running(Socket *s, int cfd) { 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) { diff --git a/src/swap.c b/src/swap.c index f72ede66d0..92035144ba 100644 --- a/src/swap.c +++ b/src/swap.c @@ -110,7 +110,7 @@ static int swap_add_target_links(Swap *s) { 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) diff --git a/src/test-engine.c b/src/test-engine.c index 89631c4659..d10196b12f 100644 --- a/src/test-engine.c +++ b/src/test-engine.c @@ -36,61 +36,61 @@ int main(int argc, char *argv[]) { 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); diff --git a/src/timer.c b/src/timer.c index b4521e6efc..1c7010d120 100644 --- a/src/timer.c +++ b/src/timer.c @@ -26,6 +26,7 @@ #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, @@ -261,18 +262,23 @@ fail: } 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) { diff --git a/src/unit.c b/src/unit.c index 1874cdf78d..a5f8712ae6 100644 --- a/src/unit.c +++ b/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); /* 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) { @@ -893,23 +893,23 @@ 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) { @@ -923,7 +923,7 @@ 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 */ @@ -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))) 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); @@ -1412,7 +1412,7 @@ int unit_add_two_dependencies_by_name(Unit *u, UnitDependency d, UnitDependency 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); @@ -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))) 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); @@ -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))) 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) @@ -1682,7 +1682,7 @@ int unit_load_related_unit(Unit *u, const char *type, Unit **_found) { 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); @@ -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"))) 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) @@ -1993,7 +1993,7 @@ int unit_coldplug(Unit *u) { 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; |