machinectl.c revision 7705a4053d83b5da22c9354a44be26ffc8e24f5a
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock This file is part of systemd.
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock Copyright 2013 Lennart Poettering
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock systemd is free software; you can redistribute it and/or modify it
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock under the terms of the GNU Lesser General Public License as published by
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock the Free Software Foundation; either version 2.1 of the License, or
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock (at your option) any later version.
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock systemd is distributed in the hope that it will be useful, but
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock WITHOUT ANY WARRANTY; without even the implied warranty of
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock Lesser General Public License for more details.
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock You should have received a copy of the GNU Lesser General Public License
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock along with systemd; If not, see <http://www.gnu.org/licenses/>.
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_all = false;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_full = false;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_no_pager = false;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_legend = true;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_read_only = false;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_mkdir = false;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_quiet = false;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_ask_password = true;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic bool arg_force = false;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic void pager_open_if_enabled(void) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic void polkit_agent_open_if_enabled(void) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock /* Open the polkit agent as a child process if necessary */
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrocktypedef struct MachineInfo {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const char *name;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const char *class;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const char *service;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int compare_machine_info(const void *a, const void *b) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const MachineInfo *x = a, *y = b;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int list_machines(int argc, char *argv[], void *userdata) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock size_t max_name = strlen("MACHINE"), max_class = strlen("CLASS"), max_service = strlen("SERVICE");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1.Manager",
9af3851a3a831b4de34b42482c22351e14f33f16eschrock "ListMachines",
9af3851a3a831b4de34b42482c22351e14f33f16eschrock if (r < 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock log_error("Could not get machines: %s", bus_error_message(&error, -r));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = sd_bus_message_enter_container(reply, 'a', "(ssso)");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock while ((r = sd_bus_message_read(reply, "(ssso)", &name, &class, &service, &object)) > 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (!GREEDY_REALLOC(machines, n_allocated, n_machines + 1))
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock qsort_safe(machines, n_machines, sizeof(MachineInfo), compare_machine_info);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock for (j = 0; j < n_machines; j++)
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrocktypedef struct ImageInfo {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const char *name;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const char *type;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int compare_image_info(const void *a, const void *b) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const ImageInfo *x = a, *y = b;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int list_images(int argc, char *argv[], void *userdata) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock size_t max_name = strlen("NAME"), max_type = strlen("TYPE"), max_size = strlen("USAGE"), max_crtime = strlen("CREATED"), max_mtime = strlen("MODIFIED");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1.Manager",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "ListImages",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (r < 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock log_error("Could not get images: %s", bus_error_message(&error, -r));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssbttto)");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock while ((r = sd_bus_message_read(reply, "(ssbttto)", &name, &type, &read_only, &crtime, &mtime, &size, &object)) > 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock char buf[MAX(FORMAT_TIMESTAMP_MAX, FORMAT_BYTES_MAX)];
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (!GREEDY_REALLOC(images, n_allocated, n_images + 1))
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock l = strlen(strna(format_timestamp(buf, sizeof(buf), crtime)));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock l = strlen(strna(format_timestamp(buf, sizeof(buf), mtime)));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock l = strlen(strna(format_bytes(buf, sizeof(buf), size)));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock qsort_safe(images, n_images, sizeof(ImageInfo), compare_image_info);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock for (j = 0; j < n_images; j++) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock char crtime_buf[FORMAT_TIMESTAMP_MAX], mtime_buf[FORMAT_TIMESTAMP_MAX], size_buf[FORMAT_BYTES_MAX];
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock images[j].read_only ? ansi_highlight_red() : "", yes_no(images[j].read_only), images[j].read_only ? ansi_normal() : "",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock (int) max_size, strna(format_bytes(size_buf, sizeof(size_buf), images[j].size)),
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock (int) max_crtime, strna(format_timestamp(crtime_buf, sizeof(crtime_buf), images[j].crtime)),
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock (int) max_mtime, strna(format_timestamp(mtime_buf, sizeof(mtime_buf), images[j].mtime)));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int show_unit_cgroup(sd_bus *bus, const char *unit, pid_t leader) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const char *cgroup;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock unsigned c;
9af3851a3a831b4de34b42482c22351e14f33f16eschrock "ControlGroup",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (r < 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock log_error("Failed to query ControlGroup: %s", bus_error_message(&error, -r));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, cgroup) != 0 && leader <= 0)
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (c > 18)
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, cgroup, "\t\t ", c, false, &leader, leader > 0, get_output_flags());
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int print_addresses(sd_bus *bus, const char *name, int ifi, const char *prefix, const char *prefix2) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1.Manager",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "GetMachineAddresses",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = sd_bus_message_enter_container(reply, 'a', "(iay)");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock while ((r = sd_bus_message_enter_container(reply, 'r', "iay")) > 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const void *a;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock char buffer[MAX(INET6_ADDRSTRLEN, INET_ADDRSTRLEN)];
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = sd_bus_message_read_array(reply, 'y', &a, &sz);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock fputs(inet_ntop(family, a, buffer, sizeof(buffer)), stdout);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int print_os_release(sd_bus *bus, const char *name, const char *prefix) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1.Manager",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "GetMachineOSRelease",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = sd_bus_message_enter_container(reply, 'a', "{ss}");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock while ((r = sd_bus_message_read(reply, "{ss}", &k, &v)) > 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrocktypedef struct MachineStatusInfo {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic void machine_status_info_clear(MachineStatusInfo *info) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock printf("(" SD_ID128_FORMAT_STR ")\n", SD_ID128_FORMAT_VAL(i->id));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock s1 = format_timestamp_relative(since1, sizeof(since1), i->timestamp.realtime);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock s2 = format_timestamp(since2, sizeof(since2), i->timestamp.realtime);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (i->leader > 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock } else if (i->class)
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (i->n_netif > 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock unsigned c;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock for (c = 0; c < i->n_netif; c++) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "\t Address: ",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int map_netif(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock const void *v;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = sd_bus_message_read_array(m, SD_BUS_TYPE_INT32, &v, &l);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (r == 0)
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int show_machine_info(const char *verb, sd_bus *bus, const char *path, bool *new_line) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Name", "s", NULL, offsetof(MachineStatusInfo, name) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Class", "s", NULL, offsetof(MachineStatusInfo, class) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Service", "s", NULL, offsetof(MachineStatusInfo, service) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Unit", "s", NULL, offsetof(MachineStatusInfo, unit) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "RootDirectory", "s", NULL, offsetof(MachineStatusInfo, root_directory) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Leader", "u", NULL, offsetof(MachineStatusInfo, leader) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Timestamp", "t", NULL, offsetof(MachineStatusInfo, timestamp.realtime) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "TimestampMonotonic", "t", NULL, offsetof(MachineStatusInfo, timestamp.monotonic) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Id", "ay", bus_map_id128, offsetof(MachineStatusInfo, id) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_(machine_status_info_clear) MachineStatusInfo info = {};
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock return log_error_errno(r, "Could not get properties: %m");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int show_machine_properties(sd_bus *bus, const char *path, bool *new_line) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, arg_property, arg_all);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock log_error_errno(r, "Could not get properties: %m");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int show_machine(int argc, char *argv[], void *userdata) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock int r = 0, i;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock /* If no argument is specified, inspect the manager
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock * itself */
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = show_machine_properties(bus, "/org/freedesktop/machine1", &new_line);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1.Manager",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "GetMachine",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (r < 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock log_error("Could not get path to machine: %s", bus_error_message(&error, -r));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = show_machine_info(argv[0], bus, path, &new_line);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrocktypedef struct ImageStatusInfo {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic void image_status_info_clear(ImageStatusInfo *info) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock char ts_relative[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->crtime);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock s2 = format_timestamp(ts_absolute, sizeof(ts_absolute), i->crtime);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->mtime);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock s2 = format_timestamp(ts_absolute, sizeof(ts_absolute), i->mtime);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock s4 = i->usage_exclusive != i->usage ? format_bytes(bs_exclusive, sizeof(bs_exclusive), i->usage_exclusive) : NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock s4 = i->limit_exclusive != i->limit ? format_bytes(bs_exclusive, sizeof(bs_exclusive), i->limit_exclusive) : NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int show_image_info(sd_bus *bus, const char *path, bool *new_line) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Name", "s", NULL, offsetof(ImageStatusInfo, name) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Path", "s", NULL, offsetof(ImageStatusInfo, path) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Type", "s", NULL, offsetof(ImageStatusInfo, type) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "ReadOnly", "b", NULL, offsetof(ImageStatusInfo, read_only) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "CreationTimestamp", "t", NULL, offsetof(ImageStatusInfo, crtime) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "ModificationTimestamp", "t", NULL, offsetof(ImageStatusInfo, mtime) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Usage", "t", NULL, offsetof(ImageStatusInfo, usage) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "Limit", "t", NULL, offsetof(ImageStatusInfo, limit) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "UsageExclusive", "t", NULL, offsetof(ImageStatusInfo, usage_exclusive) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "LimitExclusive", "t", NULL, offsetof(ImageStatusInfo, limit_exclusive) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_(image_status_info_clear) ImageStatusInfo info = {};
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock return log_error_errno(r, "Could not get properties: %m");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrocktypedef struct PoolStatusInfo {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic void pool_status_info_clear(PoolStatusInfo *info) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic void print_pool_status_info(sd_bus *bus, PoolStatusInfo *i) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "PoolPath", "s", NULL, offsetof(PoolStatusInfo, path) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "PoolUsage", "t", NULL, offsetof(PoolStatusInfo, usage) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock { "PoolLimit", "t", NULL, offsetof(PoolStatusInfo, limit) },
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_(pool_status_info_clear) PoolStatusInfo info = {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock return log_error_errno(r, "Could not get properties: %m");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int show_image_properties(sd_bus *bus, const char *path, bool *new_line) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, arg_property, arg_all);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock log_error_errno(r, "Could not get properties: %m");
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int show_image(int argc, char *argv[], void *userdata) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock int r = 0, i;
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock /* If no argument is specified, inspect the manager
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock * itself */
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock r = show_image_properties(bus, "/org/freedesktop/machine1", &new_line);
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "org.freedesktop.machine1.Manager",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock "GetImage",
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock if (r < 0) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock log_error("Could not get path to image: %s", bus_error_message(&error, -r));
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrockstatic int kill_machine(int argc, char *argv[], void *userdata) {
275c9da86e89f8abf71135cf63d9fc23671b2e60eschrock _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
if (!arg_kill_who)
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
bool copy_from;
if (!abs_host_path)
return log_oom();
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
assert(m);
if (*forward) {
static int process_forward(sd_event *event, PTYForward **forward, int master, PTYForwardFlags flags, const char *name) {
char last_char = 0;
bool machine_died;
int ret = 0, r;
if (machine_died)
return ret;
return -EINVAL;
return -EOPNOTSUPP;
"path='/org/freedesktop/machine1',",
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
&reply,
return bus_log_parse_error(r);
return -EOPNOTSUPP;
return log_oom();
if (arg_uid)
else if (machine) {
const char *at;
if (at) {
"path='/org/freedesktop/machine1',",
bus,
"/org/freedesktop/machine1",
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_create_error(r);
return bus_log_parse_error(r);
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 -EINVAL;
return log_oom();
return log_oom();
const char *object;
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
&reply,
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);
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);
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
&error,
NULL,
NULL);
unsigned priority;
assert(m);
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 abort transfer.", PTR_TO_UINT32(userdata));
assert(m);
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)
else if (path)
if (!local) {
return -EINVAL;
return log_oom();
return -EINVAL;
if (path) {
if (fd < 0)
bus,
"/org/freedesktop/import1",
return bus_log_create_error(r);
return bus_log_create_error(r);
else if (path)
if (!local) {
return -EINVAL;
return log_oom();
return -EINVAL;
if (path) {
if (fd < 0)
bus,
"/org/freedesktop/import1",
return bus_log_create_error(r);
return bus_log_create_error(r);
static void determine_compression_from_filename(const char *p) {
if (arg_format)
return -EINVAL;
if (path) {
if (fd < 0)
bus,
"/org/freedesktop/import1",
return bus_log_create_error(r);
return bus_log_create_error(r);
return -EINVAL;
if (path) {
if (fd < 0)
bus,
"/org/freedesktop/import1",
return bus_log_create_error(r);
return bus_log_create_error(r);
return -EINVAL;
local = l;
if (local) {
return log_oom();
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 log_oom();
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,
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&error,
NULL,
r = sd_bus_call_method(
bus,
"/org/freedesktop/machine1",
&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 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;
case ARG_FORMAT:
return -EINVAL;
case ARG_UID:
case ARG_SETENV:
return -EINVAL;
return log_oom();
return -EINVAL;
log_open();
goto finish;
goto finish;
pager_close();