summaryrefslogtreecommitdiff
path: root/src/machine/machinectl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-06-24 16:01:14 +0200
committerLennart Poettering <lennart@poettering.net>2016-06-24 16:01:14 +0200
commit03c2b2889fa2d090d7953e28124ec5d00898289d (patch)
tree9c9c6a7f4d63510817142e8f30acabe9abf5abe1 /src/machine/machinectl.c
parent5816a84352e19492df61036d26eff0eb00f2d8c0 (diff)
machined: "machinectl clean" can take a while, do it asynchronously from a background process
This is a follow-up to 5d2036b5f3506bd0ff07042aee8d69c26db32298, and also makes the "machinectl clean" verb asynchronous, after all it's little more than a series of image removals. The changes required to make this happen are a bit more comprehensive as we need to pass information about deleted images back to the client, as well as information about the image we failed on if we failed on one. Hence, create a temporary file in /tmp, serialize that data into, and read it from the parent after the operation is complete.
Diffstat (limited to 'src/machine/machinectl.c')
-rw-r--r--src/machine/machinectl.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index 5ca557abbf..d68c50b203 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -2375,7 +2375,7 @@ static int set_limit(int argc, char *argv[], void *userdata) {
}
static int clean_images(int argc, char *argv[], void *userdata) {
- _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
uint64_t usage, total = 0;
char fb[FORMAT_BYTES_MAX];
@@ -2384,15 +2384,22 @@ static int clean_images(int argc, char *argv[], void *userdata) {
unsigned c = 0;
int r;
- r = sd_bus_call_method(
+ r = sd_bus_message_new_method_call(
bus,
+ &m,
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
"org.freedesktop.machine1.Manager",
- "CleanPool",
- &error,
- &reply,
- "s", arg_all ? "all" : "hidden");
+ "CleanPool");
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ r = sd_bus_message_append(m, "s", arg_all ? "all" : "hidden");
+ if (r < 0)
+ return bus_log_create_error(r);
+
+ /* This is a slow operation, hence permit a longer time for completion. */
+ r = sd_bus_call(bus, m, USEC_INFINITY, &error, &reply);
if (r < 0)
return log_error_errno(r, "Could not clean pool: %s", bus_error_message(&error, r));