summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
f84190d)
For "systemctl snapshot" it makes no sense to complete an incomplete
name with ".service" as we previously did, use ".snapshot" instead.
Also, don't bother with mount units or suchlike, we know that this must
be a snapshot and hence is the only sane way for completion.
+char *snapshot_name_mangle(const char *name) {
+ char *r, *t;
+ const char *f;
+
+ assert(name);
+
+ /* Similar to unit_name_mangle(), but is called when we know
+ * that this is about snapshot units. */
+
+ r = new(char, strlen(name) * 4 + 1 + sizeof(".snapshot")-1);
+ if (!r)
+ return NULL;
+
+ for (f = name, t = r; *f; f++) {
+ if (*f == '/')
+ *(t++) = '-';
+ else if (!strchr(VALID_CHARS, *f))
+ t = do_escape_char(*f, t);
+ else
+ *(t++) = *f;
+ }
+
+ if (!endswith(name, ".snapshot"))
+ strcpy(t, ".snapshot");
+ else
+ *t = 0;
+
+ return r;
+}
+
UnitType unit_name_to_type(const char *n) {
const char *e;
UnitType unit_name_to_type(const char *n) {
const char *e;
char *unit_dbus_path_from_name(const char *name);
char *unit_name_mangle(const char *name);
char *unit_dbus_path_from_name(const char *name);
char *unit_name_mangle(const char *name);
+char *snapshot_name_mangle(const char *name);
dbus_bool_t cleanup = FALSE;
DBusMessageIter iter, sub;
const char
dbus_bool_t cleanup = FALSE;
DBusMessageIter iter, sub;
const char
- *name = "", *path, *id,
*interface = "org.freedesktop.systemd1.Unit",
*property = "Id";
_cleanup_free_ char *n = NULL;
dbus_error_init(&error);
*interface = "org.freedesktop.systemd1.Unit",
*property = "Id";
_cleanup_free_ char *n = NULL;
dbus_error_init(&error);
- if (strv_length(args) > 1) {
- name = args[1];
- n = unit_name_mangle(name);
- }
+ if (strv_length(args) > 1)
+ n = snapshot_name_mangle(args[1]);
+ else
+ n = strdup("");
+ if (!n)
+ return log_oom();
r = bus_method_call_with_reply (
bus,
r = bus_method_call_with_reply (
bus,
"CreateSnapshot",
&reply,
NULL,
"CreateSnapshot",
&reply,
NULL,
- DBUS_TYPE_STRING, n ? (const char**) &n : &name,
DBUS_TYPE_BOOLEAN, &cleanup,
DBUS_TYPE_INVALID);
if (r < 0)
DBUS_TYPE_BOOLEAN, &cleanup,
DBUS_TYPE_INVALID);
if (r < 0)
if (!dbus_message_get_args(reply, &error,
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID)) {
log_error("Failed to parse reply: %s", bus_error_message(&error));
if (!dbus_message_get_args(reply, &error,
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID)) {
log_error("Failed to parse reply: %s", bus_error_message(&error));
- r = -EIO;
- goto finish;
+ dbus_error_free(&error);
+ return -EIO;
}
dbus_message_unref(reply);
}
dbus_message_unref(reply);
DBUS_TYPE_STRING, &property,
DBUS_TYPE_INVALID);
if (r < 0)
DBUS_TYPE_STRING, &property,
DBUS_TYPE_INVALID);
if (r < 0)
if (!dbus_message_iter_init(reply, &iter) ||
dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
log_error("Failed to parse reply.");
if (!dbus_message_iter_init(reply, &iter) ||
dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
log_error("Failed to parse reply.");
- r = -EIO;
- goto finish;
}
dbus_message_iter_recurse(&iter, &sub);
if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING) {
log_error("Failed to parse reply.");
}
dbus_message_iter_recurse(&iter, &sub);
if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING) {
log_error("Failed to parse reply.");
- r = -EIO;
- goto finish;
}
dbus_message_iter_get_basic(&sub, &id);
}
dbus_message_iter_get_basic(&sub, &id);
if (!arg_quiet)
puts(id);
if (!arg_quiet)
puts(id);
-finish:
- dbus_error_free(&error);
-
- return r;
}
static int delete_snapshot(DBusConnection *bus, char **args) {
}
static int delete_snapshot(DBusConnection *bus, char **args) {
_cleanup_free_ char *n = NULL;
int r;
_cleanup_free_ char *n = NULL;
int r;
- n = unit_name_mangle(*name);
+ n = snapshot_name_mangle(*name);
+ if (!n)
+ return log_oom();
+
r = bus_method_call_with_reply(
bus,
"org.freedesktop.systemd1",
r = bus_method_call_with_reply(
bus,
"org.freedesktop.systemd1",
"RemoveSnapshot",
NULL,
NULL,
"RemoveSnapshot",
NULL,
NULL,
- DBUS_TYPE_STRING, n ? &n : name,
DBUS_TYPE_INVALID);
if (r < 0)
return r;
DBUS_TYPE_INVALID);
if (r < 0)
return r;
/* "daemon-reload" */ "Reload";
}
/* "daemon-reload" */ "Reload";
}
- r = bus_method_call_with_reply (
+ r = bus_method_call_with_reply(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
/* On reexecution, we expect a disconnect, not
* a reply */
r = 0;
/* On reexecution, we expect a disconnect, not
* a reply */
r = 0;
log_error("Failed to issue method call: %s", bus_error_message(&error));
log_error("Failed to issue method call: %s", bus_error_message(&error));
- dbus_error_free(&error);
+ dbus_error_free(&error);