summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-30 20:32:17 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-30 20:38:28 -0400
commit7358dc029ab8cb8f9d83eb847389d84f822ccfe8 (patch)
treefb119a569229988b8dbf3408794d41ce0e229442
parent4a0a74179fcfb85c456794fd91fa2ae5d4d3bc8f (diff)
Convert the rest to sd_bus_errnomap
I tried to preserve most errno values, but in some cases they were inconsistent (different errno values for the same error name) or just mismatched.
-rw-r--r--Makefile.am1
-rw-r--r--src/core/manager.c12
-rw-r--r--src/core/transaction.c88
-rw-r--r--src/core/unit.c10
-rw-r--r--src/shared/bus-errors.c73
-rw-r--r--src/timedate/timedated.c16
6 files changed, 126 insertions, 74 deletions
diff --git a/Makefile.am b/Makefile.am
index f1a972dc6..2e4f692c6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -752,6 +752,7 @@ libsystemd_shared_la_SOURCES = \
src/shared/refcnt.h \
src/shared/udev-util.h \
src/shared/bus-errors.h \
+ src/shared/bus-errors.c \
src/shared/device-nodes.c \
src/shared/device-nodes.h \
src/shared/util.c \
diff --git a/src/core/manager.c b/src/core/manager.c
index d427d88d4..ed7fdc71d 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1189,15 +1189,11 @@ 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) {
- sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Isolate is only valid for start.");
- return -EINVAL;
- }
+ if (mode == JOB_ISOLATE && type != JOB_START)
+ return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Isolate is only valid for start.");
- if (mode == JOB_ISOLATE && !unit->allow_isolate) {
- sd_bus_error_setf(e, BUS_ERROR_NO_ISOLATION, "Operation refused, unit may not be isolated.");
- return -EPERM;
- }
+ if (mode == JOB_ISOLATE && !unit->allow_isolate)
+ return sd_bus_error_setf(e, BUS_ERROR_NO_ISOLATION, "Operation refused, unit may not be isolated.");
log_debug_unit(unit->id,
"Trying to enqueue job %s/%s/%s", unit->id,
diff --git a/src/core/transaction.c b/src/core/transaction.c
index dbb4133fe..488cb86fe 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -264,13 +264,12 @@ static int transaction_merge_jobs(Transaction *tr, sd_bus_error *e) {
return -EAGAIN;
/* We couldn't merge anything. Failure */
- sd_bus_error_setf(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->id);
- return r;
+ return sd_bus_error_setf(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->id);
}
}
@@ -412,9 +411,8 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
log_error("Unable to break cycle");
- sd_bus_error_setf(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC,
- "Transaction order is cyclic. See system logs for details.");
- return -ENOEXEC;
+ return sd_bus_error_setf(e, BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC,
+ "Transaction order is cyclic. See system logs for details.");
}
/* Make the marker point to where we come from, so that we can
@@ -513,12 +511,9 @@ static int transaction_is_destructive(Transaction *tr, JobMode mode, sd_bus_erro
assert(!j->transaction_next);
if (j->unit->job && (mode == JOB_FAIL || j->unit->job->irreversible) &&
- !job_type_is_superset(j->type, j->unit->job->type)) {
-
- sd_bus_error_setf(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE,
- "Transaction is destructive.");
- return -EEXIST;
- }
+ !job_type_is_superset(j->type, j->unit->job->type))
+ return sd_bus_error_setf(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE,
+ "Transaction is destructive.");
}
return 0;
@@ -860,50 +855,39 @@ int transaction_add_job_and_dependencies(
/* by ? by->unit->id : "NA", */
/* by ? job_type_to_string(by->type) : "NA"); */
- if (unit->load_state != UNIT_LOADED &&
- unit->load_state != UNIT_ERROR &&
- unit->load_state != UNIT_NOT_FOUND &&
- unit->load_state != UNIT_MASKED) {
- sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
- "Unit %s is not loaded properly.", unit->id);
- return -EINVAL;
- }
+ if (!IN_SET(unit->load_state, UNIT_LOADED, UNIT_ERROR, UNIT_NOT_FOUND, UNIT_MASKED))
+ return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
+ "Unit %s is not loaded properly.", unit->id);
if (type != JOB_STOP && unit->load_state == UNIT_ERROR) {
if (unit->load_error == -ENOENT || unit->manager->test_run)
- sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
- "Unit %s failed to load: %s.",
- unit->id,
- strerror(-unit->load_error));
+ return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
+ "Unit %s failed to load: %s.",
+ unit->id,
+ strerror(-unit->load_error));
else
- sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
- "Unit %s failed to load: %s. "
- "See system logs and 'systemctl status %s' for details.",
- unit->id,
- strerror(-unit->load_error),
- unit->id);
- return -EINVAL;
+ return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
+ "Unit %s failed to load: %s. "
+ "See system logs and 'systemctl status %s' for details.",
+ unit->id,
+ strerror(-unit->load_error),
+ unit->id);
}
- if (type != JOB_STOP && unit->load_state == UNIT_NOT_FOUND) {
- sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
- "Unit %s failed to load: %s.",
- unit->id, strerror(-unit->load_error));
- return -EINVAL;
- }
+ if (type != JOB_STOP && unit->load_state == UNIT_NOT_FOUND)
+ return sd_bus_error_setf(e, BUS_ERROR_LOAD_FAILED,
+ "Unit %s failed to load: %s.",
+ unit->id, strerror(-unit->load_error));
- if (type != JOB_STOP && unit->load_state == UNIT_MASKED) {
- sd_bus_error_setf(e, BUS_ERROR_UNIT_MASKED,
- "Unit %s is masked.", unit->id);
- return -EADDRNOTAVAIL;
- }
+ if (type != JOB_STOP && unit->load_state == UNIT_MASKED)
+ return sd_bus_error_setf(e, BUS_ERROR_UNIT_MASKED,
+ "Unit %s is masked.", unit->id);
+
+ if (!unit_job_is_applicable(unit, type))
+ return sd_bus_error_setf(e, BUS_ERROR_JOB_TYPE_NOT_APPLICABLE,
+ "Job type %s is not applicable for unit %s.",
+ job_type_to_string(type), unit->id);
- if (!unit_job_is_applicable(unit, type)) {
- sd_bus_error_setf(e, BUS_ERROR_JOB_TYPE_NOT_APPLICABLE,
- "Job type %s is not applicable for unit %s.",
- job_type_to_string(type), unit->id);
- return -EBADR;
- }
/* First add the job. */
ret = transaction_add_one_job(tr, type, unit, override, &is_new);
diff --git a/src/core/unit.c b/src/core/unit.c
index 84f210a31..d5acc728e 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2939,18 +2939,16 @@ int unit_kill_common(
if (who == KILL_MAIN && main_pid <= 0) {
if (main_pid < 0)
- sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no main processes", unit_type_to_string(u->type));
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no main processes", unit_type_to_string(u->type));
else
- sd_bus_error_set_const(error, BUS_ERROR_NO_SUCH_PROCESS, "No main process to kill");
- return -ESRCH;
+ return sd_bus_error_set_const(error, BUS_ERROR_NO_SUCH_PROCESS, "No main process to kill");
}
if (who == KILL_CONTROL && control_pid <= 0) {
if (control_pid < 0)
- sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no control processes", unit_type_to_string(u->type));
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_PROCESS, "%s units have no control processes", unit_type_to_string(u->type));
else
- sd_bus_error_set_const(error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
- return -ESRCH;
+ return sd_bus_error_set_const(error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
}
if (who == KILL_CONTROL || who == KILL_ALL)
diff --git a/src/shared/bus-errors.c b/src/shared/bus-errors.c
new file mode 100644
index 000000000..31d00bac3
--- /dev/null
+++ b/src/shared/bus-errors.c
@@ -0,0 +1,73 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Zbigniew Jędrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <errno.h>
+
+#include "sd-bus.h"
+#include "bus-errors.h"
+
+SD_BUS_ERROR_MAPPING = {
+ {BUS_ERROR_NO_SUCH_UNIT, ENOENT},
+ {BUS_ERROR_NO_UNIT_FOR_PID, ESRCH},
+ {BUS_ERROR_UNIT_EXISTS, EEXIST},
+ {BUS_ERROR_LOAD_FAILED, EIO},
+ {BUS_ERROR_JOB_FAILED, EREMOTEIO},
+ {BUS_ERROR_NO_SUCH_JOB, ENOENT},
+ {BUS_ERROR_NOT_SUBSCRIBED, EINVAL},
+ {BUS_ERROR_ALREADY_SUBSCRIBED, EINVAL},
+ {BUS_ERROR_ONLY_BY_DEPENDENCY, EINVAL},
+ {BUS_ERROR_TRANSACTION_JOBS_CONFLICTING, EDEADLOCK},
+ {BUS_ERROR_TRANSACTION_ORDER_IS_CYCLIC, EDEADLOCK},
+ {BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE, EDEADLOCK},
+ {BUS_ERROR_UNIT_MASKED, ENOSYS},
+ {BUS_ERROR_JOB_TYPE_NOT_APPLICABLE, EBADR},
+ {BUS_ERROR_NO_ISOLATION, EPERM},
+ {BUS_ERROR_SHUTTING_DOWN, ECANCELED},
+ {BUS_ERROR_SCOPE_NOT_RUNNING, EHOSTDOWN},
+
+ {BUS_ERROR_NO_SUCH_MACHINE, ENXIO},
+ {BUS_ERROR_NO_MACHINE_FOR_PID, ENXIO},
+ {BUS_ERROR_MACHINE_EXISTS, EEXIST},
+ {BUS_ERROR_NO_PRIVATE_NETWORKING, ENOSYS},
+
+ {BUS_ERROR_NO_SUCH_SESSION, ENXIO},
+ {BUS_ERROR_NO_SESSION_FOR_PID, ENXIO},
+ {BUS_ERROR_NO_SUCH_USER, ENXIO},
+ {BUS_ERROR_NO_USER_FOR_PID, ENXIO},
+ {BUS_ERROR_NO_SUCH_SEAT, ENXIO},
+ {BUS_ERROR_SESSION_NOT_ON_SEAT, EINVAL},
+ {BUS_ERROR_NOT_IN_CONTROL, EINVAL},
+ {BUS_ERROR_DEVICE_IS_TAKEN, EINVAL},
+ {BUS_ERROR_DEVICE_NOT_TAKEN, EINVAL},
+ {BUS_ERROR_OPERATION_IN_PROGRESS, EINPROGRESS},
+ {BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, ENOSYS},
+
+ {BUS_ERROR_AUTOMATIC_TIME_SYNC_ENABLED, EALREADY},
+
+ {BUS_ERROR_NO_SUCH_PROCESS, ESRCH},
+
+ {BUS_ERROR_NO_NAME_SERVERS, EIO},
+ {BUS_ERROR_INVALID_REPLY, EINVAL},
+ {BUS_ERROR_NO_SUCH_RR, ENOENT},
+ {BUS_ERROR_NO_RESOURCES, ENOMEM},
+ {BUS_ERROR_CNAME_LOOP, EDEADLOCK},
+ {BUS_ERROR_ABORTED, ECANCELED},
+};
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 8880812b4..49a957c8d 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -44,6 +44,10 @@
#define NULL_ADJTIME_UTC "0.0 0 0\n0\nUTC\n"
#define NULL_ADJTIME_LOCAL "0.0 0 0\n0\nLOCAL\n"
+SD_BUS_ERROR_MAPPING = {
+ {"org.freedesktop.timedate1.NoNTPSupport", ENOTSUP},
+};
+
typedef struct Context {
char *zone;
bool local_rtc;
@@ -254,10 +258,8 @@ static int context_start_ntp(Context *c, sd_bus *bus, sd_bus_error *error) {
if (r < 0) {
if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND) ||
sd_bus_error_has_name(error, "org.freedesktop.systemd1.LoadFailed") ||
- sd_bus_error_has_name(error, "org.freedesktop.systemd1.NoSuchUnit")) {
- sd_bus_error_set_const(error, "org.freedesktop.timedate1.NoNTPSupport", "NTP not supported.");
- return -ENOTSUP;
- }
+ sd_bus_error_has_name(error, "org.freedesktop.systemd1.NoSuchUnit"))
+ return sd_bus_error_set_const(error, "org.freedesktop.timedate1.NoNTPSupport", "NTP not supported.");
return r;
}
@@ -298,10 +300,8 @@ static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) {
false);
if (r < 0) {
- if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND)) {
- sd_bus_error_set_const(error, "org.freedesktop.timedate1.NoNTPSupport", "NTP not supported.");
- return -ENOTSUP;
- }
+ if (sd_bus_error_has_name(error, SD_BUS_ERROR_FILE_NOT_FOUND))
+ return sd_bus_error_set_const(error, "org.freedesktop.timedate1.NoNTPSupport", "NTP not supported.");
return r;
}