machinectl.c revision 56b921c3d863f0e098f60f934e6c5880575c68ab
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2013 Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic bool arg_all = false;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic bool arg_full = false;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic bool arg_no_pager = false;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic bool arg_legend = true;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic bool arg_read_only = false;
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic bool arg_mkdir = false;
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic bool arg_quiet = false;
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic bool arg_ask_password = true;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic OutputMode arg_output = OUTPUT_SHORT;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic bool arg_force = false;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic const char* arg_dkr_index_url = NULL;
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic void pager_open_if_enabled(void) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic void polkit_agent_open_if_enabled(void) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen /* Open the polkit agent as a child process if necessary */
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen if (arg_transport != BUS_TRANSPORT_LOCAL)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersentypedef struct MachineInfo {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int compare_machine_info(const void *a, const void *b) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const MachineInfo *x = a, *y = b;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poetteringstatic int list_machines(int argc, char *argv[], void *userdata) {
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering size_t max_name = strlen("MACHINE"), max_class = strlen("CLASS"), max_service = strlen("SERVICE");
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering _cleanup_free_ MachineInfo *machines = NULL;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering const char *name, *class, *service, *object;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering size_t n_machines = 0, n_allocated = 0, j;
aa1936ea1a89c2bb968ba33e3274898a4eeae771Lennart Poettering "org.freedesktop.machine1",
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering "org.freedesktop.machine1.Manager",
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering "ListMachines",
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen log_error("Could not get machines: %s", bus_error_message(&error, -r));
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering r = sd_bus_message_enter_container(reply, 'a', "(ssso)");
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering while ((r = sd_bus_message_read(reply, "(ssso)", &name, &class, &service, &object)) > 0) {
9d12709626bccc0cae677a7035f62efe6aabb4abLennart Poettering if (!GREEDY_REALLOC(machines, n_allocated, n_machines + 1))
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_exit_container(reply);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering qsort_safe(machines, n_machines, sizeof(MachineInfo), compare_machine_info);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering for (j = 0; j < n_machines; j++)
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering printf("\n%zu machines listed.\n", n_machines);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poetteringtypedef struct ImageInfo {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poetteringstatic int compare_image_info(const void *a, const void *b) {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering const ImageInfo *x = a, *y = b;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poetteringstatic int list_images(int argc, char *argv[], void *userdata) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering size_t max_name = strlen("NAME"), max_type = strlen("TYPE"), max_size = strlen("USAGE"), max_crtime = strlen("CREATED"), max_mtime = strlen("MODIFIED");
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering "org.freedesktop.machine1",
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering "org.freedesktop.machine1.Manager",
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering log_error("Could not get images: %s", bus_error_message(&error, -r));
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssbttto)");
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering while ((r = sd_bus_message_read(reply, "(ssbttto)", &name, &type, &read_only, &crtime, &mtime, &size, &object)) > 0) {
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering char buf[MAX(FORMAT_TIMESTAMP_MAX, FORMAT_BYTES_MAX)];
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (!GREEDY_REALLOC(images, n_allocated, n_images + 1))
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers l = strlen(strna(format_timestamp(buf, sizeof(buf), crtime)));
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering l = strlen(strna(format_timestamp(buf, sizeof(buf), mtime)));
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering l = strlen(strna(format_bytes(buf, sizeof(buf), size)));
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_exit_container(reply);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering qsort_safe(images, n_images, sizeof(ImageInfo), compare_image_info);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering printf("%-*s %-*s %-3s %-*s %-*s %-*s\n",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering for (j = 0; j < n_images; j++) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering char crtime_buf[FORMAT_TIMESTAMP_MAX], mtime_buf[FORMAT_TIMESTAMP_MAX], size_buf[FORMAT_BYTES_MAX];
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering printf("%-*s %-*s %s%-3s%s %-*s %-*s %-*s\n",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering images[j].read_only ? ansi_highlight_red() : "", yes_no(images[j].read_only), images[j].read_only ? ansi_highlight_off() : "",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (int) max_size, strna(format_bytes(size_buf, sizeof(size_buf), images[j].size)),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (int) max_crtime, strna(format_timestamp(crtime_buf, sizeof(crtime_buf), images[j].crtime)),
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (int) max_mtime, strna(format_timestamp(mtime_buf, sizeof(mtime_buf), images[j].mtime)));
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering printf("\n%zu images listed.\n", n_images);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int show_unit_cgroup(sd_bus *bus, const char *unit, pid_t leader) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering if (arg_transport == BUS_TRANSPORT_REMOTE)
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering endswith(unit, ".scope") ? "org.freedesktop.systemd1.Scope" : "org.freedesktop.systemd1.Service",
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "ControlGroup",
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering log_error("Failed to query ControlGroup: %s", bus_error_message(&error, -r));
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = sd_bus_message_read(reply, "s", &cgroup);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, cgroup, false) != 0 && leader <= 0)
e7e9b6bb0b0bc5b1eb256a44f8afec6b634f26efZbigniew Jędrzejewski-Szmek show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, cgroup, "\t\t ", c, false, &leader, leader > 0, get_output_flags());
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poetteringstatic int print_addresses(sd_bus *bus, const char *name, int ifi, const char *prefix, const char *prefix2) {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "org.freedesktop.machine1",
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "org.freedesktop.machine1.Manager",
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering "GetMachineAddresses",
a6c616024db23fef34152c1432892824a07799ccLennart Poettering r = sd_bus_message_enter_container(reply, 'a', "(iay)");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering while ((r = sd_bus_message_enter_container(reply, 'r', "iay")) > 0) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const void *a;
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers char buffer[MAX(INET6_ADDRSTRLEN, INET_ADDRSTRLEN)];
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen r = sd_bus_message_read_array(reply, 'y', &a, &sz);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering fputs(inet_ntop(family, a, buffer, sizeof(buffer)), stdout);
27e72d6b22890ba4a8cbc05c49667cd1cccf1461Simon Peetersstatic int print_os_release(sd_bus *bus, const char *name, const char *prefix) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers "org.freedesktop.machine1",
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers "org.freedesktop.machine1.Manager",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "GetMachineOSRelease",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_enter_container(reply, 'a', "{ss}");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering while ((r = sd_bus_message_read(reply, "{ss}", &k, &v)) > 0) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_exit_container(reply);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!sd_id128_equal(i->id, SD_ID128_NULL))
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering printf("(" SD_ID128_FORMAT_STR ")\n", SD_ID128_FORMAT_VAL(i->id));
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering s1 = format_timestamp_relative(since1, sizeof(since1), i->timestamp.realtime);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering s2 = format_timestamp(since2, sizeof(since2), i->timestamp.realtime);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen if (i->leader > 0) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen printf("\t Leader: %u", (unsigned) i->leader);
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering } else if (i->class)
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering printf("\t Root: %s\n", i->root_directory);
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering for (c = 0; c < i->n_netif; c++) {
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering "\t Address: ",
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering print_os_release(bus, i->name, "\t OS: ");
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering show_unit_cgroup(bus, i->unit, i->leader);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering if (arg_transport == BUS_TRANSPORT_LOCAL) {
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering get_output_flags() | OUTPUT_BEGIN_NEWLINE,
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringstatic int map_netif(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering const void *v;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_read_array(m, SD_BUS_TYPE_INT32, &v, &l);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringstatic int show_machine_info(const char *verb, sd_bus *bus, const char *path, bool *new_line) {
bc9fd78c7bfc39881e19457e476393635f8b0442Lennart Poettering static const struct bus_properties_map map[] = {
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering { "Name", "s", NULL, offsetof(MachineStatusInfo, name) },
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering { "Class", "s", NULL, offsetof(MachineStatusInfo, class) },
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering { "Service", "s", NULL, offsetof(MachineStatusInfo, service) },
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering { "Unit", "s", NULL, offsetof(MachineStatusInfo, unit) },
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering { "RootDirectory", "s", NULL, offsetof(MachineStatusInfo, root_directory) },
03e334a1c7dc8c20c38902aa039440763acc9b17Lennart Poettering { "Leader", "u", NULL, offsetof(MachineStatusInfo, leader) },
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering { "Timestamp", "t", NULL, offsetof(MachineStatusInfo, timestamp.realtime) },
fbadf04511389c4a0687ba5e9baf0ecebdbb07f1Lennart Poettering { "TimestampMonotonic", "t", NULL, offsetof(MachineStatusInfo, timestamp.monotonic) },
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering { "Id", "ay", bus_map_id128, offsetof(MachineStatusInfo, id) },
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering { "NetworkInterfaces", "ai", map_netif, 0 },
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering "org.freedesktop.machine1",
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering return log_error_errno(r, "Could not get properties: %m");
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringstatic int show_machine_properties(sd_bus *bus, const char *path, bool *new_line) {
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, arg_property, arg_all);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering log_error_errno(r, "Could not get properties: %m");
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poetteringstatic int show_machine(int argc, char *argv[], void *userdata) {
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering /* If no argument is specified, inspect the manager
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering r = show_machine_properties(bus, "/org/freedesktop/machine1", &new_line);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering "org.freedesktop.machine1",
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering "org.freedesktop.machine1.Manager",
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering log_error("Could not get path to machine: %s", bus_error_message(&error, -r));
5b30bef856e89a571df57b7b953e9a1409d9acedLennart Poettering r = sd_bus_message_read(reply, "o", &path);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering r = show_machine_properties(bus, path, &new_line);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering r = show_machine_info(argv[0], bus, path, &new_line);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringstatic void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering char ts_relative[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering char ts_absolute[FORMAT_TIMESTAMP_MAX], *s2;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering char bs_exclusive[FORMAT_BYTES_MAX], *s4;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering i->read_only ? ansi_highlight_red() : "",
a6c616024db23fef34152c1432892824a07799ccLennart Poettering i->read_only ? ansi_highlight_off() : "");
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->crtime);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering s2 = format_timestamp(ts_absolute, sizeof(ts_absolute), i->crtime);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->mtime);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering s2 = format_timestamp(ts_absolute, sizeof(ts_absolute), i->mtime);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering s3 = format_bytes(bs, sizeof(bs), i->usage);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering s4 = i->usage_exclusive != i->usage ? format_bytes(bs_exclusive, sizeof(bs_exclusive), i->usage_exclusive) : NULL;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering printf("\t Usage: %s (exclusive: %s)\n", s3, s4);
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering s3 = format_bytes(bs, sizeof(bs), i->limit);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering s4 = i->limit_exclusive != i->limit ? format_bytes(bs_exclusive, sizeof(bs_exclusive), i->limit_exclusive) : NULL;
04d39279245834494baccfdb9349db8bf80abd13Lennart Poettering printf("\t Limit: %s (exclusive: %s)\n", s3, s4);
04d39279245834494baccfdb9349db8bf80abd13Lennart Poetteringstatic int show_image_info(const char *verb, sd_bus *bus, const char *path, bool *new_line) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering static const struct bus_properties_map map[] = {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "Name", "s", NULL, offsetof(ImageStatusInfo, name) },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "Path", "s", NULL, offsetof(ImageStatusInfo, path) },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "Type", "s", NULL, offsetof(ImageStatusInfo, type) },
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering { "ReadOnly", "b", NULL, offsetof(ImageStatusInfo, read_only) },
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen { "CreationTimestamp", "t", NULL, offsetof(ImageStatusInfo, crtime) },
53755121e1c8ebd3db0330bc82965ecf9a986449Lennart Poettering { "ModificationTimestamp", "t", NULL, offsetof(ImageStatusInfo, mtime) },
53755121e1c8ebd3db0330bc82965ecf9a986449Lennart Poettering { "Usage", "t", NULL, offsetof(ImageStatusInfo, usage) },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "Limit", "t", NULL, offsetof(ImageStatusInfo, limit) },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "UsageExclusive", "t", NULL, offsetof(ImageStatusInfo, usage_exclusive) },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "LimitExclusive", "t", NULL, offsetof(ImageStatusInfo, limit_exclusive) },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.machine1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return log_error_errno(r, "Could not get properties: %m");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int show_image_properties(sd_bus *bus, const char *path, bool *new_line) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, arg_property, arg_all);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_error_errno(r, "Could not get properties: %m");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int show_image(int argc, char *argv[], void *userdata) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* If no argument is specified, inspect the manager
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = show_image_properties(bus, "/org/freedesktop/machine1", &new_line);
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen "org.freedesktop.machine1",
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen "org.freedesktop.machine1.Manager",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_error("Could not get path to image: %s", bus_error_message(&error, -r));
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = sd_bus_message_read(reply, "o", &path);
d21ed1ead18d16d35c30299a69d3366847f8a039Lennart Poettering r = show_image_properties(bus, path, &new_line);
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering r = show_image_info(argv[0], bus, path, &new_line);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int kill_machine(int argc, char *argv[], void *userdata) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.machine1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.machine1.Manager",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "KillMachine",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "ssi", argv[i], arg_kill_who, arg_signal);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_error("Could not kill machine: %s", bus_error_message(&error, -r));
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int reboot_machine(int argc, char *argv[], void *userdata) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering arg_signal = SIGINT; /* sysvinit + systemd */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return kill_machine(argc, argv, userdata);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int poweroff_machine(int argc, char *argv[], void *userdata) {
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering arg_signal = SIGRTMIN+4; /* only systemd */
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return kill_machine(argc, argv, userdata);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int terminate_machine(int argc, char *argv[], void *userdata) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.machine1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.machine1.Manager",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "TerminateMachine",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_error("Could not terminate machine: %s", bus_error_message(&error, -r));
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int machine_get_leader(sd_bus *bus, const char *name, pid_t *ret) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *reply2 = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.machine1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.machine1.Manager",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_error("Could not get path to machine: %s", bus_error_message(&error, -r));
84f6181c2ac99a0514ca5e0c8fc8c8e284caf789Lennart Poettering r = sd_bus_message_read(reply, "o", &object);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen "org.freedesktop.machine1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.machine1.Machine",
84f6181c2ac99a0514ca5e0c8fc8c8e284caf789Lennart Poettering return log_error_errno(r, "Failed to retrieve PID of leader: %m");
84f6181c2ac99a0514ca5e0c8fc8c8e284caf789Lennart Poettering r = sd_bus_message_read(reply2, "u", &leader);
return bus_log_parse_error(r);
char *dest, *host_path, *container_path, *host_dirname, *host_basename, *container_dirname, *container_basename, *t;
bool copy_from;
return -EINVAL;
if (child < 0)
if (child == 0) {
int containerfd;
int mntfd;
if (mntfd < 0) {
if (containerfd < 0) {
if (copy_from)
return -EIO;
return -EIO;
const char *dest;
return -EINVAL;
return -ENOTSUP;
mount_slave_created = true;
goto finish;
mount_slave_mounted = true;
goto finish;
goto finish;
mount_tmp_created = true;
goto finish;
mount_tmp_mounted = true;
if (arg_read_only)
goto finish;
goto finish;
mount_outside_created = true;
goto finish;
mount_outside_mounted = true;
mount_tmp_mounted = false;
mount_tmp_created = false;
mount_slave_mounted = false;
mount_slave_created = false;
if (child < 0) {
goto finish;
if (child == 0) {
const char *mount_inside;
int mntfd;
if (mntfd < 0) {
if (arg_mkdir)
goto finish;
r = -EIO;
goto finish;
r = -EIO;
goto finish;
if (mount_tmp_mounted)
if (mount_tmp_created)
if (mount_slave_mounted)
if (mount_slave_created)
static int on_machine_removed(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
assert(m);
if (*forward) {
char last_char = 0;
bool machine_died;
return -ENOTSUP;
"path='/org/freedesktop/machine1',",
"/org/freedesktop/machine1",
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_parse_error(r);
if (machine_died)
return ret;
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
return -EINVAL;
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
return log_oom();
const char *object;
return -EINVAL;
return log_oom();
if (!unit)
return log_oom();
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_parse_error(r);
return log_oom();
int carries_install_info = 0;
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
method);
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_create_error(r);
return -EINVAL;
return log_oom();
if (!unit)
return log_oom();
return bus_log_create_error(r);
r = sd_bus_message_close_container(m);
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_parse_error(r);
m = sd_bus_message_unref(m);
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
return bus_log_create_error(r);
return bus_log_create_error(r);
unsigned priority;
assert(m);
static int match_transfer_removed(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
assert(m);
static int transfer_signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
assert(s);
if (!arg_quiet)
log_info("Continuing download in the background. Use \"machinectl cancel-transfer %" PRIu32 "\" to arbort transfer.", PTR_TO_UINT32(userdata));
assert(m);
return bus_log_create_error(r);
r = sd_bus_add_match(
bus,
"path='/org/freedesktop/import1'",
r = sd_bus_add_match(
bus,
return bus_log_parse_error(r);
if (!arg_quiet)
return -EINVAL;
local = l;
if (local) {
return -EINVAL;
bus,
"/org/freedesktop/import1",
return bus_log_create_error(r);
return bus_log_create_error(r);
return -EINVAL;
local = l;
if (local) {
return -EINVAL;
bus,
"/org/freedesktop/import1",
return bus_log_create_error(r);
return bus_log_create_error(r);
return -EINVAL;
if (tag) {
tag++;
return -EINVAL;
return -EINVAL;
if (local)
local++;
if (local) {
return -EINVAL;
bus,
"/org/freedesktop/import1",
return bus_log_create_error(r);
tag,
return bus_log_create_error(r);
typedef struct TransferInfo {
const char *type;
const char *remote;
const char *local;
double progress;
} TransferInfo;
static int compare_transfer_info(const void *a, const void *b) {
const TransferInfo *x = a, *y = b;
double progress;
r = sd_bus_call_method(
bus,
"/org/freedesktop/import1",
&error,
&reply,
NULL);
return bus_log_parse_error(r);
while ((r = sd_bus_message_read(reply, "(usssdo)", &id, &type, &remote, &local, &progress, &object)) > 0) {
size_t l;
return log_oom();
if (l > max_type)
max_type = l;
if (l > max_remote)
max_remote = l;
if (l > max_local)
max_local = l;
n_transfers ++;
return bus_log_parse_error(r);
return bus_log_parse_error(r);
if (arg_legend)
for (j = 0; j < n_transfers; j++)
if (arg_legend)
r = sd_bus_call_method(
bus,
"/org/freedesktop/import1",
&error,
NULL,
" show NAME... Show properties of one or more VMs/containers\n"
" terminate NAME... Terminate one or more VMs/containers\n"
case ARG_VERSION:
return log_oom();
arg_all = true;
arg_all = true;
arg_full = true;
return -EINVAL;
if (arg_output < 0) {
return -EINVAL;
case ARG_NO_PAGER:
arg_no_pager = true;
case ARG_NO_LEGEND:
arg_legend = false;
case ARG_KILL_WHO:
if (arg_signal < 0) {
return -EINVAL;
case ARG_NO_ASK_PASSWORD:
arg_ask_password = false;
case ARG_READ_ONLY:
arg_read_only = true;
case ARG_MKDIR:
arg_mkdir = true;
arg_quiet = true;
case ARG_VERIFY:
if (arg_verify < 0) {
return -EINVAL;
case ARG_FORCE:
arg_force = true;
case ARG_DKR_INDEX_URL:
return -EINVAL;
return -EINVAL;
log_open();
goto finish;
goto finish;
pager_close();