X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fsnapshot.c;h=c2678cbe6e9fda13eec8bd0ad6ae5a3366c7cdfa;hp=14238540989879809787af4ec6df0f77d981822d;hb=adeba5008eac3105ae59256dedd087ebe006a9e6;hpb=a190eeb884840e1a431e22eee2c3b93c96ca7fa3 diff --git a/src/core/snapshot.c b/src/core/snapshot.c index 142385409..c2678cbe6 100644 --- a/src/core/snapshot.c +++ b/src/core/snapshot.c @@ -51,10 +51,11 @@ static void snapshot_set_state(Snapshot *s, SnapshotState state) { s->state = state; if (state != old_state) - log_debug("%s changed %s -> %s", - UNIT(s)->id, - snapshot_state_to_string(old_state), - snapshot_state_to_string(state)); + log_debug_unit(UNIT(s)->id, + "%s changed %s -> %s", + UNIT(s)->id, + snapshot_state_to_string(old_state), + snapshot_state_to_string(state)); unit_notify(UNIT(s), state_translation_table[old_state], state_translation_table[state], true); } @@ -154,7 +155,7 @@ static int snapshot_deserialize_item(Unit *u, const char *key, const char *value state = snapshot_state_from_string(value); if (state < 0) - log_debug("Failed to parse state value %s", value); + log_debug_unit(u->id, "Failed to parse state value %s", value); else s->deserialized_state = state; @@ -162,7 +163,7 @@ static int snapshot_deserialize_item(Unit *u, const char *key, const char *value r = parse_boolean(value); if (r < 0) - log_debug("Failed to parse cleanup value %s", value); + log_debug_unit(u->id, "Failed to parse cleanup value %s", value); else s->cleanup = r; @@ -172,7 +173,7 @@ static int snapshot_deserialize_item(Unit *u, const char *key, const char *value if (r < 0) return r; } else - log_debug("Unknown serialization key '%s'", key); + log_debug_unit(u->id, "Unknown serialization key '%s'", key); return 0; } @@ -189,7 +190,7 @@ _pure_ 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, DBusError *e, Snapshot **_s) { +int snapshot_create(Manager *m, const char *name, bool cleanup, sd_bus_error *e, Snapshot **_s) { _cleanup_free_ char *n = NULL; Unit *other, *u = NULL; Iterator i; @@ -200,20 +201,14 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Sn assert(_s); if (name) { - if (!unit_name_is_valid(name, false)) { - dbus_set_error(e, BUS_ERROR_INVALID_NAME, "Unit name %s is not valid.", name); - return -EINVAL; - } + if (!unit_name_is_valid(name, TEMPLATE_INVALID)) + return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Unit name %s is not valid.", name); - 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 (unit_name_to_type(name) != UNIT_SNAPSHOT) + return sd_bus_error_setf(e, SD_BUS_ERROR_INVALID_ARGS, "Unit name %s lacks snapshot suffix.", name); - if (manager_get_unit(m, name)) { - dbus_set_error(e, BUS_ERROR_UNIT_EXISTS, "Snapshot %s exists already.", name); - return -EEXIST; - } + if (manager_get_unit(m, name)) + return sd_bus_error_setf(e, BUS_ERROR_UNIT_EXISTS, "Snapshot %s exists already.", name); } else { @@ -221,8 +216,10 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Sn if (asprintf(&n, "snapshot-%u.snapshot", ++ m->n_snapshots) < 0) return -ENOMEM; - if (!manager_get_unit(m, n)) + if (!manager_get_unit(m, n)) { + name = n; break; + } free(n); n = NULL; @@ -261,6 +258,8 @@ int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Sn SNAPSHOT(u)->cleanup = cleanup; *_s = SNAPSHOT(u); + log_info_unit(u->id, "Created snapshot %s.", u->id); + return 0; fail: @@ -273,6 +272,8 @@ fail: void snapshot_remove(Snapshot *s) { assert(s); + log_info_unit(UNIT(s)->id, "Removing snapshot %s.", UNIT(s)->id); + unit_add_to_cleanup_queue(UNIT(s)); } @@ -291,8 +292,8 @@ const UnitVTable snapshot_vtable = { .no_gc = true, .init = snapshot_init, - .load = snapshot_load, + .coldplug = snapshot_coldplug, .dump = snapshot_dump, @@ -307,5 +308,5 @@ const UnitVTable snapshot_vtable = { .sub_state_to_string = snapshot_sub_state_to_string, .bus_interface = "org.freedesktop.systemd1.Snapshot", - .bus_message_handler = bus_snapshot_message_handler + .bus_vtable = bus_snapshot_vtable };