1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 #include <netinet/in.h>
10 #include <sys/mount.h>
11 #include <sys/socket.h>
16 #include "alloc-util.h"
18 #include "build-path.h"
19 #include "bus-common-errors.h"
20 #include "bus-error.h"
21 #include "bus-locator.h"
22 #include "bus-map-properties.h"
23 #include "bus-print-properties.h"
24 #include "bus-unit-procs.h"
25 #include "bus-unit-util.h"
26 #include "bus-wait-for-jobs.h"
27 #include "cgroup-show.h"
28 #include "cgroup-util.h"
29 #include "constants.h"
31 #include "edit-util.h"
34 #include "format-table.h"
35 #include "hostname-util.h"
36 #include "import-util.h"
37 #include "locale-util.h"
39 #include "logs-show.h"
40 #include "machine-dbus.h"
42 #include "main-func.h"
44 #include "nulstr-util.h"
46 #include "parse-argument.h"
47 #include "parse-util.h"
48 #include "path-util.h"
49 #include "pretty-print.h"
50 #include "process-util.h"
52 #include "rlimit-util.h"
54 #include "signal-util.h"
55 #include "sort-util.h"
56 #include "spawn-ask-password-agent.h"
57 #include "spawn-polkit-agent.h"
58 #include "stdio-util.h"
59 #include "string-table.h"
61 #include "terminal-util.h"
62 #include "unit-name.h"
66 typedef enum MachineRunner
{
70 _RUNNER_INVALID
= -EINVAL
,
73 static const char* const machine_runner_table
[_RUNNER_MAX
] = {
74 [RUNNER_NSPAWN
] = "nspawn",
75 [RUNNER_VMSPAWN
] = "vmspawn",
78 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(machine_runner
, MachineRunner
);
80 static const char* const machine_runner_unit_prefix_table
[_RUNNER_MAX
] = {
81 [RUNNER_NSPAWN
] = "systemd-nspawn",
82 [RUNNER_VMSPAWN
] = "systemd-vmspawn",
85 static char **arg_property
= NULL
;
86 static bool arg_all
= false;
87 static BusPrintPropertyFlags arg_print_flags
= 0;
88 static bool arg_full
= false;
89 static PagerFlags arg_pager_flags
= 0;
90 static bool arg_legend
= true;
91 static const char *arg_kill_whom
= NULL
;
92 static int arg_signal
= SIGTERM
;
93 static BusTransport arg_transport
= BUS_TRANSPORT_LOCAL
;
94 static const char *arg_host
= NULL
;
95 static bool arg_read_only
= false;
96 static bool arg_mkdir
= false;
97 static bool arg_quiet
= false;
98 static bool arg_ask_password
= true;
99 static unsigned arg_lines
= 10;
100 static OutputMode arg_output
= OUTPUT_SHORT
;
101 static bool arg_now
= false;
102 static bool arg_force
= false;
103 static ImportVerify arg_verify
= IMPORT_VERIFY_SIGNATURE
;
104 static MachineRunner arg_runner
= RUNNER_NSPAWN
;
105 static const char* arg_format
= NULL
;
106 static const char *arg_uid
= NULL
;
107 static char **arg_setenv
= NULL
;
108 static unsigned arg_max_addresses
= 1;
110 STATIC_DESTRUCTOR_REGISTER(arg_property
, strv_freep
);
111 STATIC_DESTRUCTOR_REGISTER(arg_setenv
, strv_freep
);
113 static OutputFlags
get_output_flags(void) {
115 FLAGS_SET(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
) * OUTPUT_SHOW_ALL
|
116 (arg_full
|| !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH
|
117 colors_enabled() * OUTPUT_COLOR
|
118 !arg_quiet
* OUTPUT_WARN_CUTOFF
;
121 static int call_get_os_release(sd_bus
*bus
, const char *method
, const char *name
, const char *query
, ...) {
122 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
123 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
124 const char *k
, *v
, **query_res
= NULL
;
125 size_t count
= 0, awaited_args
= 0;
133 NULSTR_FOREACH(iter
, query
)
135 query_res
= newa0(const char *, awaited_args
);
137 r
= bus_call_method(bus
, bus_machine_mgr
, method
, &error
, &reply
, "s", name
);
139 return log_debug_errno(r
, "Failed to call '%s()': %s", method
, bus_error_message(&error
, r
));
141 r
= sd_bus_message_enter_container(reply
, 'a', "{ss}");
143 return bus_log_parse_error(r
);
145 while ((r
= sd_bus_message_read(reply
, "{ss}", &k
, &v
)) > 0) {
147 NULSTR_FOREACH(iter
, query
) {
148 if (streq(k
, iter
)) {
149 query_res
[count
] = v
;
156 return bus_log_parse_error(r
);
158 r
= sd_bus_message_exit_container(reply
);
160 return bus_log_parse_error(r
);
163 for (count
= 0; count
< awaited_args
; count
++) {
166 out
= va_arg(ap
, char **);
168 if (query_res
[count
]) {
169 val
= strdup(query_res
[count
]);
182 static int call_get_addresses(
190 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
191 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
192 _cleanup_free_
char *addresses
= NULL
;
201 r
= bus_call_method(bus
, bus_machine_mgr
, "GetMachineAddresses", NULL
, &reply
, "s", name
);
203 return log_debug_errno(r
, "Could not get addresses: %s", bus_error_message(&error
, r
));
205 addresses
= strdup(prefix
);
210 r
= sd_bus_message_enter_container(reply
, 'a', "(iay)");
212 return bus_log_parse_error(r
);
214 while ((r
= sd_bus_message_enter_container(reply
, 'r', "iay")) > 0) {
218 char buf_ifi
[1 + DECIMAL_STR_MAX(int)] = "";
220 r
= sd_bus_message_read(reply
, "i", &family
);
222 return bus_log_parse_error(r
);
224 r
= sd_bus_message_read_array(reply
, 'y', &a
, &sz
);
226 return bus_log_parse_error(r
);
228 if (family
== AF_INET6
&& ifi
> 0)
229 xsprintf(buf_ifi
, "%%%i", ifi
);
231 if (!strextend(&addresses
, prefix
, IN_ADDR_TO_STRING(family
, a
), buf_ifi
))
234 r
= sd_bus_message_exit_container(reply
);
236 return bus_log_parse_error(r
);
243 return bus_log_parse_error(r
);
245 r
= sd_bus_message_exit_container(reply
);
247 return bus_log_parse_error(r
);
249 *ret
= TAKE_PTR(addresses
);
253 static int show_table(Table
*table
, const char *word
) {
259 if (!table_isempty(table
) || OUTPUT_MODE_IS_JSON(arg_output
)) {
260 r
= table_set_sort(table
, (size_t) 0);
262 return table_log_sort_error(r
);
264 table_set_header(table
, arg_legend
);
266 if (OUTPUT_MODE_IS_JSON(arg_output
))
267 r
= table_print_json(table
, NULL
, output_mode_to_json_format_flags(arg_output
) | JSON_FORMAT_COLOR_AUTO
);
269 r
= table_print(table
, NULL
);
271 return table_log_print_error(r
);
275 if (table_isempty(table
))
276 printf("No %s.\n", word
);
278 printf("\n%zu %s listed.\n", table_get_rows(table
) - 1, word
);
284 static int list_machines(int argc
, char *argv
[], void *userdata
) {
285 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
286 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
287 _cleanup_(table_unrefp
) Table
*table
= NULL
;
288 sd_bus
*bus
= ASSERT_PTR(userdata
);
291 pager_open(arg_pager_flags
);
293 r
= bus_call_method(bus
, bus_machine_mgr
, "ListMachines", &error
, &reply
, NULL
);
295 return log_error_errno(r
, "Could not get machines: %s", bus_error_message(&error
, r
));
297 table
= table_new("machine", "class", "service", "os", "version",
298 arg_max_addresses
> 0 ? "addresses" : NULL
);
302 table_set_ersatz_string(table
, TABLE_ERSATZ_DASH
);
303 if (!arg_full
&& arg_max_addresses
> 0 && arg_max_addresses
< UINT_MAX
)
304 table_set_cell_height_max(table
, arg_max_addresses
);
307 table_set_width(table
, 0);
309 r
= sd_bus_message_enter_container(reply
, 'a', "(ssso)");
311 return bus_log_parse_error(r
);
314 _cleanup_free_
char *os
= NULL
, *version_id
= NULL
, *addresses
= NULL
;
315 const char *name
, *class, *service
;
317 r
= sd_bus_message_read(reply
, "(ssso)", &name
, &class, &service
, NULL
);
319 return bus_log_parse_error(r
);
323 if (name
[0] == '.' && !arg_all
)
326 (void) call_get_os_release(
328 "GetMachineOSRelease",
335 r
= table_add_many(table
,
336 TABLE_STRING
, empty_to_null(name
),
337 TABLE_STRING
, empty_to_null(class),
338 TABLE_STRING
, empty_to_null(service
),
339 TABLE_STRING
, empty_to_null(os
),
340 TABLE_STRING
, empty_to_null(version_id
));
342 return table_log_add_error(r
);
344 if (arg_max_addresses
> 0) {
345 (void) call_get_addresses(bus
, name
, 0, "", "\n", &addresses
);
347 r
= table_add_many(table
,
348 TABLE_STRING
, empty_to_null(addresses
));
350 return table_log_add_error(r
);
354 r
= sd_bus_message_exit_container(reply
);
356 return bus_log_parse_error(r
);
358 return show_table(table
, "machines");
361 static int list_images(int argc
, char *argv
[], void *userdata
) {
363 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
364 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
365 _cleanup_(table_unrefp
) Table
*table
= NULL
;
366 sd_bus
*bus
= ASSERT_PTR(userdata
);
369 pager_open(arg_pager_flags
);
371 r
= bus_call_method(bus
, bus_machine_mgr
, "ListImages", &error
, &reply
, NULL
);
373 return log_error_errno(r
, "Could not get images: %s", bus_error_message(&error
, r
));
375 table
= table_new("name", "type", "ro", "usage", "created", "modified");
380 table_set_width(table
, 0);
382 (void) table_set_align_percent(table
, TABLE_HEADER_CELL(3), 100);
384 r
= sd_bus_message_enter_container(reply
, SD_BUS_TYPE_ARRAY
, "(ssbttto)");
386 return bus_log_parse_error(r
);
389 uint64_t crtime
, mtime
, size
;
390 const char *name
, *type
;
393 r
= sd_bus_message_read(reply
, "(ssbttto)", &name
, &type
, &ro_int
, &crtime
, &mtime
, &size
, NULL
);
395 return bus_log_parse_error(r
);
399 if (name
[0] == '.' && !arg_all
)
402 r
= table_add_many(table
,
405 TABLE_BOOLEAN
, ro_int
,
406 TABLE_SET_COLOR
, ro_int
? ansi_highlight_red() : NULL
,
408 TABLE_TIMESTAMP
, crtime
,
409 TABLE_TIMESTAMP
, mtime
);
411 return table_log_add_error(r
);
414 r
= sd_bus_message_exit_container(reply
);
416 return bus_log_parse_error(r
);
418 return show_table(table
, "images");
421 static int show_unit_cgroup(sd_bus
*bus
, const char *unit
, pid_t leader
) {
422 _cleanup_free_
char *cgroup
= NULL
;
423 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
430 r
= show_cgroup_get_unit_path_and_warn(bus
, unit
, &cgroup
);
443 r
= unit_show_processes(bus
, unit
, cgroup
, "\t\t ", c
, get_output_flags(), &error
);
446 if (arg_transport
== BUS_TRANSPORT_REMOTE
)
449 /* Fallback for older systemd versions where the GetUnitProcesses() call is not yet available */
451 if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER
, cgroup
) != 0 && leader
<= 0)
454 show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER
, cgroup
, "\t\t ", c
, &leader
, leader
> 0, get_output_flags());
456 return log_error_errno(r
, "Failed to dump process list: %s", bus_error_message(&error
, r
));
461 static int print_os_release(sd_bus
*bus
, const char *method
, const char *name
, const char *prefix
) {
462 _cleanup_free_
char *pretty
= NULL
;
469 r
= call_get_os_release(bus
, method
, name
, "PRETTY_NAME\0", &pretty
, NULL
);
474 printf("%s%s\n", prefix
, pretty
);
479 static int print_uid_shift(sd_bus
*bus
, const char *name
) {
480 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
481 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
488 r
= bus_call_method(bus
, bus_machine_mgr
, "GetMachineUIDShift", &error
, &reply
, "s", name
);
490 return log_debug_errno(r
, "Failed to query UID/GID shift: %s", bus_error_message(&error
, r
));
492 r
= sd_bus_message_read(reply
, "u", &shift
);
496 if (shift
== 0) /* Don't show trivial mappings */
499 printf(" UID Shift: %" PRIu32
"\n", shift
);
503 typedef struct MachineStatusInfo
{
509 const char *root_directory
;
511 struct dual_timestamp timestamp
;
516 static void machine_status_info_clear(MachineStatusInfo
*info
) {
523 static void print_machine_status_info(sd_bus
*bus
, MachineStatusInfo
*i
) {
524 _cleanup_free_
char *addresses
= NULL
, *s1
= NULL
, *s2
= NULL
;
530 fputs(strna(i
->name
), stdout
);
532 if (!sd_id128_is_null(i
->id
))
533 printf("(" SD_ID128_FORMAT_STR
")\n", SD_ID128_FORMAT_VAL(i
->id
));
537 s1
= strdup(strempty(FORMAT_TIMESTAMP_RELATIVE(i
->timestamp
.realtime
)));
538 s2
= strdup(strempty(FORMAT_TIMESTAMP(i
->timestamp
.realtime
)));
541 printf("\t Since: %s; %s\n", strna(s2
), s1
);
542 else if (!isempty(s2
))
543 printf("\t Since: %s\n", s2
);
546 _cleanup_free_
char *t
= NULL
;
548 printf("\t Leader: %u", (unsigned) i
->leader
);
550 (void) pid_get_comm(i
->leader
, &t
);
558 printf("\t Service: %s", i
->service
);
561 printf("; class %s", i
->class);
565 printf("\t Class: %s\n", i
->class);
567 if (i
->root_directory
)
568 printf("\t Root: %s\n", i
->root_directory
);
570 if (i
->n_netif
> 0) {
571 fputs("\t Iface:", stdout
);
573 for (size_t c
= 0; c
< i
->n_netif
; c
++) {
574 char name
[IF_NAMESIZE
];
576 if (format_ifname(i
->netif
[c
], name
) >= 0) {
585 printf(" %i", i
->netif
[c
]);
591 if (call_get_addresses(bus
, i
->name
, ifi
,
592 "\t Address: ", "\n\t ",
594 fputs(addresses
, stdout
);
598 print_os_release(bus
, "GetMachineOSRelease", i
->name
, "\t OS: ");
600 print_uid_shift(bus
, i
->name
);
603 printf("\t Unit: %s\n", i
->unit
);
604 show_unit_cgroup(bus
, i
->unit
, i
->leader
);
606 if (arg_transport
== BUS_TRANSPORT_LOCAL
)
608 show_journal_by_unit(
614 i
->timestamp
.monotonic
,
617 get_output_flags() | OUTPUT_BEGIN_NEWLINE
,
618 SD_JOURNAL_LOCAL_ONLY
,
624 static int map_netif(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
625 MachineStatusInfo
*i
= userdata
;
630 assert_cc(sizeof(int32_t) == sizeof(int));
631 r
= sd_bus_message_read_array(m
, SD_BUS_TYPE_INT32
, &v
, &l
);
637 i
->n_netif
= l
/ sizeof(int32_t);
638 i
->netif
= memdup(v
, l
);
645 static int show_machine_info(const char *verb
, sd_bus
*bus
, const char *path
, bool *new_line
) {
647 static const struct bus_properties_map map
[] = {
648 { "Name", "s", NULL
, offsetof(MachineStatusInfo
, name
) },
649 { "Class", "s", NULL
, offsetof(MachineStatusInfo
, class) },
650 { "Service", "s", NULL
, offsetof(MachineStatusInfo
, service
) },
651 { "Unit", "s", NULL
, offsetof(MachineStatusInfo
, unit
) },
652 { "RootDirectory", "s", NULL
, offsetof(MachineStatusInfo
, root_directory
) },
653 { "Leader", "u", NULL
, offsetof(MachineStatusInfo
, leader
) },
654 { "Timestamp", "t", NULL
, offsetof(MachineStatusInfo
, timestamp
.realtime
) },
655 { "TimestampMonotonic", "t", NULL
, offsetof(MachineStatusInfo
, timestamp
.monotonic
) },
656 { "Id", "ay", bus_map_id128
, offsetof(MachineStatusInfo
, id
) },
657 { "NetworkInterfaces", "ai", map_netif
, 0 },
661 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
662 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
663 _cleanup_(machine_status_info_clear
) MachineStatusInfo info
= {};
671 r
= bus_map_all_properties(bus
,
672 "org.freedesktop.machine1",
680 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
686 print_machine_status_info(bus
, &info
);
691 static int show_machine_properties(sd_bus
*bus
, const char *path
, bool *new_line
) {
703 r
= bus_print_all_properties(bus
, "org.freedesktop.machine1", path
, NULL
, arg_property
, arg_print_flags
, NULL
);
705 log_error_errno(r
, "Could not get properties: %m");
710 static int show_machine(int argc
, char *argv
[], void *userdata
) {
711 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
712 bool properties
, new_line
= false;
713 sd_bus
*bus
= ASSERT_PTR(userdata
);
716 properties
= !strstr(argv
[0], "status");
718 pager_open(arg_pager_flags
);
720 if (properties
&& argc
<= 1) {
722 /* If no argument is specified, inspect the manager
724 r
= show_machine_properties(bus
, "/org/freedesktop/machine1", &new_line
);
729 for (int i
= 1; i
< argc
; i
++) {
730 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
731 const char *path
= NULL
;
733 r
= bus_call_method(bus
, bus_machine_mgr
, "GetMachine", &error
, &reply
, "s", argv
[i
]);
735 return log_error_errno(r
, "Could not get path to machine: %s", bus_error_message(&error
, r
));
737 r
= sd_bus_message_read(reply
, "o", &path
);
739 return bus_log_parse_error(r
);
742 r
= show_machine_properties(bus
, path
, &new_line
);
744 r
= show_machine_info(argv
[0], bus
, path
, &new_line
);
750 static int print_image_hostname(sd_bus
*bus
, const char *name
) {
751 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
755 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImageHostname", NULL
, &reply
, "s", name
);
759 r
= sd_bus_message_read(reply
, "s", &hn
);
764 printf("\tHostname: %s\n", hn
);
769 static int print_image_machine_id(sd_bus
*bus
, const char *name
) {
770 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
774 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImageMachineID", NULL
, &reply
, "s", name
);
778 r
= bus_message_read_id128(reply
, &id
);
782 if (!sd_id128_is_null(id
))
783 printf(" Machine ID: " SD_ID128_FORMAT_STR
"\n", SD_ID128_FORMAT_VAL(id
));
788 static int print_image_machine_info(sd_bus
*bus
, const char *name
) {
789 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
792 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImageMachineInfo", NULL
, &reply
, "s", name
);
796 r
= sd_bus_message_enter_container(reply
, 'a', "{ss}");
803 r
= sd_bus_message_read(reply
, "{ss}", &p
, &q
);
809 if (streq(p
, "DEPLOYMENT"))
810 printf(" Deployment: %s\n", q
);
813 r
= sd_bus_message_exit_container(reply
);
820 typedef struct ImageStatusInfo
{
829 uint64_t usage_exclusive
;
830 uint64_t limit_exclusive
;
833 static void print_image_status_info(sd_bus
*bus
, ImageStatusInfo
*i
) {
838 fputs(i
->name
, stdout
);
843 printf("\t Type: %s\n", i
->type
);
846 printf("\t Path: %s\n", i
->path
);
848 (void) print_image_hostname(bus
, i
->name
);
849 (void) print_image_machine_id(bus
, i
->name
);
850 (void) print_image_machine_info(bus
, i
->name
);
852 print_os_release(bus
, "GetImageOSRelease", i
->name
, "\t OS: ");
854 printf("\t RO: %s%s%s\n",
855 i
->read_only
? ansi_highlight_red() : "",
856 i
->read_only
? "read-only" : "writable",
857 i
->read_only
? ansi_normal() : "");
859 if (timestamp_is_set(i
->crtime
))
860 printf("\t Created: %s; %s\n",
861 FORMAT_TIMESTAMP(i
->crtime
), FORMAT_TIMESTAMP_RELATIVE(i
->crtime
));
863 if (timestamp_is_set(i
->mtime
))
864 printf("\tModified: %s; %s\n",
865 FORMAT_TIMESTAMP(i
->mtime
), FORMAT_TIMESTAMP_RELATIVE(i
->mtime
));
867 if (i
->usage
!= UINT64_MAX
) {
868 if (i
->usage_exclusive
!= i
->usage
&& i
->usage_exclusive
!= UINT64_MAX
)
869 printf("\t Usage: %s (exclusive: %s)\n",
870 FORMAT_BYTES(i
->usage
), FORMAT_BYTES(i
->usage_exclusive
));
872 printf("\t Usage: %s\n", FORMAT_BYTES(i
->usage
));
875 if (i
->limit
!= UINT64_MAX
) {
876 if (i
->limit_exclusive
!= i
->limit
&& i
->limit_exclusive
!= UINT64_MAX
)
877 printf("\t Limit: %s (exclusive: %s)\n",
878 FORMAT_BYTES(i
->limit
), FORMAT_BYTES(i
->limit_exclusive
));
880 printf("\t Limit: %s\n", FORMAT_BYTES(i
->limit
));
884 static int show_image_info(sd_bus
*bus
, const char *path
, bool *new_line
) {
886 static const struct bus_properties_map map
[] = {
887 { "Name", "s", NULL
, offsetof(ImageStatusInfo
, name
) },
888 { "Path", "s", NULL
, offsetof(ImageStatusInfo
, path
) },
889 { "Type", "s", NULL
, offsetof(ImageStatusInfo
, type
) },
890 { "ReadOnly", "b", NULL
, offsetof(ImageStatusInfo
, read_only
) },
891 { "CreationTimestamp", "t", NULL
, offsetof(ImageStatusInfo
, crtime
) },
892 { "ModificationTimestamp", "t", NULL
, offsetof(ImageStatusInfo
, mtime
) },
893 { "Usage", "t", NULL
, offsetof(ImageStatusInfo
, usage
) },
894 { "Limit", "t", NULL
, offsetof(ImageStatusInfo
, limit
) },
895 { "UsageExclusive", "t", NULL
, offsetof(ImageStatusInfo
, usage_exclusive
) },
896 { "LimitExclusive", "t", NULL
, offsetof(ImageStatusInfo
, limit_exclusive
) },
900 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
901 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
902 ImageStatusInfo info
= {};
909 r
= bus_map_all_properties(bus
,
910 "org.freedesktop.machine1",
913 BUS_MAP_BOOLEAN_AS_BOOL
,
918 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
924 print_image_status_info(bus
, &info
);
929 typedef struct PoolStatusInfo
{
935 static void print_pool_status_info(sd_bus
*bus
, PoolStatusInfo
*i
) {
937 printf("\t Path: %s\n", i
->path
);
939 if (i
->usage
!= UINT64_MAX
)
940 printf("\t Usage: %s\n", FORMAT_BYTES(i
->usage
));
942 if (i
->limit
!= UINT64_MAX
)
943 printf("\t Limit: %s\n", FORMAT_BYTES(i
->limit
));
946 static int show_pool_info(sd_bus
*bus
) {
948 static const struct bus_properties_map map
[] = {
949 { "PoolPath", "s", NULL
, offsetof(PoolStatusInfo
, path
) },
950 { "PoolUsage", "t", NULL
, offsetof(PoolStatusInfo
, usage
) },
951 { "PoolLimit", "t", NULL
, offsetof(PoolStatusInfo
, limit
) },
955 PoolStatusInfo info
= {
960 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
961 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
966 r
= bus_map_all_properties(bus
,
967 "org.freedesktop.machine1",
968 "/org/freedesktop/machine1",
975 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
977 print_pool_status_info(bus
, &info
);
982 static int show_image_properties(sd_bus
*bus
, const char *path
, bool *new_line
) {
994 r
= bus_print_all_properties(bus
, "org.freedesktop.machine1", path
, NULL
, arg_property
, arg_print_flags
, NULL
);
996 log_error_errno(r
, "Could not get properties: %m");
1001 static int show_image(int argc
, char *argv
[], void *userdata
) {
1002 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1003 bool properties
, new_line
= false;
1004 sd_bus
*bus
= ASSERT_PTR(userdata
);
1007 properties
= !strstr(argv
[0], "status");
1009 pager_open(arg_pager_flags
);
1013 /* If no argument is specified, inspect the manager
1017 r
= show_image_properties(bus
, "/org/freedesktop/machine1", &new_line
);
1019 r
= show_pool_info(bus
);
1024 for (int i
= 1; i
< argc
; i
++) {
1025 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1026 const char *path
= NULL
;
1028 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImage", &error
, &reply
, "s", argv
[i
]);
1030 return log_error_errno(r
, "Could not get path to image: %s", bus_error_message(&error
, r
));
1032 r
= sd_bus_message_read(reply
, "o", &path
);
1034 return bus_log_parse_error(r
);
1037 r
= show_image_properties(bus
, path
, &new_line
);
1039 r
= show_image_info(bus
, path
, &new_line
);
1045 static int kill_machine(int argc
, char *argv
[], void *userdata
) {
1046 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1047 sd_bus
*bus
= ASSERT_PTR(userdata
);
1050 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1053 arg_kill_whom
= "all";
1055 for (int i
= 1; i
< argc
; i
++) {
1056 r
= bus_call_method(
1062 "ssi", argv
[i
], arg_kill_whom
, arg_signal
);
1064 return log_error_errno(r
, "Could not kill machine: %s", bus_error_message(&error
, r
));
1070 static int reboot_machine(int argc
, char *argv
[], void *userdata
) {
1071 if (arg_runner
== RUNNER_VMSPAWN
)
1072 return log_error_errno(
1073 SYNTHETIC_ERRNO(EOPNOTSUPP
),
1074 "%s only support supported for --runner=nspawn",
1075 streq(argv
[0], "reboot") ? "Reboot" : "Restart");
1077 arg_kill_whom
= "leader";
1078 arg_signal
= SIGINT
; /* sysvinit + systemd */
1080 return kill_machine(argc
, argv
, userdata
);
1083 static int poweroff_machine(int argc
, char *argv
[], void *userdata
) {
1084 arg_kill_whom
= "leader";
1085 arg_signal
= SIGRTMIN
+4; /* only systemd */
1087 return kill_machine(argc
, argv
, userdata
);
1090 static int terminate_machine(int argc
, char *argv
[], void *userdata
) {
1091 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1092 sd_bus
*bus
= ASSERT_PTR(userdata
);
1095 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1097 for (int i
= 1; i
< argc
; i
++) {
1098 r
= bus_call_method(bus
, bus_machine_mgr
, "TerminateMachine", &error
, NULL
, "s", argv
[i
]);
1100 return log_error_errno(r
, "Could not terminate machine: %s", bus_error_message(&error
, r
));
1106 static const char *select_copy_method(bool copy_from
, bool force
) {
1108 return copy_from
? "CopyFromMachineWithFlags" : "CopyToMachineWithFlags";
1110 return copy_from
? "CopyFromMachine" : "CopyToMachine";
1113 static int copy_files(int argc
, char *argv
[], void *userdata
) {
1114 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1115 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1116 _cleanup_free_
char *abs_host_path
= NULL
;
1117 char *dest
, *host_path
, *container_path
;
1118 sd_bus
*bus
= ASSERT_PTR(userdata
);
1122 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1124 copy_from
= streq(argv
[0], "copy-from");
1125 dest
= argv
[3] ?: argv
[2];
1126 host_path
= copy_from
? dest
: argv
[2];
1127 container_path
= copy_from
? argv
[2] : dest
;
1129 if (!path_is_absolute(host_path
)) {
1130 r
= path_make_absolute_cwd(host_path
, &abs_host_path
);
1132 return log_error_errno(r
, "Failed to make path absolute: %m");
1134 host_path
= abs_host_path
;
1137 r
= bus_message_new_method_call(
1141 select_copy_method(copy_from
, arg_force
));
1143 return bus_log_create_error(r
);
1145 r
= sd_bus_message_append(
1149 copy_from
? container_path
: host_path
,
1150 copy_from
? host_path
: container_path
);
1152 return bus_log_create_error(r
);
1155 r
= sd_bus_message_append(m
, "t", (uint64_t) MACHINE_COPY_REPLACE
);
1157 return bus_log_create_error(r
);
1160 /* This is a slow operation, hence turn off any method call timeouts */
1161 r
= sd_bus_call(bus
, m
, USEC_INFINITY
, &error
, NULL
);
1163 return log_error_errno(r
, "Failed to copy: %s", bus_error_message(&error
, r
));
1168 static int bind_mount(int argc
, char *argv
[], void *userdata
) {
1169 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1170 sd_bus
*bus
= ASSERT_PTR(userdata
);
1173 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1175 r
= bus_call_method(
1188 return log_error_errno(r
, "Failed to bind mount: %s", bus_error_message(&error
, r
));
1193 static int on_machine_removed(sd_bus_message
*m
, void *userdata
, sd_bus_error
*ret_error
) {
1194 PTYForward
** forward
= (PTYForward
**) userdata
;
1201 /* If the forwarder is already initialized, tell it to
1202 * exit on the next vhangup(), so that we still flush
1203 * out what might be queued and exit then. */
1205 r
= pty_forward_set_ignore_vhangup(*forward
, false);
1209 log_error_errno(r
, "Failed to set ignore_vhangup flag: %m");
1212 /* On error, or when the forwarder is not initialized yet, quit immediately */
1213 sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(m
)), EXIT_FAILURE
);
1217 static int process_forward(sd_event
*event
, PTYForward
**forward
, int master
, PTYForwardFlags flags
, const char *name
) {
1223 assert(master
>= 0);
1226 assert_se(sigprocmask_many(SIG_BLOCK
, NULL
, SIGWINCH
, SIGTERM
, SIGINT
) >= 0);
1229 if (streq(name
, ".host"))
1230 log_info("Connected to the local host. Press ^] three times within 1s to exit session.");
1232 log_info("Connected to machine %s. Press ^] three times within 1s to exit session.", name
);
1235 (void) sd_event_add_signal(event
, NULL
, SIGINT
, NULL
, NULL
);
1236 (void) sd_event_add_signal(event
, NULL
, SIGTERM
, NULL
, NULL
);
1238 r
= pty_forward_new(event
, master
, flags
, forward
);
1240 return log_error_errno(r
, "Failed to create PTY forwarder: %m");
1242 r
= sd_event_loop(event
);
1244 return log_error_errno(r
, "Failed to run event loop: %m");
1246 pty_forward_get_last_char(*forward
, &last_char
);
1249 (flags
& PTY_FORWARD_IGNORE_VHANGUP
) &&
1250 pty_forward_get_ignore_vhangup(*forward
) == 0;
1252 *forward
= pty_forward_free(*forward
);
1254 if (last_char
!= '\n')
1255 fputc('\n', stdout
);
1259 log_info("Machine %s terminated.", name
);
1260 else if (streq(name
, ".host"))
1261 log_info("Connection to the local host terminated.");
1263 log_info("Connection to machine %s terminated.", name
);
1269 static int parse_machine_uid(const char *spec
, const char **machine
, char **uid
) {
1271 * Whatever is specified in the spec takes priority over global arguments.
1274 const char *_machine
= NULL
;
1279 at
= strchr(spec
, '@');
1282 /* Do the same as ssh and refuse "@host". */
1286 _uid
= strndup(spec
, at
- spec
);
1293 if (arg_uid
&& !_uid
) {
1294 _uid
= strdup(arg_uid
);
1300 *machine
= isempty(_machine
) ? ".host" : _machine
;
1304 static int login_machine(int argc
, char *argv
[], void *userdata
) {
1305 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1306 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1307 _cleanup_(pty_forward_freep
) PTYForward
*forward
= NULL
;
1308 _cleanup_(sd_bus_slot_unrefp
) sd_bus_slot
*slot
= NULL
;
1309 _cleanup_(sd_event_unrefp
) sd_event
*event
= NULL
;
1311 sd_bus
*bus
= ASSERT_PTR(userdata
);
1312 const char *match
, *machine
;
1314 if (!strv_isempty(arg_setenv
) || arg_uid
)
1315 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1316 "--setenv= and --uid= are not supported for 'login'. Use 'shell' instead.");
1318 if (!IN_SET(arg_transport
, BUS_TRANSPORT_LOCAL
, BUS_TRANSPORT_MACHINE
))
1319 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1320 "Login only supported on local machines.");
1322 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1324 r
= sd_event_default(&event
);
1326 return log_error_errno(r
, "Failed to get event loop: %m");
1328 r
= sd_bus_attach_event(bus
, event
, 0);
1330 return log_error_errno(r
, "Failed to attach bus to event loop: %m");
1332 machine
= argc
< 2 || isempty(argv
[1]) ? ".host" : argv
[1];
1334 match
= strjoina("type='signal',"
1335 "sender='org.freedesktop.machine1',"
1336 "path='/org/freedesktop/machine1',",
1337 "interface='org.freedesktop.machine1.Manager',"
1338 "member='MachineRemoved',"
1339 "arg0='", machine
, "'");
1341 r
= sd_bus_add_match_async(bus
, &slot
, match
, on_machine_removed
, NULL
, &forward
);
1343 return log_error_errno(r
, "Failed to request machine removal match: %m");
1345 r
= bus_call_method(bus
, bus_machine_mgr
, "OpenMachineLogin", &error
, &reply
, "s", machine
);
1347 return log_error_errno(r
, "Failed to get login PTY: %s", bus_error_message(&error
, r
));
1349 r
= sd_bus_message_read(reply
, "hs", &master
, NULL
);
1351 return bus_log_parse_error(r
);
1353 return process_forward(event
, &forward
, master
, PTY_FORWARD_IGNORE_VHANGUP
, machine
);
1356 static int shell_machine(int argc
, char *argv
[], void *userdata
) {
1357 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
, *m
= NULL
;
1358 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1359 _cleanup_(pty_forward_freep
) PTYForward
*forward
= NULL
;
1360 _cleanup_(sd_bus_slot_unrefp
) sd_bus_slot
*slot
= NULL
;
1361 _cleanup_(sd_event_unrefp
) sd_event
*event
= NULL
;
1363 sd_bus
*bus
= ASSERT_PTR(userdata
);
1364 const char *match
, *machine
, *path
;
1365 _cleanup_free_
char *uid
= NULL
;
1367 if (!IN_SET(arg_transport
, BUS_TRANSPORT_LOCAL
, BUS_TRANSPORT_MACHINE
))
1368 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1369 "Shell only supported on local machines.");
1371 /* Pass $TERM to shell session, if not explicitly specified. */
1372 if (!strv_find_prefix(arg_setenv
, "TERM=")) {
1375 t
= strv_find_prefix(environ
, "TERM=");
1377 if (strv_extend(&arg_setenv
, t
) < 0)
1382 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1384 r
= sd_event_default(&event
);
1386 return log_error_errno(r
, "Failed to get event loop: %m");
1388 r
= sd_bus_attach_event(bus
, event
, 0);
1390 return log_error_errno(r
, "Failed to attach bus to event loop: %m");
1392 r
= parse_machine_uid(argc
>= 2 ? argv
[1] : NULL
, &machine
, &uid
);
1394 return log_error_errno(r
, "Failed to parse machine specification: %m");
1396 match
= strjoina("type='signal',"
1397 "sender='org.freedesktop.machine1',"
1398 "path='/org/freedesktop/machine1',",
1399 "interface='org.freedesktop.machine1.Manager',"
1400 "member='MachineRemoved',"
1401 "arg0='", machine
, "'");
1403 r
= sd_bus_add_match_async(bus
, &slot
, match
, on_machine_removed
, NULL
, &forward
);
1405 return log_error_errno(r
, "Failed to request machine removal match: %m");
1407 r
= bus_message_new_method_call(bus
, &m
, bus_machine_mgr
, "OpenMachineShell");
1409 return bus_log_create_error(r
);
1411 path
= argc
< 3 || isempty(argv
[2]) ? NULL
: argv
[2];
1413 r
= sd_bus_message_append(m
, "sss", machine
, uid
, path
);
1415 return bus_log_create_error(r
);
1417 r
= sd_bus_message_append_strv(m
, strv_length(argv
) <= 3 ? NULL
: argv
+ 2);
1419 return bus_log_create_error(r
);
1421 r
= sd_bus_message_append_strv(m
, arg_setenv
);
1423 return bus_log_create_error(r
);
1425 r
= sd_bus_call(bus
, m
, 0, &error
, &reply
);
1427 return log_error_errno(r
, "Failed to get shell PTY: %s", bus_error_message(&error
, r
));
1429 r
= sd_bus_message_read(reply
, "hs", &master
, NULL
);
1431 return bus_log_parse_error(r
);
1433 return process_forward(event
, &forward
, master
, 0, machine
);
1436 static int normalize_nspawn_filename(const char *name
, char **ret_file
) {
1437 _cleanup_free_
char *file
= NULL
;
1442 if (!endswith(name
, ".nspawn"))
1443 file
= strjoin(name
, ".nspawn");
1445 file
= strdup(name
);
1449 if (!filename_is_valid(file
))
1450 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Invalid settings file name '%s'.", file
);
1452 *ret_file
= TAKE_PTR(file
);
1456 static int get_settings_path(const char *name
, char **ret_path
) {
1460 FOREACH_STRING(i
, "/etc/systemd/nspawn", "/run/systemd/nspawn", "/var/lib/machines") {
1461 _cleanup_free_
char *path
= NULL
;
1463 path
= path_join(i
, name
);
1467 if (access(path
, F_OK
) >= 0) {
1468 *ret_path
= TAKE_PTR(path
);
1476 static int edit_settings(int argc
, char *argv
[], void *userdata
) {
1477 _cleanup_(edit_file_context_done
) EditFileContext context
= {};
1481 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Cannot edit machine settings if not on a tty.");
1483 if (arg_transport
!= BUS_TRANSPORT_LOCAL
)
1484 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1485 "Edit is only supported on the host machine.");
1487 if (arg_runner
== RUNNER_VMSPAWN
)
1488 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
), "Edit is only supported for --runner=nspawn");
1494 STRV_FOREACH(name
, strv_skip(argv
, 1)) {
1495 _cleanup_free_
char *file
= NULL
, *path
= NULL
;
1497 if (path_is_absolute(*name
)) {
1498 if (!path_is_safe(*name
))
1499 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1500 "Invalid settings file path '%s'.",
1503 r
= edit_files_add(&context
, *name
, NULL
, NULL
);
1509 r
= normalize_nspawn_filename(*name
, &file
);
1513 r
= get_settings_path(file
, &path
);
1515 log_debug("No existing settings file for machine '%s' found, creating a new file.", *name
);
1517 path
= path_join("/etc/systemd/nspawn", file
);
1521 r
= edit_files_add(&context
, path
, NULL
, NULL
);
1527 return log_error_errno(r
, "Failed to get the path of the settings file: %m");
1529 if (path_startswith(path
, "/var/lib/machines")) {
1530 _cleanup_free_
char *new_path
= NULL
;
1532 new_path
= path_join("/etc/systemd/nspawn", file
);
1536 r
= edit_files_add(&context
, new_path
, path
, NULL
);
1538 r
= edit_files_add(&context
, path
, NULL
, NULL
);
1543 return do_edit_files_and_install(&context
);
1546 static int cat_settings(int argc
, char *argv
[], void *userdata
) {
1549 if (arg_transport
!= BUS_TRANSPORT_LOCAL
)
1550 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1551 "Cat is only supported on the host machine.");
1553 if (arg_runner
== RUNNER_VMSPAWN
)
1554 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
), "Cat is only supported for --runner=nspawn");
1556 pager_open(arg_pager_flags
);
1558 STRV_FOREACH(name
, strv_skip(argv
, 1)) {
1559 _cleanup_free_
char *file
= NULL
, *path
= NULL
;
1562 if (path_is_absolute(*name
)) {
1563 if (!path_is_safe(*name
))
1564 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1565 "Invalid settings file path '%s'.",
1568 q
= cat_files(*name
, /* dropins = */ NULL
, /* flags = */ CAT_FORMAT_HAS_SECTIONS
);
1570 return r
< 0 ? r
: q
;
1574 q
= normalize_nspawn_filename(*name
, &file
);
1576 return r
< 0 ? r
: q
;
1578 q
= get_settings_path(file
, &path
);
1580 log_error_errno(q
, "No settings file found for machine '%s'.", *name
);
1585 log_error_errno(q
, "Failed to get the path of the settings file: %m");
1586 return r
< 0 ? r
: q
;
1589 q
= cat_files(path
, /* dropins = */ NULL
, /* flags = */ CAT_FORMAT_HAS_SECTIONS
);
1591 return r
< 0 ? r
: q
;
1597 static int remove_image(int argc
, char *argv
[], void *userdata
) {
1598 sd_bus
*bus
= ASSERT_PTR(userdata
);
1601 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1603 for (int i
= 1; i
< argc
; i
++) {
1604 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1605 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1607 r
= bus_message_new_method_call(bus
, &m
, bus_machine_mgr
, "RemoveImage");
1609 return bus_log_create_error(r
);
1611 r
= sd_bus_message_append(m
, "s", argv
[i
]);
1613 return bus_log_create_error(r
);
1615 /* This is a slow operation, hence turn off any method call timeouts */
1616 r
= sd_bus_call(bus
, m
, USEC_INFINITY
, &error
, NULL
);
1618 return log_error_errno(r
, "Could not remove image: %s", bus_error_message(&error
, r
));
1624 static int rename_image(int argc
, char *argv
[], void *userdata
) {
1625 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1626 sd_bus
*bus
= ASSERT_PTR(userdata
);
1629 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1631 r
= bus_call_method(
1637 "ss", argv
[1], argv
[2]);
1639 return log_error_errno(r
, "Could not rename image: %s", bus_error_message(&error
, r
));
1644 static int clone_image(int argc
, char *argv
[], void *userdata
) {
1645 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1646 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1647 sd_bus
*bus
= ASSERT_PTR(userdata
);
1650 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1652 r
= bus_message_new_method_call(bus
, &m
, bus_machine_mgr
, "CloneImage");
1654 return bus_log_create_error(r
);
1656 r
= sd_bus_message_append(m
, "ssb", argv
[1], argv
[2], arg_read_only
);
1658 return bus_log_create_error(r
);
1660 /* This is a slow operation, hence turn off any method call timeouts */
1661 r
= sd_bus_call(bus
, m
, USEC_INFINITY
, &error
, NULL
);
1663 return log_error_errno(r
, "Could not clone image: %s", bus_error_message(&error
, r
));
1668 static int read_only_image(int argc
, char *argv
[], void *userdata
) {
1669 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1670 sd_bus
*bus
= ASSERT_PTR(userdata
);
1674 b
= parse_boolean(argv
[2]);
1676 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1677 "Failed to parse boolean argument: %s",
1681 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1683 r
= bus_call_method(bus
, bus_machine_mgr
, "MarkImageReadOnly", &error
, NULL
, "sb", argv
[1], b
);
1685 return log_error_errno(r
, "Could not mark image read-only: %s", bus_error_message(&error
, r
));
1690 static int image_exists(sd_bus
*bus
, const char *name
) {
1691 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1697 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImage", &error
, NULL
, "s", name
);
1699 if (sd_bus_error_has_name(&error
, BUS_ERROR_NO_SUCH_IMAGE
))
1702 return log_error_errno(r
, "Failed to check whether image %s exists: %s", name
, bus_error_message(&error
, r
));
1708 static int make_service_name(const char *name
, char **ret
) {
1713 assert(arg_runner
>= 0 && arg_runner
< (MachineRunner
) ELEMENTSOF(machine_runner_unit_prefix_table
));
1715 if (!hostname_is_valid(name
, 0))
1716 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1717 "Invalid machine name %s.", name
);
1719 r
= unit_name_build(machine_runner_unit_prefix_table
[arg_runner
], name
, ".service", ret
);
1721 return log_error_errno(r
, "Failed to build unit name: %m");
1726 static int start_machine(int argc
, char *argv
[], void *userdata
) {
1727 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1728 _cleanup_(bus_wait_for_jobs_freep
) BusWaitForJobs
*w
= NULL
;
1729 sd_bus
*bus
= ASSERT_PTR(userdata
);
1732 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1733 ask_password_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1735 r
= bus_wait_for_jobs_new(bus
, &w
);
1737 return log_error_errno(r
, "Could not watch jobs: %m");
1739 for (int i
= 1; i
< argc
; i
++) {
1740 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1741 _cleanup_free_
char *unit
= NULL
;
1744 r
= make_service_name(argv
[i
], &unit
);
1748 r
= image_exists(bus
, argv
[i
]);
1752 return log_error_errno(SYNTHETIC_ERRNO(ENXIO
),
1753 "Machine image '%s' does not exist.",
1756 r
= bus_call_method(
1762 "ss", unit
, "fail");
1764 return log_error_errno(r
, "Failed to start unit: %s", bus_error_message(&error
, r
));
1766 r
= sd_bus_message_read(reply
, "o", &object
);
1768 return bus_log_parse_error(r
);
1770 r
= bus_wait_for_jobs_add(w
, object
);
1775 r
= bus_wait_for_jobs(w
, arg_quiet
, NULL
);
1782 static int enable_machine(int argc
, char *argv
[], void *userdata
) {
1783 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
, *reply
= NULL
;
1784 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1786 sd_bus
*bus
= ASSERT_PTR(userdata
);
1790 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1792 enable
= streq(argv
[0], "enable");
1793 method
= enable
? "EnableUnitFiles" : "DisableUnitFiles";
1795 r
= bus_message_new_method_call(bus
, &m
, bus_systemd_mgr
, method
);
1797 return bus_log_create_error(r
);
1799 r
= sd_bus_message_open_container(m
, 'a', "s");
1801 return bus_log_create_error(r
);
1804 r
= sd_bus_message_append(m
, "s", "machines.target");
1806 return bus_log_create_error(r
);
1809 for (int i
= 1; i
< argc
; i
++) {
1810 _cleanup_free_
char *unit
= NULL
;
1812 r
= make_service_name(argv
[i
], &unit
);
1816 r
= image_exists(bus
, argv
[i
]);
1820 return log_error_errno(SYNTHETIC_ERRNO(ENXIO
),
1821 "Machine image '%s' does not exist.",
1824 r
= sd_bus_message_append(m
, "s", unit
);
1826 return bus_log_create_error(r
);
1829 r
= sd_bus_message_close_container(m
);
1831 return bus_log_create_error(r
);
1834 r
= sd_bus_message_append(m
, "bb", false, false);
1836 r
= sd_bus_message_append(m
, "b", false);
1838 return bus_log_create_error(r
);
1840 r
= sd_bus_call(bus
, m
, 0, &error
, &reply
);
1842 return log_error_errno(r
, "Failed to enable or disable unit: %s", bus_error_message(&error
, r
));
1845 r
= sd_bus_message_read(reply
, "b", NULL
);
1847 return bus_log_parse_error(r
);
1850 r
= bus_deserialize_and_dump_unit_file_changes(reply
, arg_quiet
);
1854 r
= bus_service_manager_reload(bus
);
1859 _cleanup_strv_free_
char **new_args
= NULL
;
1861 new_args
= strv_new(enable
? "start" : "poweroff");
1865 r
= strv_extend_strv(&new_args
, argv
+ 1, /* filter_duplicates = */ false);
1870 return start_machine(strv_length(new_args
), new_args
, userdata
);
1872 return poweroff_machine(strv_length(new_args
), new_args
, userdata
);
1878 static int set_limit(int argc
, char *argv
[], void *userdata
) {
1879 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1880 sd_bus
*bus
= userdata
;
1884 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1886 if (STR_IN_SET(argv
[argc
-1], "-", "none", "infinity"))
1889 r
= parse_size(argv
[argc
-1], 1024, &limit
);
1891 return log_error_errno(r
, "Failed to parse size: %s", argv
[argc
-1]);
1895 /* With two arguments changes the quota limit of the
1896 * specified image */
1897 r
= bus_call_method(bus
, bus_machine_mgr
, "SetImageLimit", &error
, NULL
, "st", argv
[1], limit
);
1899 /* With one argument changes the pool quota limit */
1900 r
= bus_call_method(bus
, bus_machine_mgr
, "SetPoolLimit", &error
, NULL
, "t", limit
);
1903 return log_error_errno(r
, "Could not set limit: %s", bus_error_message(&error
, r
));
1908 static int clean_images(int argc
, char *argv
[], void *userdata
) {
1909 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
, *reply
= NULL
;
1910 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1911 uint64_t usage
, total
= 0;
1912 sd_bus
*bus
= userdata
;
1917 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1919 r
= bus_message_new_method_call(bus
, &m
, bus_machine_mgr
, "CleanPool");
1921 return bus_log_create_error(r
);
1923 r
= sd_bus_message_append(m
, "s", arg_all
? "all" : "hidden");
1925 return bus_log_create_error(r
);
1927 /* This is a slow operation, hence permit a longer time for completion. */
1928 r
= sd_bus_call(bus
, m
, USEC_INFINITY
, &error
, &reply
);
1930 return log_error_errno(r
, "Could not clean pool: %s", bus_error_message(&error
, r
));
1932 r
= sd_bus_message_enter_container(reply
, 'a', "(st)");
1934 return bus_log_parse_error(r
);
1936 while ((r
= sd_bus_message_read(reply
, "(st)", &name
, &usage
)) > 0) {
1937 if (usage
== UINT64_MAX
) {
1938 log_info("Removed image '%s'", name
);
1941 log_info("Removed image '%s'. Freed exclusive disk space: %s",
1942 name
, FORMAT_BYTES(usage
));
1943 if (total
!= UINT64_MAX
)
1949 r
= sd_bus_message_exit_container(reply
);
1951 return bus_log_parse_error(r
);
1953 if (total
== UINT64_MAX
)
1954 log_info("Removed %u images in total.", c
);
1956 log_info("Removed %u images in total. Total freed exclusive disk space: %s.",
1957 c
, FORMAT_BYTES(total
));
1962 static int chainload_importctl(int argc
, char *argv
[]) {
1965 log_notice("The 'machinectl %1$s' command has been replaced by 'importctl -m %1$s'. Redirecting invocation.", argv
[optind
]);
1967 _cleanup_strv_free_
char **c
=
1968 strv_new("importctl", "--class=machine");
1972 if (FLAGS_SET(arg_pager_flags
, PAGER_DISABLE
))
1973 if (strv_extend(&c
, "--no-pager") < 0)
1976 if (strv_extend(&c
, "--no-legend") < 0)
1979 if (strv_extend(&c
, "--read-only") < 0)
1982 if (strv_extend(&c
, "--force") < 0)
1985 if (strv_extend(&c
, "--quiet") < 0)
1987 if (!arg_ask_password
)
1988 if (strv_extend(&c
, "--no-ask-password") < 0)
1990 if (strv_extend_many(&c
, "--verify", import_verify_to_string(arg_verify
)) < 0)
1993 if (strv_extend_many(&c
, "--format", arg_format
) < 0)
1996 if (strv_extend_strv(&c
, argv
+ optind
, /* filter_duplicates= */ false) < 0)
1999 if (DEBUG_LOGGING
) {
2000 _cleanup_free_
char *joined
= strv_join(c
, " ");
2001 log_debug("Chainloading: %s", joined
);
2004 r
= invoke_callout_binary(BINDIR
"/importctl", c
);
2005 return log_error_errno(r
, "Failed to invoke 'importctl': %m");
2008 static int help(int argc
, char *argv
[], void *userdata
) {
2009 _cleanup_free_
char *link
= NULL
;
2012 pager_open(arg_pager_flags
);
2014 r
= terminal_urlify_man("machinectl", "1", &link
);
2018 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
2019 "%5$sSend control commands to or query the virtual machine and container%6$s\n"
2020 "%5$sregistration manager.%6$s\n"
2021 "\n%3$sMachine Commands:%4$s\n"
2022 " list List running VMs and containers\n"
2023 " status NAME... Show VM/container details\n"
2024 " show [NAME...] Show properties of one or more VMs/containers\n"
2025 " start NAME... Start container as a service\n"
2026 " login [NAME] Get a login prompt in a container or on the\n"
2028 " shell [[USER@]NAME [COMMAND...]]\n"
2029 " Invoke a shell (or other command) in a container\n"
2030 " or on the local host\n"
2031 " enable NAME... Enable automatic container start at boot\n"
2032 " disable NAME... Disable automatic container start at boot\n"
2033 " poweroff NAME... Power off one or more containers\n"
2034 " reboot NAME... Reboot one or more containers\n"
2035 " terminate NAME... Terminate one or more VMs/containers\n"
2036 " kill NAME... Send signal to processes of a VM/container\n"
2037 " copy-to NAME PATH [PATH] Copy files from the host to a container\n"
2038 " copy-from NAME PATH [PATH] Copy files from a container to the host\n"
2039 " bind NAME PATH [PATH] Bind mount a path from the host into a container\n"
2040 "\n%3$sImage Commands:%4$s\n"
2041 " list-images Show available container and VM images\n"
2042 " image-status [NAME...] Show image details\n"
2043 " show-image [NAME...] Show properties of image\n"
2044 " edit NAME|FILE... Edit settings of one or more VMs/containers\n"
2045 " cat NAME|FILE... Show settings of one or more VMs/containers\n"
2046 " clone NAME NAME Clone an image\n"
2047 " rename NAME NAME Rename an image\n"
2048 " read-only NAME [BOOL] Mark or unmark image read-only\n"
2049 " remove NAME... Remove an image\n"
2050 " set-limit [NAME] BYTES Set image or pool size limit (disk quota)\n"
2051 " clean Remove hidden (or all) images\n"
2052 "\n%3$sOptions:%4$s\n"
2053 " -h --help Show this help\n"
2054 " --version Show package version\n"
2055 " --no-pager Do not pipe output into a pager\n"
2056 " --no-legend Do not show the headers and footers\n"
2057 " --no-ask-password Do not ask for system passwords\n"
2058 " -H --host=[USER@]HOST Operate on remote host\n"
2059 " -M --machine=CONTAINER Operate on local container\n"
2060 " -p --property=NAME Show only properties by this name\n"
2061 " --value When showing properties, only print the value\n"
2062 " -P NAME Equivalent to --value --property=NAME\n"
2063 " -q --quiet Suppress output\n"
2064 " -a --all Show all properties, including empty ones\n"
2065 " -l --full Do not ellipsize output\n"
2066 " --kill-whom=WHOM Whom to send signal to\n"
2067 " -s --signal=SIGNAL Which signal to send\n"
2068 " --uid=USER Specify user ID to invoke shell as\n"
2069 " -E --setenv=VAR[=VALUE] Add an environment variable for shell\n"
2070 " --read-only Create read-only bind mount or clone\n"
2071 " --mkdir Create directory before bind mounting, if missing\n"
2072 " -n --lines=INTEGER Number of journal entries to show\n"
2073 " --max-addresses=INTEGER Number of internet addresses to show at most\n"
2074 " -o --output=STRING Change journal output mode (short, short-precise,\n"
2075 " short-iso, short-iso-precise, short-full,\n"
2076 " short-monotonic, short-unix, short-delta,\n"
2077 " json, json-pretty, json-sse, json-seq, cat,\n"
2078 " verbose, export, with-unit)\n"
2079 " --force Replace target file when copying, if necessary\n"
2080 " --now Start or power off container after enabling or\n"
2082 " --runner=RUNNER Select between nspawn and vmspawn as the runner\n"
2083 " -V Short for --runner=vmspawn\n"
2084 "\nSee the %2$s for details.\n",
2085 program_invocation_short_name
,
2095 static int parse_argv(int argc
, char *argv
[]) {
2098 ARG_VERSION
= 0x100,
2105 ARG_NO_ASK_PASSWORD
,
2115 static const struct option options
[] = {
2116 { "help", no_argument
, NULL
, 'h' },
2117 { "version", no_argument
, NULL
, ARG_VERSION
},
2118 { "property", required_argument
, NULL
, 'p' },
2119 { "value", no_argument
, NULL
, ARG_VALUE
},
2120 { "all", no_argument
, NULL
, 'a' },
2121 { "full", no_argument
, NULL
, 'l' },
2122 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
2123 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
},
2124 { "kill-whom", required_argument
, NULL
, ARG_KILL_WHOM
},
2125 { "signal", required_argument
, NULL
, 's' },
2126 { "host", required_argument
, NULL
, 'H' },
2127 { "machine", required_argument
, NULL
, 'M' },
2128 { "read-only", no_argument
, NULL
, ARG_READ_ONLY
},
2129 { "mkdir", no_argument
, NULL
, ARG_MKDIR
},
2130 { "quiet", no_argument
, NULL
, 'q' },
2131 { "lines", required_argument
, NULL
, 'n' },
2132 { "output", required_argument
, NULL
, 'o' },
2133 { "no-ask-password", no_argument
, NULL
, ARG_NO_ASK_PASSWORD
},
2134 { "verify", required_argument
, NULL
, ARG_VERIFY
},
2135 { "runner", required_argument
, NULL
, ARG_RUNNER
},
2136 { "now", no_argument
, NULL
, ARG_NOW
},
2137 { "force", no_argument
, NULL
, ARG_FORCE
},
2138 { "format", required_argument
, NULL
, ARG_FORMAT
},
2139 { "uid", required_argument
, NULL
, ARG_UID
},
2140 { "setenv", required_argument
, NULL
, 'E' },
2141 { "max-addresses", required_argument
, NULL
, ARG_MAX_ADDRESSES
},
2145 bool reorder
= false;
2146 int c
, r
, shell
= -1;
2151 /* Resetting to 0 forces the invocation of an internal initialization routine of getopt_long()
2152 * that checks for GNU extensions in optstring ('-' or '+' at the beginning). */
2156 static const char option_string
[] = "-hp:P:als:H:M:qn:o:E:V";
2158 c
= getopt_long(argc
, argv
, option_string
+ reorder
, options
, NULL
);
2164 case 1: /* getopt_long() returns 1 if "-" was the first character of the option string, and a
2165 * non-option argument was discovered. */
2169 /* We generally are fine with the fact that getopt_long() reorders the command line, and looks
2170 * for switches after the main verb. However, for "shell" we really don't want that, since we
2171 * want that switches specified after the machine name are passed to the program to execute,
2172 * and not processed by us. To make this possible, we'll first invoke getopt_long() with
2173 * reordering disabled (i.e. with the "-" prefix in the option string), looking for the first
2174 * non-option parameter. If it's the verb "shell" we remember its position and continue
2175 * processing options. In this case, as soon as we hit the next non-option argument we found
2176 * the machine name, and stop further processing. If the first non-option argument is any other
2177 * verb than "shell" we switch to normal reordering mode and continue processing arguments
2181 /* If we already found the "shell" verb on the command line, and now found the next
2182 * non-option argument, then this is the machine name and we should stop processing
2183 * further arguments. */
2184 optind
--; /* don't process this argument, go one step back */
2187 if (streq(optarg
, "shell"))
2188 /* Remember the position of the "shell" verb, and continue processing normally. */
2193 /* OK, this is some other verb. In this case, turn on reordering again, and continue
2194 * processing normally. */
2197 /* We changed the option string. getopt_long() only looks at it again if we invoke it
2198 * at least once with a reset option index. Hence, let's reset the option index here,
2199 * then invoke getopt_long() again (ignoring what it has to say, after all we most
2200 * likely already processed it), and the bump the option index so that we read the
2201 * intended argument again. */
2202 saved_optind
= optind
;
2204 (void) getopt_long(argc
, argv
, option_string
+ reorder
, options
, NULL
);
2205 optind
= saved_optind
- 1; /* go one step back, process this argument again */
2211 return help(0, NULL
, NULL
);
2218 r
= strv_extend(&arg_property
, optarg
);
2222 /* If the user asked for a particular property, show it to them, even if empty. */
2223 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
, true);
2230 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_ONLY_VALUE
, true);
2234 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
, true);
2243 if (safe_atou(optarg
, &arg_lines
) < 0)
2244 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
2245 "Failed to parse lines '%s'", optarg
);
2249 if (streq(optarg
, "help")) {
2250 DUMP_STRING_TABLE(output_mode
, OutputMode
, _OUTPUT_MODE_MAX
);
2254 r
= output_mode_from_string(optarg
);
2256 return log_error_errno(r
, "Unknown output '%s'.", optarg
);
2259 if (OUTPUT_MODE_IS_JSON(arg_output
))
2264 arg_pager_flags
|= PAGER_DISABLE
;
2272 arg_kill_whom
= optarg
;
2276 r
= parse_signal_argument(optarg
, &arg_signal
);
2281 case ARG_NO_ASK_PASSWORD
:
2282 arg_ask_password
= false;
2286 arg_transport
= BUS_TRANSPORT_REMOTE
;
2291 arg_transport
= BUS_TRANSPORT_MACHINE
;
2296 arg_read_only
= true;
2308 if (streq(optarg
, "help")) {
2309 DUMP_STRING_TABLE(import_verify
, ImportVerify
, _IMPORT_VERIFY_MAX
);
2313 r
= import_verify_from_string(optarg
);
2315 return log_error_errno(r
, "Failed to parse --verify= setting: %s", optarg
);
2320 arg_runner
= RUNNER_VMSPAWN
;
2324 r
= machine_runner_from_string(optarg
);
2326 return log_error_errno(r
, "Failed to parse --runner= setting: %s", optarg
);
2340 if (!STR_IN_SET(optarg
, "uncompressed", "xz", "gzip", "bzip2"))
2341 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
2342 "Unknown format: %s", optarg
);
2344 arg_format
= optarg
;
2352 r
= strv_env_replace_strdup_passthrough(&arg_setenv
, optarg
);
2354 return log_error_errno(r
, "Cannot assign environment variable %s: %m", optarg
);
2357 case ARG_MAX_ADDRESSES
:
2358 if (streq(optarg
, "all"))
2359 arg_max_addresses
= UINT_MAX
;
2360 else if (safe_atou(optarg
, &arg_max_addresses
) < 0)
2361 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
2362 "Invalid number of addresses: %s", optarg
);
2369 assert_not_reached();
2377 /* We found the "shell" verb while processing the argument list. Since we turned off reordering of the
2378 * argument list initially let's readjust it now, and move the "shell" verb to the back. */
2380 optind
-= 1; /* place the option index where the "shell" verb will be placed */
2383 for (int i
= shell
; i
< optind
; i
++)
2384 argv
[i
] = argv
[i
+1];
2391 static int machinectl_main(int argc
, char *argv
[], sd_bus
*bus
) {
2393 static const Verb verbs
[] = {
2394 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
2395 { "list", VERB_ANY
, 1, VERB_DEFAULT
, list_machines
},
2396 { "list-images", VERB_ANY
, 1, 0, list_images
},
2397 { "status", 2, VERB_ANY
, 0, show_machine
},
2398 { "image-status", VERB_ANY
, VERB_ANY
, 0, show_image
},
2399 { "show", VERB_ANY
, VERB_ANY
, 0, show_machine
},
2400 { "show-image", VERB_ANY
, VERB_ANY
, 0, show_image
},
2401 { "terminate", 2, VERB_ANY
, 0, terminate_machine
},
2402 { "reboot", 2, VERB_ANY
, 0, reboot_machine
},
2403 { "restart", 2, VERB_ANY
, 0, reboot_machine
}, /* Convenience alias */
2404 { "poweroff", 2, VERB_ANY
, 0, poweroff_machine
},
2405 { "stop", 2, VERB_ANY
, 0, poweroff_machine
}, /* Convenience alias */
2406 { "kill", 2, VERB_ANY
, 0, kill_machine
},
2407 { "login", VERB_ANY
, 2, 0, login_machine
},
2408 { "shell", VERB_ANY
, VERB_ANY
, 0, shell_machine
},
2409 { "bind", 3, 4, 0, bind_mount
},
2410 { "edit", 2, VERB_ANY
, 0, edit_settings
},
2411 { "cat", 2, VERB_ANY
, 0, cat_settings
},
2412 { "copy-to", 3, 4, 0, copy_files
},
2413 { "copy-from", 3, 4, 0, copy_files
},
2414 { "remove", 2, VERB_ANY
, 0, remove_image
},
2415 { "rename", 3, 3, 0, rename_image
},
2416 { "clone", 3, 3, 0, clone_image
},
2417 { "read-only", 2, 3, 0, read_only_image
},
2418 { "start", 2, VERB_ANY
, 0, start_machine
},
2419 { "enable", 2, VERB_ANY
, 0, enable_machine
},
2420 { "disable", 2, VERB_ANY
, 0, enable_machine
},
2421 { "set-limit", 2, 3, 0, set_limit
},
2422 { "clean", VERB_ANY
, 1, 0, clean_images
},
2426 return dispatch_verb(argc
, argv
, verbs
, bus
);
2429 static int run(int argc
, char *argv
[]) {
2430 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2433 setlocale(LC_ALL
, "");
2436 /* The journal merging logic potentially needs a lot of fds. */
2437 (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE
);
2440 r
= parse_argv(argc
, argv
);
2444 if (STRPTR_IN_SET(argv
[optind
],
2445 "import-tar", "import-raw", "import-fs",
2446 "export-tar", "export-raw",
2447 "pull-tar", "pull-raw",
2448 "list-transfers", "cancel-transfer"))
2449 return chainload_importctl(argc
, argv
);
2451 r
= bus_connect_transport(arg_transport
, arg_host
, RUNTIME_SCOPE_SYSTEM
, &bus
);
2453 return bus_log_connect_error(r
, arg_transport
);
2455 (void) sd_bus_set_allow_interactive_authorization(bus
, arg_ask_password
);
2457 return machinectl_main(argc
, argv
, bus
);
2460 DEFINE_MAIN_FUNCTION(run
);