summaryrefslogtreecommitdiff
path: root/src/snapshot.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-07-08 02:43:18 +0200
committerLennart Poettering <lennart@poettering.net>2010-07-08 02:43:18 +0200
commit398ef8ba0266cca453d90a90b3a2aa1caa44189f (patch)
treec2724108ae05922768b1f57acc0372bb58d955cb /src/snapshot.c
parent2105e76a7725d6a29ebfe0af0bf23b3279e466a2 (diff)
dbus: make errors reported via D-Bus more useful
Diffstat (limited to 'src/snapshot.c')
-rw-r--r--src/snapshot.c17
1 files changed, 12 insertions, 5 deletions
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)