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/>.
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersenstatic bool arg_legend = true;
d21ed1ead18d16d35c30299a69d3366847f8a039Lennart Poetteringstatic BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poetteringstatic OutputMode arg_output = OUTPUT_SHORT;
6e18cc9fa078d2a967251017ddb5baefb104b720Lennart Poetteringstatic ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poetteringstatic void polkit_agent_open_if_enabled(void) {
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering /* Open the polkit agent as a child process if necessary */
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering if (arg_transport != BUS_TRANSPORT_LOCAL)
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poetteringstatic OutputFlags get_output_flags(void) {
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poetteringstatic int compare_machine_info(const void *a, const void *b) {
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering const MachineInfo *x = a, *y = b;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int list_machines(int argc, char *argv[], void *userdata) {
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering size_t max_name = strlen("MACHINE"), max_class = strlen("CLASS"), max_service = strlen("SERVICE");
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering _cleanup_free_ MachineInfo *machines = NULL;
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering size_t n_machines = 0, n_allocated = 0, j;
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen "org.freedesktop.machine1",
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen "org.freedesktop.machine1.Manager",
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen "ListMachines",
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen log_error("Could not get machines: %s", bus_error_message(&error, -r));
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering r = sd_bus_message_enter_container(reply, 'a', "(ssso)");
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen while ((r = sd_bus_message_read(reply, "(ssso)", &name, &class, &service, &object)) > 0) {
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering if (!GREEDY_REALLOC(machines, n_allocated, n_machines + 1))
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering qsort_safe(machines, n_machines, sizeof(MachineInfo), compare_machine_info);
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering for (j = 0; j < n_machines; j++)
0b63e2789f984e84f40bf6e49f5da15c87298cedLennart Poettering printf("\n%zu machines listed.\n", n_machines);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poetteringstatic int compare_image_info(const void *a, const void *b) {
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering const ImageInfo *x = a, *y = b;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int list_images(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering size_t max_name = strlen("NAME"), max_type = strlen("TYPE"), max_size = strlen("USAGE"), max_crtime = strlen("CREATED"), max_mtime = strlen("MODIFIED");
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering "org.freedesktop.machine1",
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering "org.freedesktop.machine1.Manager",
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering log_error("Could not get images: %s", bus_error_message(&error, -r));
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssbttto)");
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering while ((r = sd_bus_message_read(reply, "(ssbttto)", &name, &type, &read_only, &crtime, &mtime, &size, &object)) > 0) {
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering char buf[MAX(FORMAT_TIMESTAMP_MAX, FORMAT_BYTES_MAX)];
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (!GREEDY_REALLOC(images, n_allocated, n_images + 1))
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering l = strlen(strna(format_timestamp(buf, sizeof(buf), crtime)));
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering l = strlen(strna(format_timestamp(buf, sizeof(buf), mtime)));
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering l = strlen(strna(format_bytes(buf, sizeof(buf), size)));
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering r = sd_bus_message_exit_container(reply);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering qsort_safe(images, n_images, sizeof(ImageInfo), compare_image_info);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering printf("%-*s %-*s %-3s %-*s %-*s %-*s\n",
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering for (j = 0; j < n_images; j++) {
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering char crtime_buf[FORMAT_TIMESTAMP_MAX], mtime_buf[FORMAT_TIMESTAMP_MAX], size_buf[FORMAT_BYTES_MAX];
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering printf("%-*s %-*s %s%-3s%s %-*s %-*s %-*s\n",
1fc464f6fbecfc5d8ba9f7b98d19e21fb324bfb9Lennart Poettering images[j].read_only ? ansi_highlight_red() : "", yes_no(images[j].read_only), images[j].read_only ? ansi_normal() : "",
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering (int) max_size, strna(format_bytes(size_buf, sizeof(size_buf), images[j].size)),
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering (int) max_crtime, strna(format_timestamp(crtime_buf, sizeof(crtime_buf), images[j].crtime)),
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering (int) max_mtime, strna(format_timestamp(mtime_buf, sizeof(mtime_buf), images[j].mtime)));
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering printf("\n%zu images listed.\n", n_images);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poetteringstatic int show_unit_cgroup(sd_bus *bus, const char *unit, pid_t leader) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
d21ed1ead18d16d35c30299a69d3366847f8a039Lennart Poettering if (arg_transport == BUS_TRANSPORT_REMOTE)
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering "ControlGroup",
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen log_error("Failed to query ControlGroup: %s", bus_error_message(&error, -r));
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering r = sd_bus_message_read(reply, "s", &cgroup);
6f883237f1b8a96ec0ea354866e033b6fcea9506Lennart Poettering if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, cgroup) != 0 && leader <= 0)
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering 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) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering "org.freedesktop.machine1",
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering "org.freedesktop.machine1.Manager",
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering "GetMachineAddresses",
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering r = sd_bus_message_enter_container(reply, 'a', "(iay)");
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering while ((r = sd_bus_message_enter_container(reply, 'r', "iay")) > 0) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering const void *a;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering char buffer[MAX(INET6_ADDRSTRLEN, INET_ADDRSTRLEN)];
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering r = sd_bus_message_read(reply, "i", &family);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_read_array(reply, 'y', &a, &sz);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering fputs(inet_ntop(family, a, buffer, sizeof(buffer)), stdout);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_exit_container(reply);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_exit_container(reply);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poetteringstatic int print_os_release(sd_bus *bus, const char *name, const char *prefix) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering "org.freedesktop.machine1",
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering "org.freedesktop.machine1.Manager",
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering "GetMachineOSRelease",
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = sd_bus_message_enter_container(reply, 'a', "{ss}");
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering while ((r = sd_bus_message_read(reply, "{ss}", &k, &v)) > 0) {
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = sd_bus_message_exit_container(reply);
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannstatic void machine_status_info_clear(MachineStatusInfo *info) {
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersenstatic 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));
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering s1 = format_timestamp_relative(since1, sizeof(since1), i->timestamp.realtime);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering s2 = format_timestamp(since2, sizeof(since2), i->timestamp.realtime);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering printf("\t Leader: %u", (unsigned) i->leader);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering } else if (i->class)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering printf("\t Root: %s\n", i->root_directory);
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering for (c = 0; c < i->n_netif; c++) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering "\t Address: ",
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering print_os_release(bus, i->name, "\t OS: ");
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering show_unit_cgroup(bus, i->unit, i->leader);
ece174c5439021e32ebcc858842de9586072c006Lennart Poettering if (arg_transport == BUS_TRANSPORT_LOCAL)
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering get_output_flags() | OUTPUT_BEGIN_NEWLINE,
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poetteringstatic int map_netif(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering const void *v;
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
f48e75cb9a8112d35855c44a156934f2ee0edb2eLennart Poettering r = sd_bus_message_read_array(m, SD_BUS_TYPE_INT32, &v, &l);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int show_machine_info(const char *verb, sd_bus *bus, const char *path, bool *new_line) {
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers static const struct bus_properties_map map[] = {
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "Name", "s", NULL, offsetof(MachineStatusInfo, name) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "Class", "s", NULL, offsetof(MachineStatusInfo, class) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "Service", "s", NULL, offsetof(MachineStatusInfo, service) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "Unit", "s", NULL, offsetof(MachineStatusInfo, unit) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "RootDirectory", "s", NULL, offsetof(MachineStatusInfo, root_directory) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "Leader", "u", NULL, offsetof(MachineStatusInfo, leader) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "Timestamp", "t", NULL, offsetof(MachineStatusInfo, timestamp.realtime) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "TimestampMonotonic", "t", NULL, offsetof(MachineStatusInfo, timestamp.monotonic) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "Id", "ay", bus_map_id128, offsetof(MachineStatusInfo, id) },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "NetworkInterfaces", "ai", map_netif, 0 },
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann _cleanup_(machine_status_info_clear) MachineStatusInfo info = {};
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers "org.freedesktop.machine1",
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt return log_error_errno(r, "Could not get properties: %m");
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int show_machine_properties(sd_bus *bus, const char *path, bool *new_line) {
27e72d6b22890ba4a8cbc05c49667cd1cccf1461Simon Peeters r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, arg_property, arg_all);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt log_error_errno(r, "Could not get properties: %m");
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int show_machine(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
9f6eb1cd58f2ddf2eb6ba0e4de056e13d938af75Kay Sievers /* If no argument is specified, inspect the manager
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = show_machine_properties(bus, "/org/freedesktop/machine1", &new_line);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen "org.freedesktop.machine1",
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen "org.freedesktop.machine1.Manager",
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen "GetMachine",
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen log_error("Could not get path to machine: %s", bus_error_message(&error, -r));
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = show_machine_properties(bus, path, &new_line);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = show_machine_info(argv[0], bus, path, &new_line);
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannstatic void image_status_info_clear(ImageStatusInfo *info) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering char ts_relative[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering char ts_absolute[FORMAT_TIMESTAMP_MAX], *s2;
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering char bs_exclusive[FORMAT_BYTES_MAX], *s4;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering i->read_only ? ansi_highlight_red() : "",
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->crtime);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering s2 = format_timestamp(ts_absolute, sizeof(ts_absolute), i->crtime);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering s1 = format_timestamp_relative(ts_relative, sizeof(ts_relative), i->mtime);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering s2 = format_timestamp(ts_absolute, sizeof(ts_absolute), i->mtime);
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering s3 = format_bytes(bs, sizeof(bs), i->usage);
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering s4 = i->usage_exclusive != i->usage ? format_bytes(bs_exclusive, sizeof(bs_exclusive), i->usage_exclusive) : NULL;
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering printf("\t Usage: %s (exclusive: %s)\n", s3, s4);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering s3 = format_bytes(bs, sizeof(bs), i->limit);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering s4 = i->limit_exclusive != i->limit ? format_bytes(bs_exclusive, sizeof(bs_exclusive), i->limit_exclusive) : NULL;
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering printf("\t Limit: %s (exclusive: %s)\n", s3, s4);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringstatic int show_image_info(sd_bus *bus, const char *path, bool *new_line) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering static const struct bus_properties_map map[] = {
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering { "Name", "s", NULL, offsetof(ImageStatusInfo, name) },
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering { "Path", "s", NULL, offsetof(ImageStatusInfo, path) },
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering { "Type", "s", NULL, offsetof(ImageStatusInfo, type) },
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering { "ReadOnly", "b", NULL, offsetof(ImageStatusInfo, read_only) },
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering { "CreationTimestamp", "t", NULL, offsetof(ImageStatusInfo, crtime) },
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering { "ModificationTimestamp", "t", NULL, offsetof(ImageStatusInfo, mtime) },
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering { "Usage", "t", NULL, offsetof(ImageStatusInfo, usage) },
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering { "Limit", "t", NULL, offsetof(ImageStatusInfo, limit) },
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering { "UsageExclusive", "t", NULL, offsetof(ImageStatusInfo, usage_exclusive) },
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering { "LimitExclusive", "t", NULL, offsetof(ImageStatusInfo, limit_exclusive) },
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann _cleanup_(image_status_info_clear) ImageStatusInfo info = {};
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering "org.freedesktop.machine1",
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering return log_error_errno(r, "Could not get properties: %m");
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmannstatic void pool_status_info_clear(PoolStatusInfo *info) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringstatic void print_pool_status_info(sd_bus *bus, PoolStatusInfo *i) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering s = format_bytes(bs, sizeof(bs), i->usage);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering s = format_bytes(bs, sizeof(bs), i->limit);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering static const struct bus_properties_map map[] = {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering { "PoolPath", "s", NULL, offsetof(PoolStatusInfo, path) },
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering { "PoolUsage", "t", NULL, offsetof(PoolStatusInfo, usage) },
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering { "PoolLimit", "t", NULL, offsetof(PoolStatusInfo, limit) },
e7e55dbdc38f929805ab2407fbd50886043a9e7cDavid Herrmann _cleanup_(pool_status_info_clear) PoolStatusInfo info = {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering "org.freedesktop.machine1",
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering return log_error_errno(r, "Could not get properties: %m");
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int show_image_properties(sd_bus *bus, const char *path, bool *new_line) {
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = bus_print_all_properties(bus, "org.freedesktop.machine1", path, arg_property, arg_all);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering log_error_errno(r, "Could not get properties: %m");
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poetteringstatic int show_image(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering /* If no argument is specified, inspect the manager
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering r = show_image_properties(bus, "/org/freedesktop/machine1", &new_line);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering "org.freedesktop.machine1",
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering "org.freedesktop.machine1.Manager",
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering log_error("Could not get path to image: %s", bus_error_message(&error, -r));
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = sd_bus_message_read(reply, "o", &path);
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering r = show_image_properties(bus, path, &new_line);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering r = show_image_info(bus, path, &new_line);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int kill_machine(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "org.freedesktop.machine1",
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "org.freedesktop.machine1.Manager",
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "KillMachine",
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering "ssi", argv[i], arg_kill_who, arg_signal);
a1da85830bfaa77b9eb9c54693e5573559c97e50Tom Gundersen log_error("Could not kill machine: %s", bus_error_message(&error, -r));
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int reboot_machine(int argc, char *argv[], void *userdata) {
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering arg_signal = SIGINT; /* sysvinit + systemd */
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering return kill_machine(argc, argv, userdata);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int poweroff_machine(int argc, char *argv[], void *userdata) {
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering arg_signal = SIGRTMIN+4; /* only systemd */
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering return kill_machine(argc, argv, userdata);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int terminate_machine(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering "org.freedesktop.machine1",
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering "org.freedesktop.machine1.Manager",
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering "TerminateMachine",
1dba654b27918c22e413ac5b3c19301f1ff86ad2Lennart Poettering log_error("Could not terminate machine: %s", bus_error_message(&error, -r));
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poetteringstatic int copy_files(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
0f4743651081b5367ab06f238827ddfd4da74e74Lennart Poettering r = path_make_absolute_cwd(host_path, &abs_host_path);
0f4743651081b5367ab06f238827ddfd4da74e74Lennart Poettering return log_error_errno(r, "Failed to make path absolute: %m");
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering "org.freedesktop.machine1",
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering "org.freedesktop.machine1.Manager",
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering copy_from ? "CopyFromMachine" : "CopyToMachine",
0f4743651081b5367ab06f238827ddfd4da74e74Lennart Poettering return log_error_errno(r, "Failed to copy: %s", bus_error_message(&error, r));
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int bind_mount(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering "org.freedesktop.machine1",
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering "org.freedesktop.machine1.Manager",
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering "BindMountMachine",
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering log_error("Failed to bind mount: %s", bus_error_message(&error, -r));
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int on_machine_removed(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering PTYForward ** forward = (PTYForward**) userdata;
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering /* If the forwarder is already initialized, tell it to
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poettering * exit on the next vhangup(), so that we still flush
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poettering * out what might be queued and exit then. */
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poettering r = pty_forward_set_ignore_vhangup(*forward, false);
da054c3782f25b3b18243f6c76dcfcf90ba70274Lennart Poettering log_error_errno(r, "Failed to set ignore_vhangup flag: %m");
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering /* On error, or when the forwarder is not initialized yet, quit immediately */
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(m)), EXIT_FAILURE);
ae3dde801253b1d5f7363bb9fb06bcb230f00eb8Lennart Poetteringstatic int process_forward(sd_event *event, PTYForward **forward, int master, PTYForwardFlags flags, const char *name) {
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGWINCH, SIGTERM, SIGINT, -1) >= 0);
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering log_info("Connected to the local host. Press ^] three times within 1s to exit session.");
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering log_info("Connected to machine %s. Press ^] three times within 1s to exit session.", name);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
ae3dde801253b1d5f7363bb9fb06bcb230f00eb8Lennart Poettering r = pty_forward_new(event, master, flags, forward);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering return log_error_errno(r, "Failed to create PTY forwarder: %m");
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering return log_error_errno(r, "Failed to run event loop: %m");
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering pty_forward_get_last_char(*forward, &last_char);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering pty_forward_get_ignore_vhangup(*forward) == 0;
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering log_info("Machine %s terminated.", name);
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering log_info("Connection to the local host terminated.");
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering log_info("Connection to machine %s terminated.", name);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int login_machine(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
023fb90b83871a15ef7f57e8cd126e3426f99b9eLennart Poettering _cleanup_(pty_forward_freep) PTYForward *forward = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *slot = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_event_unrefp) sd_event *event = NULL;
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering if (!strv_isempty(arg_setenv) || arg_uid) {
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering log_error("--setenv= and --uid= are not supported for 'login'. Use 'shell' instead.");
bf441e3d9371a7e5aa1def66cfc40f0118884644Lennart Poettering if (arg_transport != BUS_TRANSPORT_LOCAL &&
de33fc625725d199629ed074d6278504deb23debLennart Poettering arg_transport != BUS_TRANSPORT_MACHINE) {
923d8fd381bced1c2d90ca53d18629d61a0f454aLennart Poettering log_error("Login only supported on local machines.");
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt return log_error_errno(r, "Failed to get event loop: %m");
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt return log_error_errno(r, "Failed to attach bus to event loop: %m");
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering machine = argc < 2 || isempty(argv[1]) ? ".host" : argv[1];
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "sender='org.freedesktop.machine1',"
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "interface='org.freedesktop.machine1.Manager',"
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "member='MachineRemoved',"
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering r = sd_bus_add_match(bus, &slot, match, on_machine_removed, &forward);
0ec5543c4c0318552a4dcdd83210793347b93081Lennart Poettering return log_error_errno(r, "Failed to add machine removal match: %m");
2723b3b51d409340558e46e37e90525d4f880fe1Lennart Poettering "org.freedesktop.machine1",
2723b3b51d409340558e46e37e90525d4f880fe1Lennart Poettering "org.freedesktop.machine1.Manager",
2723b3b51d409340558e46e37e90525d4f880fe1Lennart Poettering "OpenMachineLogin",
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering log_error("Failed to get login PTY: %s", bus_error_message(&error, -r));
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering r = sd_bus_message_read(reply, "hs", &master, &pty);
ae3dde801253b1d5f7363bb9fb06bcb230f00eb8Lennart Poettering return process_forward(event, &forward, master, PTY_FORWARD_IGNORE_VHANGUP, machine);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poetteringstatic int shell_machine(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL, *m = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering _cleanup_(pty_forward_freep) PTYForward *forward = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *slot = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_event_unrefp) sd_event *event = NULL;
ef3100e9637adda26fa19e7ee8606788320dcde3Lennart Poettering const char *pty, *match, *machine, *path, *uid = NULL;
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering if (arg_transport != BUS_TRANSPORT_LOCAL &&
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering arg_transport != BUS_TRANSPORT_MACHINE) {
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering log_error("Shell only supported on local machines.");
89fec31893bd71292de5ab88cd73816148165b2fLennart Poettering /* Pass $TERM to shell session, if not explicitly specified. */
89fec31893bd71292de5ab88cd73816148165b2fLennart Poettering if (!strv_find_prefix(arg_setenv, "TERM=")) {
89fec31893bd71292de5ab88cd73816148165b2fLennart Poettering const char *t;
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering return log_error_errno(r, "Failed to get event loop: %m");
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering return log_error_errno(r, "Failed to attach bus to event loop: %m");
ef3100e9637adda26fa19e7ee8606788320dcde3Lennart Poettering machine = argc < 2 || isempty(argv[1]) ? NULL : argv[1];
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "sender='org.freedesktop.machine1',"
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "interface='org.freedesktop.machine1.Manager',"
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "member='MachineRemoved',"
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering r = sd_bus_add_match(bus, &slot, match, on_machine_removed, &forward);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering return log_error_errno(r, "Failed to add machine removal match: %m");
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "org.freedesktop.machine1",
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "org.freedesktop.machine1.Manager",
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering "OpenMachineShell");
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering path = argc < 3 || isempty(argv[2]) ? NULL : argv[2];
ef3100e9637adda26fa19e7ee8606788320dcde3Lennart Poettering r = sd_bus_message_append(m, "sss", machine, uid, path);
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering r = sd_bus_message_append_strv(m, strv_length(argv) <= 3 ? NULL : argv + 2);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering r = sd_bus_message_append_strv(m, arg_setenv);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering r = sd_bus_call(bus, m, 0, &error, &reply);
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering log_error("Failed to get shell PTY: %s", bus_error_message(&error, -r));
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering r = sd_bus_message_read(reply, "hs", &master, &pty);
40e1f4ea7458a0a80eaf1ef356e52bfe0835412eLennart Poettering return process_forward(event, &forward, master, 0, machine);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poetteringstatic int remove_image(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering "org.freedesktop.machine1",
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering "org.freedesktop.machine1.Manager",
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering "RemoveImage",
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering log_error("Could not remove image: %s", bus_error_message(&error, -r));
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poetteringstatic int rename_image(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering "org.freedesktop.machine1",
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering "org.freedesktop.machine1.Manager",
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering "RenameImage",
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering log_error("Could not rename image: %s", bus_error_message(&error, -r));
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poetteringstatic int clone_image(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering "org.freedesktop.machine1",
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering "org.freedesktop.machine1.Manager",
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering log_error("Could not clone image: %s", bus_error_message(&error, -r));
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poetteringstatic int read_only_image(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering int b = true, r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering log_error("Failed to parse boolean argument: %s", argv[2]);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering "org.freedesktop.machine1",
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering "org.freedesktop.machine1.Manager",
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering "MarkImageReadOnly",
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering log_error("Could not mark image read-only: %s", bus_error_message(&error, -r));
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poetteringstatic int make_service_name(const char *name, char **ret) {
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering log_error("Invalid machine name %s.", name);
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering r = unit_name_build("systemd-nspawn", e, ".service", ret);
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering return log_error_errno(r, "Failed to build unit name: %m");
ebd011d95b61a86258dece9864f65b7c4af721c0Lennart Poetteringstatic int start_machine(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
ebd011d95b61a86258dece9864f65b7c4af721c0Lennart Poettering _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
ebd011d95b61a86258dece9864f65b7c4af721c0Lennart Poettering "org.freedesktop.systemd1.Manager",
ebd011d95b61a86258dece9864f65b7c4af721c0Lennart Poettering log_error("Failed to start unit: %s", bus_error_message(&error, -r));
ebd011d95b61a86258dece9864f65b7c4af721c0Lennart Poettering r = sd_bus_message_read(reply, "o", &object);
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poetteringstatic int enable_machine(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering method = streq(argv[0], "enable") ? "EnableUnitFiles" : "DisableUnitFiles";
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering "org.freedesktop.systemd1.Manager",
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering r = sd_bus_message_open_container(m, 'a', "s");
90615ad79188c360c0571b0a0d2ed81d88ece1abThomas Hindoe Paaboel Andersen _cleanup_free_ char *unit = NULL;
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering r = sd_bus_message_append(m, "bb", false, false);
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering r = sd_bus_message_append(m, "b", false);
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering r = sd_bus_call(bus, m, 0, &error, &reply);
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering log_error("Failed to enable or disable unit: %s", bus_error_message(&error, -r));
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering r = sd_bus_message_read(reply, "b", carries_install_info);
57ab2eabb8f92fad5239c7d4492e9c6e23ee0678Jan Synacek r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet, NULL, NULL);
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering "org.freedesktop.systemd1.Manager",
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering log_error("Failed to reload daemon: %s", bus_error_message(&error, -r));
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int match_log_message(sd_bus_message *m, void *userdata, sd_bus_error *error) {
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering r = sd_bus_message_read(m, "us", &priority, &line);
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering if (!streq_ptr(*our_path, sd_bus_message_get_path(m)))
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering if (arg_quiet && LOG_PRI(priority) >= LOG_INFO)
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int match_transfer_removed(sd_bus_message *m, void *userdata, sd_bus_error *error) {
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering const char **our_path = userdata, *path, *result;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering r = sd_bus_message_read(m, "uos", &id, &path, &result);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(m)), !streq_ptr(result, "done"));
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poetteringstatic int transfer_signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
cc98b3025eeb89addb76a27390cb2baca4eab8b9Torstein Husebø log_info("Continuing download in the background. Use \"machinectl cancel-transfer %" PRIu32 "\" to abort transfer.", PTR_TO_UINT32(userdata));
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering sd_event_exit(sd_event_source_get_event(s), EINTR);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poetteringstatic int transfer_image_common(sd_bus *bus, sd_bus_message *m) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *slot_job_removed = NULL, *slot_log_message = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_event_unrefp) sd_event* event = NULL;
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering return log_error_errno(r, "Failed to get event loop: %m");
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering return log_error_errno(r, "Failed to attach bus to event loop: %m");
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "type='signal',"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "sender='org.freedesktop.import1',"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "interface='org.freedesktop.import1.Manager',"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "member='TransferRemoved',"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering return log_error_errno(r, "Failed to install match: %m");
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "type='signal',"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "sender='org.freedesktop.import1',"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "interface='org.freedesktop.import1.Transfer',"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "member='LogMessage'",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering return log_error_errno(r, "Failed to install match: %m");
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering r = sd_bus_call(bus, m, 0, &error, &reply);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering log_error("Failed transfer image: %s", bus_error_message(&error, -r));
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering r = sd_bus_message_read(reply, "uo", &id, &path);
72c0a2c255b172ebbb2a2b7dab7c9aec4c9582d9Lennart Poettering assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0);
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering log_info("Enqueued transfer job %u. Press C-c to continue download in background.", id);
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering sd_event_add_signal(event, NULL, SIGINT, transfer_signal_handler, UINT32_TO_PTR(id));
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering sd_event_add_signal(event, NULL, SIGTERM, transfer_signal_handler, UINT32_TO_PTR(id));
6adf7b5e46d32376868feef0197e6ada352aa6f2Lennart Poettering return log_error_errno(r, "Failed to run event loop: %m");
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poetteringstatic int import_tar(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering log_error("Need either path or local name.");
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering log_error("Local name %s is not a suitable machine name.", local);
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering return log_error_errno(errno, "Failed to open %s: %m", path);
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering "org.freedesktop.import1",
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering "org.freedesktop.import1.Manager",
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poetteringstatic int import_raw(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering log_error("Need either path or local name.");
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering log_error("Local name %s is not a suitable machine name.", local);
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering return log_error_errno(errno, "Failed to open %s: %m", path);
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering "org.freedesktop.import1",
b6e676ce41508e2aeea22202fc8f234126177f52Lennart Poettering "org.freedesktop.import1.Manager",
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poetteringstatic void determine_compression_from_filename(const char *p) {
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poetteringstatic int export_tar(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering log_error("Machine name %s is not valid.", local);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering determine_compression_from_filename(path);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering fd = open(path, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC|O_NOCTTY, 0666);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering return log_error_errno(errno, "Failed to open %s: %m", path);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering "org.freedesktop.import1",
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering "org.freedesktop.import1.Manager",
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poetteringstatic int export_raw(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering log_error("Machine name %s is not valid.", local);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering determine_compression_from_filename(path);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering fd = open(path, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC|O_NOCTTY, 0666);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering return log_error_errno(errno, "Failed to open %s: %m", path);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering "org.freedesktop.import1",
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering "org.freedesktop.import1.Manager",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poetteringstatic int pull_tar(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering _cleanup_free_ char *l = NULL, *ll = NULL;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering log_error("URL '%s' is not valid.", remote);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering r = import_url_last_component(remote, &l);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering return log_error_errno(r, "Failed to get final component of URL: %m");
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering log_error("Local name %s is not a suitable machine name.", local);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "org.freedesktop.import1",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "org.freedesktop.import1.Manager",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poetteringstatic int pull_raw(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering _cleanup_free_ char *l = NULL, *ll = NULL;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering log_error("URL '%s' is not valid.", remote);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering r = import_url_last_component(remote, &l);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering return log_error_errno(r, "Failed to get final component of URL: %m");
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering log_error("Local name %s is not a suitable machine name.", local);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "org.freedesktop.import1",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "org.freedesktop.import1.Manager",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poetteringstatic int compare_transfer_info(const void *a, const void *b) {
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering const TransferInfo *x = a, *y = b;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poetteringstatic int list_transfers(int argc, char *argv[], void *userdata) {
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering size_t max_type = strlen("TYPE"), max_local = strlen("LOCAL"), max_remote = strlen("REMOTE");
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering _cleanup_free_ TransferInfo *transfers = NULL;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering size_t n_transfers = 0, n_allocated = 0, j;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering const char *type, *remote, *local, *object;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "org.freedesktop.import1",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "org.freedesktop.import1.Manager",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "ListTransfers",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering log_error("Could not get transfers: %s", bus_error_message(&error, -r));
7079cfeffb6d520f20ddff53fd78467e72e6cc94Lennart Poettering r = sd_bus_message_enter_container(reply, 'a', "(usssdo)");
7079cfeffb6d520f20ddff53fd78467e72e6cc94Lennart Poettering while ((r = sd_bus_message_read(reply, "(usssdo)", &id, &type, &remote, &local, &progress, &object)) > 0) {
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering if (!GREEDY_REALLOC(transfers, n_allocated, n_transfers + 1))
7079cfeffb6d520f20ddff53fd78467e72e6cc94Lennart Poettering transfers[n_transfers].progress = progress;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering r = sd_bus_message_exit_container(reply);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering qsort_safe(transfers, n_transfers, sizeof(TransferInfo), compare_transfer_info);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering (int) MAX(2U, DECIMAL_STR_WIDTH(max_id)), "ID",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering for (j = 0; j < n_transfers; j++)
7079cfeffb6d520f20ddff53fd78467e72e6cc94Lennart Poettering printf("%*" PRIu32 " %*u%% %-*s %-*s %-*s\n",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering (int) MAX(2U, DECIMAL_STR_WIDTH(max_id)), transfers[j].id,
7079cfeffb6d520f20ddff53fd78467e72e6cc94Lennart Poettering (int) 6, (unsigned) (transfers[j].progress * 100),
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering printf("\n%zu transfers listed.\n", n_transfers);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poetteringstatic int cancel_transfer(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering return log_error_errno(r, "Failed to parse transfer id: %s", argv[i]);
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "org.freedesktop.import1",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "org.freedesktop.import1.Manager",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering "CancelTransfer",
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering log_error("Could not cancel transfer: %s", bus_error_message(&error, -r));
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poetteringstatic int set_limit(int argc, char *argv[], void *userdata) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
7705a4053d83b5da22c9354a44be26ffc8e24f5aLennart Poettering if (STR_IN_SET(argv[argc-1], "-", "none", "infinity"))
59f448cf15f94bc5ebfd5b254de6f2441d02fbecLennart Poettering r = parse_size(argv[argc-1], 1024, &limit);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return log_error("Failed to parse size: %s", argv[argc-1]);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering /* With two arguments changes the quota limit of the
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering * specified image */
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering "org.freedesktop.machine1",
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering "org.freedesktop.machine1.Manager",
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering "SetImageLimit",
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering /* With one argument changes the pool quota limit */
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering "org.freedesktop.machine1",
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering "org.freedesktop.machine1.Manager",
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering "SetPoolLimit",
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering log_error("Could not set limit: %s", bus_error_message(&error, -r));
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int help(int argc, char *argv[], void *userdata) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering printf("%s [OPTIONS...] {COMMAND} ...\n\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "Send control commands to or query the virtual machine and container\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering "registration manager.\n\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " -h --help Show this help\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " --version Show package version\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " --no-pager Do not pipe output into a pager\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " --no-legend Do not show the headers and footers\n"
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering " --no-ask-password Do not ask for system passwords\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " -H --host=[USER@]HOST Operate on remote host\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " -M --machine=CONTAINER Operate on local container\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " -p --property=NAME Show only properties by this name\n"
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering " -q --quiet Suppress output\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " -a --all Show all properties, including empty ones\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " -l --full Do not ellipsize output\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " --kill-who=WHO Who to send signal to\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " -s --signal=SIGNAL Which signal to send\n"
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering " --uid=USER Specify user ID to invoke shell as\n"
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering " --setenv=VAR=VALUE Add an environment variable for shell\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " --read-only Create read-only bind mount\n"
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering " --mkdir Create directory before bind mounting, if missing\n"
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering " -n --lines=INTEGER Number of journal entries to show\n"
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering " -o --output=STRING Change journal output mode (short,\n"
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering " short-monotonic, verbose, export, json,\n"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering " json-pretty, json-sse, cat)\n"
7f444afa1b62920265fec99a61cb4dc53d521956Lennart Poettering " --verify=MODE Verification mode for downloaded images (no,\n"
7f444afa1b62920265fec99a61cb4dc53d521956Lennart Poettering " checksum, signature)\n"
b43d75c378d919900e5c1e82a82e3e17dd3de9f9Lennart Poettering " --force Download image even if already exists\n\n"
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering "Machine Commands:\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " list List running VMs and containers\n"
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering " status NAME... Show VM/container details\n"
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering " show [NAME...] Show properties of one or more VMs/containers\n"
ebd011d95b61a86258dece9864f65b7c4af721c0Lennart Poettering " start NAME... Start container as a service\n"
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering " login [NAME] Get a login prompt in a container or on the\n"
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering " local host\n"
ef3100e9637adda26fa19e7ee8606788320dcde3Lennart Poettering " shell [[USER@]NAME [COMMAND...]]\n"
ef3100e9637adda26fa19e7ee8606788320dcde3Lennart Poettering " Invoke a shell (or other command) in a container\n"
ef3100e9637adda26fa19e7ee8606788320dcde3Lennart Poettering " or on the local host\n"
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering " enable NAME... Enable automatic container start at boot\n"
d8f52ed25a9edce75fda5251c977b7898e33887eLennart Poettering " disable NAME... Disable automatic container start at boot\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " poweroff NAME... Power off one or more containers\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " reboot NAME... Reboot one or more containers\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " terminate NAME... Terminate one or more VMs/containers\n"
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering " kill NAME... Send signal to processes of a VM/container\n"
f2cbe59e113f08549949a76ac5b9b3972df4cc30Lennart Poettering " copy-to NAME PATH [PATH] Copy files from the host to a container\n"
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering " copy-from NAME PATH [PATH] Copy files from a container to the host\n"
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering " bind NAME PATH [PATH] Bind mount a path from the host into a container\n\n"
fefdc04b38725457a91651218feb7000f6ccc1f4Lennart Poettering "Image Commands:\n"
56b921c3d863f0e098f60f934e6c5880575c68abZbigniew Jędrzejewski-Szmek " list-images Show available container and VM images\n"
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering " image-status [NAME...] Show image details\n"
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering " show-image [NAME...] Show properties of image\n"
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering " clone NAME NAME Clone an image\n"
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering " rename NAME NAME Rename an image\n"
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering " read-only NAME [BOOL] Mark or unmark image read-only\n"
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering " remove NAME... Remove an image\n"
e721d697db20c976c9eebd32c461d2b957efa437Lennart Poettering " set-limit [NAME] BYTES Set image or pool size limit (disk quota)\n\n"
b5b38b41c37dbe1a117af9bf99e94b58ac91239aLennart Poettering "Image Transfer Commands:\n"
b5b38b41c37dbe1a117af9bf99e94b58ac91239aLennart Poettering " pull-tar URL [NAME] Download a TAR container image\n"
b5b38b41c37dbe1a117af9bf99e94b58ac91239aLennart Poettering " pull-raw URL [NAME] Download a RAW container or VM image\n"
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering " import-tar FILE [NAME] Import a local TAR container image\n"
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering " import-raw FILE [NAME] Import a local RAW container or VM image\n"
6e9efa59209d48fc69a456fbadb2b5c113f503a6Lennart Poettering " export-tar NAME [FILE] Export a TAR container image locally\n"
6e9efa59209d48fc69a456fbadb2b5c113f503a6Lennart Poettering " export-raw NAME [FILE] Export a RAW container or VM image locally\n"
b5b38b41c37dbe1a117af9bf99e94b58ac91239aLennart Poettering " list-transfers Show list of downloads in progress\n"
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering " cancel-transfer Cancel a download\n"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringstatic int parse_argv(int argc, char *argv[]) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "version", no_argument, NULL, ARG_VERSION },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "property", required_argument, NULL, 'p' },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "no-pager", no_argument, NULL, ARG_NO_PAGER },
e56056e93d33619a3acf13e483900b4f8938228fThomas Hindoe Paaboel Andersen { "no-legend", no_argument, NULL, ARG_NO_LEGEND },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "kill-who", required_argument, NULL, ARG_KILL_WHO },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "signal", required_argument, NULL, 's' },
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering { "host", required_argument, NULL, 'H' },
a7893c6b28772edbc7e1fea3c209caa54d465648Lennart Poettering { "machine", required_argument, NULL, 'M' },
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering { "read-only", no_argument, NULL, ARG_READ_ONLY },
785890acf6d629ff881a1f065f431df1b7fc8c7aLennart Poettering { "mkdir", no_argument, NULL, ARG_MKDIR },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "lines", required_argument, NULL, 'n' },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering { "output", required_argument, NULL, 'o' },
acf97e213e69a97e63ab8f7fad7ecd53608c757aLennart Poettering { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "verify", required_argument, NULL, ARG_VERIFY },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "force", no_argument, NULL, ARG_FORCE },
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering { "format", required_argument, NULL, ARG_FORMAT },
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering { "uid", required_argument, NULL, ARG_UID },
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering { "setenv", required_argument, NULL, ARG_SETENV },
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering while ((c = getopt_long(argc, argv, "hp:als:H:M:qn:o:", options, NULL)) >= 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering /* If the user asked for a particular
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering * property, show it to him, even if it is
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering log_error("Failed to parse lines '%s'", optarg);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering arg_output = output_mode_from_string(optarg);
8b0cc9a36c8f92f010f2e8465942d2cd7c580d78Lennart Poettering log_error("Unknown output '%s'.", optarg);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering arg_signal = signal_from_string_try_harder(optarg);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering log_error("Failed to parse signal string %s.", optarg);
6e18cc9fa078d2a967251017ddb5baefb104b720Lennart Poettering arg_verify = import_verify_from_string(optarg);
6e18cc9fa078d2a967251017ddb5baefb104b720Lennart Poettering log_error("Failed to parse --verify= setting: %s", optarg);
587fec427c80b6c34dcf1d7570f891fcb652a7c5Lennart Poettering if (!STR_IN_SET(optarg, "uncompressed", "xz", "gzip", "bzip2")) {
c454426c54c9beb274f415a80c64a4f1580700e7Lennart Poettering log_error("Environment assignment invalid: %s", optarg);
56159e0d918e9a9be07988133bb2847779325de0Lennart Poetteringstatic int machinectl_main(int argc, char *argv[], sd_bus *bus) {
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "list", VERB_ANY, 1, VERB_DEFAULT, list_machines },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "list-images", VERB_ANY, 1, 0, list_images },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "status", 2, VERB_ANY, 0, show_machine },
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering { "image-status", VERB_ANY, VERB_ANY, 0, show_image },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "show", VERB_ANY, VERB_ANY, 0, show_machine },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "show-image", VERB_ANY, VERB_ANY, 0, show_image },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "terminate", 2, VERB_ANY, 0, terminate_machine },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "reboot", 2, VERB_ANY, 0, reboot_machine },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "poweroff", 2, VERB_ANY, 0, poweroff_machine },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "kill", 2, VERB_ANY, 0, kill_machine },
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering { "login", VERB_ANY, 2, 0, login_machine },
91913f584af38b29a816cca959ba648acd60ac9fLennart Poettering { "shell", VERB_ANY, VERB_ANY, 0, shell_machine },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "remove", 2, VERB_ANY, 0, remove_image },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "read-only", 2, 3, 0, read_only_image },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "start", 2, VERB_ANY, 0, start_machine },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "enable", 2, VERB_ANY, 0, enable_machine },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "disable", 2, VERB_ANY, 0, enable_machine },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "list-transfers", VERB_ANY, 1, 0, list_transfers },
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering { "cancel-transfer", 2, VERB_ANY, 0, cancel_transfer },
56159e0d918e9a9be07988133bb2847779325de0Lennart Poettering return dispatch_verb(argc, argv, verbs, bus);
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
266f3e269d173f104aa2a5e3ceac9b6979ea5039Lennart Poettering r = bus_connect_transport(arg_transport, arg_host, false, &bus);
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt log_error_errno(r, "Failed to create bus connection: %m");
2723b3b51d409340558e46e37e90525d4f880fe1Lennart Poettering sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);