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
;
132 r
= bus_call_method(bus
, bus_machine_mgr
, method
, &error
, &reply
, "s", name
);
134 return log_debug_errno(r
, "Failed to call '%s()': %s", method
, bus_error_message(&error
, r
));
136 r
= sd_bus_message_enter_container(reply
, 'a', "{ss}");
138 return bus_log_parse_error(r
);
143 NULSTR_FOREACH(i
, query
)
146 res
= newa0(const char*, n_fields
);
149 while ((r
= sd_bus_message_read(reply
, "{ss}", &k
, &v
)) > 0) {
151 NULSTR_FOREACH(i
, query
) {
160 return bus_log_parse_error(r
);
162 r
= sd_bus_message_exit_container(reply
);
164 return bus_log_parse_error(r
);
169 FOREACH_ARRAY(i
, res
, n_fields
) {
170 r
= strdup_to(va_arg(ap
, char**), *i
);
179 static int call_get_addresses(
187 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
188 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
189 _cleanup_free_
char *addresses
= NULL
;
198 r
= bus_call_method(bus
, bus_machine_mgr
, "GetMachineAddresses", NULL
, &reply
, "s", name
);
200 return log_debug_errno(r
, "Could not get addresses: %s", bus_error_message(&error
, r
));
202 addresses
= strdup(prefix
);
206 r
= sd_bus_message_enter_container(reply
, 'a', "(iay)");
208 return bus_log_parse_error(r
);
211 while ((r
= sd_bus_message_enter_container(reply
, 'r', "iay")) > 0) {
215 char buf_ifi
[1 + DECIMAL_STR_MAX(int)] = "";
217 r
= sd_bus_message_read(reply
, "i", &family
);
219 return bus_log_parse_error(r
);
221 r
= sd_bus_message_read_array(reply
, 'y', &a
, &sz
);
223 return bus_log_parse_error(r
);
225 if (family
== AF_INET6
&& ifi
> 0)
226 xsprintf(buf_ifi
, "%%%i", ifi
);
228 if (!strextend(&addresses
, prefix
, IN_ADDR_TO_STRING(family
, a
), buf_ifi
))
231 r
= sd_bus_message_exit_container(reply
);
233 return bus_log_parse_error(r
);
240 return bus_log_parse_error(r
);
242 r
= sd_bus_message_exit_container(reply
);
244 return bus_log_parse_error(r
);
246 *ret
= TAKE_PTR(addresses
);
250 static int show_table(Table
*table
, const char *word
) {
256 if (!table_isempty(table
) || OUTPUT_MODE_IS_JSON(arg_output
)) {
257 r
= table_set_sort(table
, (size_t) 0);
259 return table_log_sort_error(r
);
261 table_set_header(table
, arg_legend
);
263 if (OUTPUT_MODE_IS_JSON(arg_output
))
264 r
= table_print_json(table
, NULL
, output_mode_to_json_format_flags(arg_output
) | JSON_FORMAT_COLOR_AUTO
);
266 r
= table_print(table
, NULL
);
268 return table_log_print_error(r
);
272 if (table_isempty(table
))
273 printf("No %s.\n", word
);
275 printf("\n%zu %s listed.\n", table_get_rows(table
) - 1, word
);
281 static int list_machines(int argc
, char *argv
[], void *userdata
) {
282 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
283 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
284 _cleanup_(table_unrefp
) Table
*table
= NULL
;
285 sd_bus
*bus
= ASSERT_PTR(userdata
);
288 pager_open(arg_pager_flags
);
290 r
= bus_call_method(bus
, bus_machine_mgr
, "ListMachines", &error
, &reply
, NULL
);
292 return log_error_errno(r
, "Could not get machines: %s", bus_error_message(&error
, r
));
294 table
= table_new("machine", "class", "service", "os", "version",
295 arg_max_addresses
> 0 ? "addresses" : NULL
);
299 table_set_ersatz_string(table
, TABLE_ERSATZ_DASH
);
300 if (!arg_full
&& arg_max_addresses
> 0 && arg_max_addresses
< UINT_MAX
)
301 table_set_cell_height_max(table
, arg_max_addresses
);
304 table_set_width(table
, 0);
306 r
= sd_bus_message_enter_container(reply
, 'a', "(ssso)");
308 return bus_log_parse_error(r
);
311 _cleanup_free_
char *os
= NULL
, *version_id
= NULL
, *addresses
= NULL
;
312 const char *name
, *class, *service
;
314 r
= sd_bus_message_read(reply
, "(ssso)", &name
, &class, &service
, NULL
);
316 return bus_log_parse_error(r
);
320 if (name
[0] == '.' && !arg_all
)
323 (void) call_get_os_release(
325 "GetMachineOSRelease",
332 r
= table_add_many(table
,
333 TABLE_STRING
, empty_to_null(name
),
334 TABLE_STRING
, empty_to_null(class),
335 TABLE_STRING
, empty_to_null(service
),
336 TABLE_STRING
, empty_to_null(os
),
337 TABLE_STRING
, empty_to_null(version_id
));
339 return table_log_add_error(r
);
341 if (arg_max_addresses
> 0) {
342 (void) call_get_addresses(bus
, name
, 0, "", "\n", &addresses
);
344 r
= table_add_many(table
,
345 TABLE_STRING
, empty_to_null(addresses
));
347 return table_log_add_error(r
);
351 r
= sd_bus_message_exit_container(reply
);
353 return bus_log_parse_error(r
);
355 return show_table(table
, "machines");
358 static int list_images(int argc
, char *argv
[], void *userdata
) {
360 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
361 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
362 _cleanup_(table_unrefp
) Table
*table
= NULL
;
363 sd_bus
*bus
= ASSERT_PTR(userdata
);
366 pager_open(arg_pager_flags
);
368 r
= bus_call_method(bus
, bus_machine_mgr
, "ListImages", &error
, &reply
, NULL
);
370 return log_error_errno(r
, "Could not get images: %s", bus_error_message(&error
, r
));
372 table
= table_new("name", "type", "ro", "usage", "created", "modified");
377 table_set_width(table
, 0);
379 (void) table_set_align_percent(table
, TABLE_HEADER_CELL(3), 100);
381 r
= sd_bus_message_enter_container(reply
, SD_BUS_TYPE_ARRAY
, "(ssbttto)");
383 return bus_log_parse_error(r
);
386 uint64_t crtime
, mtime
, size
;
387 const char *name
, *type
;
390 r
= sd_bus_message_read(reply
, "(ssbttto)", &name
, &type
, &ro_int
, &crtime
, &mtime
, &size
, NULL
);
392 return bus_log_parse_error(r
);
396 if (name
[0] == '.' && !arg_all
)
399 r
= table_add_many(table
,
402 TABLE_BOOLEAN
, ro_int
,
403 TABLE_SET_COLOR
, ro_int
? ansi_highlight_red() : NULL
,
405 TABLE_TIMESTAMP
, crtime
,
406 TABLE_TIMESTAMP
, mtime
);
408 return table_log_add_error(r
);
411 r
= sd_bus_message_exit_container(reply
);
413 return bus_log_parse_error(r
);
415 return show_table(table
, "images");
418 static int show_unit_cgroup(sd_bus
*bus
, const char *unit
, pid_t leader
) {
419 _cleanup_free_
char *cgroup
= NULL
;
420 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
427 r
= show_cgroup_get_unit_path_and_warn(bus
, unit
, &cgroup
);
440 r
= unit_show_processes(bus
, unit
, cgroup
, "\t\t ", c
, get_output_flags(), &error
);
443 if (arg_transport
== BUS_TRANSPORT_REMOTE
)
446 /* Fallback for older systemd versions where the GetUnitProcesses() call is not yet available */
448 if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER
, cgroup
) != 0 && leader
<= 0)
451 show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER
, cgroup
, "\t\t ", c
, &leader
, leader
> 0, get_output_flags());
453 return log_error_errno(r
, "Failed to dump process list: %s", bus_error_message(&error
, r
));
458 static int print_os_release(sd_bus
*bus
, const char *method
, const char *name
, const char *prefix
) {
459 _cleanup_free_
char *pretty
= NULL
;
466 r
= call_get_os_release(bus
, method
, name
, "PRETTY_NAME\0", &pretty
, NULL
);
471 printf("%s%s\n", prefix
, pretty
);
476 static int print_uid_shift(sd_bus
*bus
, const char *name
) {
477 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
478 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
485 r
= bus_call_method(bus
, bus_machine_mgr
, "GetMachineUIDShift", &error
, &reply
, "s", name
);
487 return log_debug_errno(r
, "Failed to query UID/GID shift: %s", bus_error_message(&error
, r
));
489 r
= sd_bus_message_read(reply
, "u", &shift
);
493 if (shift
== 0) /* Don't show trivial mappings */
496 printf(" UID Shift: %" PRIu32
"\n", shift
);
500 typedef struct MachineStatusInfo
{
506 const char *root_directory
;
508 struct dual_timestamp timestamp
;
513 static void machine_status_info_clear(MachineStatusInfo
*info
) {
520 static void print_machine_status_info(sd_bus
*bus
, MachineStatusInfo
*i
) {
521 _cleanup_free_
char *addresses
= NULL
, *s1
= NULL
, *s2
= NULL
;
527 fputs(strna(i
->name
), stdout
);
529 if (!sd_id128_is_null(i
->id
))
530 printf("(" SD_ID128_FORMAT_STR
")\n", SD_ID128_FORMAT_VAL(i
->id
));
534 s1
= strdup(strempty(FORMAT_TIMESTAMP_RELATIVE(i
->timestamp
.realtime
)));
535 s2
= strdup(strempty(FORMAT_TIMESTAMP(i
->timestamp
.realtime
)));
538 printf("\t Since: %s; %s\n", strna(s2
), s1
);
539 else if (!isempty(s2
))
540 printf("\t Since: %s\n", s2
);
543 _cleanup_free_
char *t
= NULL
;
545 printf("\t Leader: %u", (unsigned) i
->leader
);
547 (void) pid_get_comm(i
->leader
, &t
);
555 printf("\t Service: %s", i
->service
);
558 printf("; class %s", i
->class);
562 printf("\t Class: %s\n", i
->class);
564 if (i
->root_directory
)
565 printf("\t Root: %s\n", i
->root_directory
);
567 if (i
->n_netif
> 0) {
568 fputs("\t Iface:", stdout
);
570 for (size_t c
= 0; c
< i
->n_netif
; c
++) {
571 char name
[IF_NAMESIZE
];
573 if (format_ifname(i
->netif
[c
], name
) >= 0) {
582 printf(" %i", i
->netif
[c
]);
588 if (call_get_addresses(bus
, i
->name
, ifi
,
589 "\t Address: ", "\n\t ",
591 fputs(addresses
, stdout
);
595 print_os_release(bus
, "GetMachineOSRelease", i
->name
, "\t OS: ");
597 print_uid_shift(bus
, i
->name
);
600 printf("\t Unit: %s\n", i
->unit
);
601 show_unit_cgroup(bus
, i
->unit
, i
->leader
);
603 if (arg_transport
== BUS_TRANSPORT_LOCAL
)
605 show_journal_by_unit(
611 i
->timestamp
.monotonic
,
614 get_output_flags() | OUTPUT_BEGIN_NEWLINE
,
615 SD_JOURNAL_LOCAL_ONLY
,
621 static int map_netif(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
622 MachineStatusInfo
*i
= userdata
;
627 assert_cc(sizeof(int32_t) == sizeof(int));
628 r
= sd_bus_message_read_array(m
, SD_BUS_TYPE_INT32
, &v
, &l
);
634 i
->n_netif
= l
/ sizeof(int32_t);
635 i
->netif
= memdup(v
, l
);
642 static int show_machine_info(const char *verb
, sd_bus
*bus
, const char *path
, bool *new_line
) {
644 static const struct bus_properties_map map
[] = {
645 { "Name", "s", NULL
, offsetof(MachineStatusInfo
, name
) },
646 { "Class", "s", NULL
, offsetof(MachineStatusInfo
, class) },
647 { "Service", "s", NULL
, offsetof(MachineStatusInfo
, service
) },
648 { "Unit", "s", NULL
, offsetof(MachineStatusInfo
, unit
) },
649 { "RootDirectory", "s", NULL
, offsetof(MachineStatusInfo
, root_directory
) },
650 { "Leader", "u", NULL
, offsetof(MachineStatusInfo
, leader
) },
651 { "Timestamp", "t", NULL
, offsetof(MachineStatusInfo
, timestamp
.realtime
) },
652 { "TimestampMonotonic", "t", NULL
, offsetof(MachineStatusInfo
, timestamp
.monotonic
) },
653 { "Id", "ay", bus_map_id128
, offsetof(MachineStatusInfo
, id
) },
654 { "NetworkInterfaces", "ai", map_netif
, 0 },
658 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
659 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
660 _cleanup_(machine_status_info_clear
) MachineStatusInfo info
= {};
668 r
= bus_map_all_properties(bus
,
669 "org.freedesktop.machine1",
677 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
683 print_machine_status_info(bus
, &info
);
688 static int show_machine_properties(sd_bus
*bus
, const char *path
, bool *new_line
) {
700 r
= bus_print_all_properties(bus
, "org.freedesktop.machine1", path
, NULL
, arg_property
, arg_print_flags
, NULL
);
702 log_error_errno(r
, "Could not get properties: %m");
707 static int show_machine(int argc
, char *argv
[], void *userdata
) {
708 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
709 bool properties
, new_line
= false;
710 sd_bus
*bus
= ASSERT_PTR(userdata
);
713 properties
= !strstr(argv
[0], "status");
715 pager_open(arg_pager_flags
);
717 if (properties
&& argc
<= 1) {
719 /* If no argument is specified, inspect the manager
721 r
= show_machine_properties(bus
, "/org/freedesktop/machine1", &new_line
);
726 for (int i
= 1; i
< argc
; i
++) {
727 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
728 const char *path
= NULL
;
730 r
= bus_call_method(bus
, bus_machine_mgr
, "GetMachine", &error
, &reply
, "s", argv
[i
]);
732 return log_error_errno(r
, "Could not get path to machine: %s", bus_error_message(&error
, r
));
734 r
= sd_bus_message_read(reply
, "o", &path
);
736 return bus_log_parse_error(r
);
739 r
= show_machine_properties(bus
, path
, &new_line
);
741 r
= show_machine_info(argv
[0], bus
, path
, &new_line
);
747 static int print_image_hostname(sd_bus
*bus
, const char *name
) {
748 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
752 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImageHostname", NULL
, &reply
, "s", name
);
756 r
= sd_bus_message_read(reply
, "s", &hn
);
761 printf("\tHostname: %s\n", hn
);
766 static int print_image_machine_id(sd_bus
*bus
, const char *name
) {
767 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
771 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImageMachineID", NULL
, &reply
, "s", name
);
775 r
= bus_message_read_id128(reply
, &id
);
779 if (!sd_id128_is_null(id
))
780 printf(" Machine ID: " SD_ID128_FORMAT_STR
"\n", SD_ID128_FORMAT_VAL(id
));
785 static int print_image_machine_info(sd_bus
*bus
, const char *name
) {
786 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
789 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImageMachineInfo", NULL
, &reply
, "s", name
);
793 r
= sd_bus_message_enter_container(reply
, 'a', "{ss}");
800 r
= sd_bus_message_read(reply
, "{ss}", &p
, &q
);
806 if (streq(p
, "DEPLOYMENT"))
807 printf(" Deployment: %s\n", q
);
810 r
= sd_bus_message_exit_container(reply
);
817 typedef struct ImageStatusInfo
{
826 uint64_t usage_exclusive
;
827 uint64_t limit_exclusive
;
830 static void print_image_status_info(sd_bus
*bus
, ImageStatusInfo
*i
) {
835 fputs(i
->name
, stdout
);
840 printf("\t Type: %s\n", i
->type
);
843 printf("\t Path: %s\n", i
->path
);
845 (void) print_image_hostname(bus
, i
->name
);
846 (void) print_image_machine_id(bus
, i
->name
);
847 (void) print_image_machine_info(bus
, i
->name
);
849 print_os_release(bus
, "GetImageOSRelease", i
->name
, "\t OS: ");
851 printf("\t RO: %s%s%s\n",
852 i
->read_only
? ansi_highlight_red() : "",
853 i
->read_only
? "read-only" : "writable",
854 i
->read_only
? ansi_normal() : "");
856 if (timestamp_is_set(i
->crtime
))
857 printf("\t Created: %s; %s\n",
858 FORMAT_TIMESTAMP(i
->crtime
), FORMAT_TIMESTAMP_RELATIVE(i
->crtime
));
860 if (timestamp_is_set(i
->mtime
))
861 printf("\tModified: %s; %s\n",
862 FORMAT_TIMESTAMP(i
->mtime
), FORMAT_TIMESTAMP_RELATIVE(i
->mtime
));
864 if (i
->usage
!= UINT64_MAX
) {
865 if (i
->usage_exclusive
!= i
->usage
&& i
->usage_exclusive
!= UINT64_MAX
)
866 printf("\t Usage: %s (exclusive: %s)\n",
867 FORMAT_BYTES(i
->usage
), FORMAT_BYTES(i
->usage_exclusive
));
869 printf("\t Usage: %s\n", FORMAT_BYTES(i
->usage
));
872 if (i
->limit
!= UINT64_MAX
) {
873 if (i
->limit_exclusive
!= i
->limit
&& i
->limit_exclusive
!= UINT64_MAX
)
874 printf("\t Limit: %s (exclusive: %s)\n",
875 FORMAT_BYTES(i
->limit
), FORMAT_BYTES(i
->limit_exclusive
));
877 printf("\t Limit: %s\n", FORMAT_BYTES(i
->limit
));
881 static int show_image_info(sd_bus
*bus
, const char *path
, bool *new_line
) {
883 static const struct bus_properties_map map
[] = {
884 { "Name", "s", NULL
, offsetof(ImageStatusInfo
, name
) },
885 { "Path", "s", NULL
, offsetof(ImageStatusInfo
, path
) },
886 { "Type", "s", NULL
, offsetof(ImageStatusInfo
, type
) },
887 { "ReadOnly", "b", NULL
, offsetof(ImageStatusInfo
, read_only
) },
888 { "CreationTimestamp", "t", NULL
, offsetof(ImageStatusInfo
, crtime
) },
889 { "ModificationTimestamp", "t", NULL
, offsetof(ImageStatusInfo
, mtime
) },
890 { "Usage", "t", NULL
, offsetof(ImageStatusInfo
, usage
) },
891 { "Limit", "t", NULL
, offsetof(ImageStatusInfo
, limit
) },
892 { "UsageExclusive", "t", NULL
, offsetof(ImageStatusInfo
, usage_exclusive
) },
893 { "LimitExclusive", "t", NULL
, offsetof(ImageStatusInfo
, limit_exclusive
) },
897 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
898 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
899 ImageStatusInfo info
= {};
906 r
= bus_map_all_properties(bus
,
907 "org.freedesktop.machine1",
910 BUS_MAP_BOOLEAN_AS_BOOL
,
915 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
921 print_image_status_info(bus
, &info
);
926 typedef struct PoolStatusInfo
{
932 static void print_pool_status_info(sd_bus
*bus
, PoolStatusInfo
*i
) {
934 printf("\t Path: %s\n", i
->path
);
936 if (i
->usage
!= UINT64_MAX
)
937 printf("\t Usage: %s\n", FORMAT_BYTES(i
->usage
));
939 if (i
->limit
!= UINT64_MAX
)
940 printf("\t Limit: %s\n", FORMAT_BYTES(i
->limit
));
943 static int show_pool_info(sd_bus
*bus
) {
945 static const struct bus_properties_map map
[] = {
946 { "PoolPath", "s", NULL
, offsetof(PoolStatusInfo
, path
) },
947 { "PoolUsage", "t", NULL
, offsetof(PoolStatusInfo
, usage
) },
948 { "PoolLimit", "t", NULL
, offsetof(PoolStatusInfo
, limit
) },
952 PoolStatusInfo info
= {
957 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
958 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
963 r
= bus_map_all_properties(bus
,
964 "org.freedesktop.machine1",
965 "/org/freedesktop/machine1",
972 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
974 print_pool_status_info(bus
, &info
);
979 static int show_image_properties(sd_bus
*bus
, const char *path
, bool *new_line
) {
991 r
= bus_print_all_properties(bus
, "org.freedesktop.machine1", path
, NULL
, arg_property
, arg_print_flags
, NULL
);
993 log_error_errno(r
, "Could not get properties: %m");
998 static int show_image(int argc
, char *argv
[], void *userdata
) {
999 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1000 bool properties
, new_line
= false;
1001 sd_bus
*bus
= ASSERT_PTR(userdata
);
1004 properties
= !strstr(argv
[0], "status");
1006 pager_open(arg_pager_flags
);
1010 /* If no argument is specified, inspect the manager
1014 r
= show_image_properties(bus
, "/org/freedesktop/machine1", &new_line
);
1016 r
= show_pool_info(bus
);
1021 for (int i
= 1; i
< argc
; i
++) {
1022 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1023 const char *path
= NULL
;
1025 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImage", &error
, &reply
, "s", argv
[i
]);
1027 return log_error_errno(r
, "Could not get path to image: %s", bus_error_message(&error
, r
));
1029 r
= sd_bus_message_read(reply
, "o", &path
);
1031 return bus_log_parse_error(r
);
1034 r
= show_image_properties(bus
, path
, &new_line
);
1036 r
= show_image_info(bus
, path
, &new_line
);
1042 static int kill_machine(int argc
, char *argv
[], void *userdata
) {
1043 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1044 sd_bus
*bus
= ASSERT_PTR(userdata
);
1047 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1050 arg_kill_whom
= "all";
1052 for (int i
= 1; i
< argc
; i
++) {
1053 r
= bus_call_method(
1059 "ssi", argv
[i
], arg_kill_whom
, arg_signal
);
1061 return log_error_errno(r
, "Could not kill machine: %s", bus_error_message(&error
, r
));
1067 static int reboot_machine(int argc
, char *argv
[], void *userdata
) {
1068 if (arg_runner
== RUNNER_VMSPAWN
)
1069 return log_error_errno(
1070 SYNTHETIC_ERRNO(EOPNOTSUPP
),
1071 "%s only support supported for --runner=nspawn",
1072 streq(argv
[0], "reboot") ? "Reboot" : "Restart");
1074 arg_kill_whom
= "leader";
1075 arg_signal
= SIGINT
; /* sysvinit + systemd */
1077 return kill_machine(argc
, argv
, userdata
);
1080 static int poweroff_machine(int argc
, char *argv
[], void *userdata
) {
1081 arg_kill_whom
= "leader";
1082 arg_signal
= SIGRTMIN
+4; /* only systemd */
1084 return kill_machine(argc
, argv
, userdata
);
1087 static int terminate_machine(int argc
, char *argv
[], void *userdata
) {
1088 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1089 sd_bus
*bus
= ASSERT_PTR(userdata
);
1092 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1094 for (int i
= 1; i
< argc
; i
++) {
1095 r
= bus_call_method(bus
, bus_machine_mgr
, "TerminateMachine", &error
, NULL
, "s", argv
[i
]);
1097 return log_error_errno(r
, "Could not terminate machine: %s", bus_error_message(&error
, r
));
1103 static const char *select_copy_method(bool copy_from
, bool force
) {
1105 return copy_from
? "CopyFromMachineWithFlags" : "CopyToMachineWithFlags";
1107 return copy_from
? "CopyFromMachine" : "CopyToMachine";
1110 static int copy_files(int argc
, char *argv
[], void *userdata
) {
1111 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1112 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1113 _cleanup_free_
char *abs_host_path
= NULL
;
1114 char *dest
, *host_path
, *container_path
;
1115 sd_bus
*bus
= ASSERT_PTR(userdata
);
1119 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1121 copy_from
= streq(argv
[0], "copy-from");
1122 dest
= argv
[3] ?: argv
[2];
1123 host_path
= copy_from
? dest
: argv
[2];
1124 container_path
= copy_from
? argv
[2] : dest
;
1126 if (!path_is_absolute(host_path
)) {
1127 r
= path_make_absolute_cwd(host_path
, &abs_host_path
);
1129 return log_error_errno(r
, "Failed to make path absolute: %m");
1131 host_path
= abs_host_path
;
1134 r
= bus_message_new_method_call(
1138 select_copy_method(copy_from
, arg_force
));
1140 return bus_log_create_error(r
);
1142 r
= sd_bus_message_append(
1146 copy_from
? container_path
: host_path
,
1147 copy_from
? host_path
: container_path
);
1149 return bus_log_create_error(r
);
1152 r
= sd_bus_message_append(m
, "t", (uint64_t) MACHINE_COPY_REPLACE
);
1154 return bus_log_create_error(r
);
1157 /* This is a slow operation, hence turn off any method call timeouts */
1158 r
= sd_bus_call(bus
, m
, USEC_INFINITY
, &error
, NULL
);
1160 return log_error_errno(r
, "Failed to copy: %s", bus_error_message(&error
, r
));
1165 static int bind_mount(int argc
, char *argv
[], void *userdata
) {
1166 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1167 sd_bus
*bus
= ASSERT_PTR(userdata
);
1170 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1172 r
= bus_call_method(
1185 return log_error_errno(r
, "Failed to bind mount: %s", bus_error_message(&error
, r
));
1190 static int on_machine_removed(sd_bus_message
*m
, void *userdata
, sd_bus_error
*ret_error
) {
1191 PTYForward
** forward
= (PTYForward
**) userdata
;
1198 /* If the forwarder is already initialized, tell it to
1199 * exit on the next vhangup(), so that we still flush
1200 * out what might be queued and exit then. */
1202 r
= pty_forward_set_ignore_vhangup(*forward
, false);
1206 log_error_errno(r
, "Failed to set ignore_vhangup flag: %m");
1209 /* On error, or when the forwarder is not initialized yet, quit immediately */
1210 sd_event_exit(sd_bus_get_event(sd_bus_message_get_bus(m
)), EXIT_FAILURE
);
1214 static int process_forward(sd_event
*event
, PTYForward
**forward
, int master
, PTYForwardFlags flags
, const char *name
) {
1220 assert(master
>= 0);
1223 assert_se(sigprocmask_many(SIG_BLOCK
, NULL
, SIGWINCH
, SIGTERM
, SIGINT
) >= 0);
1226 if (streq(name
, ".host"))
1227 log_info("Connected to the local host. Press ^] three times within 1s to exit session.");
1229 log_info("Connected to machine %s. Press ^] three times within 1s to exit session.", name
);
1232 (void) sd_event_add_signal(event
, NULL
, SIGINT
, NULL
, NULL
);
1233 (void) sd_event_add_signal(event
, NULL
, SIGTERM
, NULL
, NULL
);
1235 r
= pty_forward_new(event
, master
, flags
, forward
);
1237 return log_error_errno(r
, "Failed to create PTY forwarder: %m");
1239 r
= sd_event_loop(event
);
1241 return log_error_errno(r
, "Failed to run event loop: %m");
1243 pty_forward_get_last_char(*forward
, &last_char
);
1246 (flags
& PTY_FORWARD_IGNORE_VHANGUP
) &&
1247 pty_forward_get_ignore_vhangup(*forward
) == 0;
1249 *forward
= pty_forward_free(*forward
);
1251 if (last_char
!= '\n')
1252 fputc('\n', stdout
);
1256 log_info("Machine %s terminated.", name
);
1257 else if (streq(name
, ".host"))
1258 log_info("Connection to the local host terminated.");
1260 log_info("Connection to machine %s terminated.", name
);
1266 static int parse_machine_uid(const char *spec
, const char **machine
, char **uid
) {
1268 * Whatever is specified in the spec takes priority over global arguments.
1271 const char *_machine
= NULL
;
1276 at
= strchr(spec
, '@');
1279 /* Do the same as ssh and refuse "@host". */
1283 _uid
= strndup(spec
, at
- spec
);
1290 if (arg_uid
&& !_uid
) {
1291 _uid
= strdup(arg_uid
);
1297 *machine
= isempty(_machine
) ? ".host" : _machine
;
1301 static int login_machine(int argc
, char *argv
[], void *userdata
) {
1302 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1303 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1304 _cleanup_(pty_forward_freep
) PTYForward
*forward
= NULL
;
1305 _cleanup_(sd_bus_slot_unrefp
) sd_bus_slot
*slot
= NULL
;
1306 _cleanup_(sd_event_unrefp
) sd_event
*event
= NULL
;
1308 sd_bus
*bus
= ASSERT_PTR(userdata
);
1309 const char *match
, *machine
;
1311 if (!strv_isempty(arg_setenv
) || arg_uid
)
1312 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1313 "--setenv= and --uid= are not supported for 'login'. Use 'shell' instead.");
1315 if (!IN_SET(arg_transport
, BUS_TRANSPORT_LOCAL
, BUS_TRANSPORT_MACHINE
))
1316 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1317 "Login only supported on local machines.");
1319 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1321 r
= sd_event_default(&event
);
1323 return log_error_errno(r
, "Failed to get event loop: %m");
1325 r
= sd_bus_attach_event(bus
, event
, 0);
1327 return log_error_errno(r
, "Failed to attach bus to event loop: %m");
1329 machine
= argc
< 2 || isempty(argv
[1]) ? ".host" : argv
[1];
1331 match
= strjoina("type='signal',"
1332 "sender='org.freedesktop.machine1',"
1333 "path='/org/freedesktop/machine1',",
1334 "interface='org.freedesktop.machine1.Manager',"
1335 "member='MachineRemoved',"
1336 "arg0='", machine
, "'");
1338 r
= sd_bus_add_match_async(bus
, &slot
, match
, on_machine_removed
, NULL
, &forward
);
1340 return log_error_errno(r
, "Failed to request machine removal match: %m");
1342 r
= bus_call_method(bus
, bus_machine_mgr
, "OpenMachineLogin", &error
, &reply
, "s", machine
);
1344 return log_error_errno(r
, "Failed to get login PTY: %s", bus_error_message(&error
, r
));
1346 r
= sd_bus_message_read(reply
, "hs", &master
, NULL
);
1348 return bus_log_parse_error(r
);
1350 return process_forward(event
, &forward
, master
, PTY_FORWARD_IGNORE_VHANGUP
, machine
);
1353 static int shell_machine(int argc
, char *argv
[], void *userdata
) {
1354 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
, *m
= NULL
;
1355 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1356 _cleanup_(pty_forward_freep
) PTYForward
*forward
= NULL
;
1357 _cleanup_(sd_bus_slot_unrefp
) sd_bus_slot
*slot
= NULL
;
1358 _cleanup_(sd_event_unrefp
) sd_event
*event
= NULL
;
1360 sd_bus
*bus
= ASSERT_PTR(userdata
);
1361 const char *match
, *machine
, *path
;
1362 _cleanup_free_
char *uid
= NULL
;
1364 if (!IN_SET(arg_transport
, BUS_TRANSPORT_LOCAL
, BUS_TRANSPORT_MACHINE
))
1365 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1366 "Shell only supported on local machines.");
1368 /* Pass $TERM to shell session, if not explicitly specified. */
1369 if (!strv_find_prefix(arg_setenv
, "TERM=")) {
1372 t
= strv_find_prefix(environ
, "TERM=");
1374 if (strv_extend(&arg_setenv
, t
) < 0)
1379 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1381 r
= sd_event_default(&event
);
1383 return log_error_errno(r
, "Failed to get event loop: %m");
1385 r
= sd_bus_attach_event(bus
, event
, 0);
1387 return log_error_errno(r
, "Failed to attach bus to event loop: %m");
1389 r
= parse_machine_uid(argc
>= 2 ? argv
[1] : NULL
, &machine
, &uid
);
1391 return log_error_errno(r
, "Failed to parse machine specification: %m");
1393 match
= strjoina("type='signal',"
1394 "sender='org.freedesktop.machine1',"
1395 "path='/org/freedesktop/machine1',",
1396 "interface='org.freedesktop.machine1.Manager',"
1397 "member='MachineRemoved',"
1398 "arg0='", machine
, "'");
1400 r
= sd_bus_add_match_async(bus
, &slot
, match
, on_machine_removed
, NULL
, &forward
);
1402 return log_error_errno(r
, "Failed to request machine removal match: %m");
1404 r
= bus_message_new_method_call(bus
, &m
, bus_machine_mgr
, "OpenMachineShell");
1406 return bus_log_create_error(r
);
1408 path
= argc
< 3 || isempty(argv
[2]) ? NULL
: argv
[2];
1410 r
= sd_bus_message_append(m
, "sss", machine
, uid
, path
);
1412 return bus_log_create_error(r
);
1414 r
= sd_bus_message_append_strv(m
, strv_length(argv
) <= 3 ? NULL
: argv
+ 2);
1416 return bus_log_create_error(r
);
1418 r
= sd_bus_message_append_strv(m
, arg_setenv
);
1420 return bus_log_create_error(r
);
1422 r
= sd_bus_call(bus
, m
, 0, &error
, &reply
);
1424 return log_error_errno(r
, "Failed to get shell PTY: %s", bus_error_message(&error
, r
));
1426 r
= sd_bus_message_read(reply
, "hs", &master
, NULL
);
1428 return bus_log_parse_error(r
);
1430 return process_forward(event
, &forward
, master
, 0, machine
);
1433 static int normalize_nspawn_filename(const char *name
, char **ret_file
) {
1434 _cleanup_free_
char *file
= NULL
;
1439 if (!endswith(name
, ".nspawn"))
1440 file
= strjoin(name
, ".nspawn");
1442 file
= strdup(name
);
1446 if (!filename_is_valid(file
))
1447 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Invalid settings file name '%s'.", file
);
1449 *ret_file
= TAKE_PTR(file
);
1453 static int get_settings_path(const char *name
, char **ret_path
) {
1457 FOREACH_STRING(i
, "/etc/systemd/nspawn", "/run/systemd/nspawn", "/var/lib/machines") {
1458 _cleanup_free_
char *path
= NULL
;
1460 path
= path_join(i
, name
);
1464 if (access(path
, F_OK
) >= 0) {
1465 *ret_path
= TAKE_PTR(path
);
1473 static int edit_settings(int argc
, char *argv
[], void *userdata
) {
1474 _cleanup_(edit_file_context_done
) EditFileContext context
= {};
1478 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Cannot edit machine settings if not on a tty.");
1480 if (arg_transport
!= BUS_TRANSPORT_LOCAL
)
1481 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1482 "Edit is only supported on the host machine.");
1484 if (arg_runner
== RUNNER_VMSPAWN
)
1485 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
), "Edit is only supported for --runner=nspawn");
1491 STRV_FOREACH(name
, strv_skip(argv
, 1)) {
1492 _cleanup_free_
char *file
= NULL
, *path
= NULL
;
1494 if (path_is_absolute(*name
)) {
1495 if (!path_is_safe(*name
))
1496 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1497 "Invalid settings file path '%s'.",
1500 r
= edit_files_add(&context
, *name
, NULL
, NULL
);
1506 r
= normalize_nspawn_filename(*name
, &file
);
1510 r
= get_settings_path(file
, &path
);
1512 log_debug("No existing settings file for machine '%s' found, creating a new file.", *name
);
1514 path
= path_join("/etc/systemd/nspawn", file
);
1518 r
= edit_files_add(&context
, path
, NULL
, NULL
);
1524 return log_error_errno(r
, "Failed to get the path of the settings file: %m");
1526 if (path_startswith(path
, "/var/lib/machines")) {
1527 _cleanup_free_
char *new_path
= NULL
;
1529 new_path
= path_join("/etc/systemd/nspawn", file
);
1533 r
= edit_files_add(&context
, new_path
, path
, NULL
);
1535 r
= edit_files_add(&context
, path
, NULL
, NULL
);
1540 return do_edit_files_and_install(&context
);
1543 static int cat_settings(int argc
, char *argv
[], void *userdata
) {
1546 if (arg_transport
!= BUS_TRANSPORT_LOCAL
)
1547 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
),
1548 "Cat is only supported on the host machine.");
1550 if (arg_runner
== RUNNER_VMSPAWN
)
1551 return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP
), "Cat is only supported for --runner=nspawn");
1553 pager_open(arg_pager_flags
);
1555 STRV_FOREACH(name
, strv_skip(argv
, 1)) {
1556 _cleanup_free_
char *file
= NULL
, *path
= NULL
;
1559 if (path_is_absolute(*name
)) {
1560 if (!path_is_safe(*name
))
1561 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1562 "Invalid settings file path '%s'.",
1565 q
= cat_files(*name
, /* dropins = */ NULL
, /* flags = */ CAT_FORMAT_HAS_SECTIONS
);
1567 return r
< 0 ? r
: q
;
1571 q
= normalize_nspawn_filename(*name
, &file
);
1573 return r
< 0 ? r
: q
;
1575 q
= get_settings_path(file
, &path
);
1577 log_error_errno(q
, "No settings file found for machine '%s'.", *name
);
1582 log_error_errno(q
, "Failed to get the path of the settings file: %m");
1583 return r
< 0 ? r
: q
;
1586 q
= cat_files(path
, /* dropins = */ NULL
, /* flags = */ CAT_FORMAT_HAS_SECTIONS
);
1588 return r
< 0 ? r
: q
;
1594 static int remove_image(int argc
, char *argv
[], void *userdata
) {
1595 sd_bus
*bus
= ASSERT_PTR(userdata
);
1598 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1600 for (int i
= 1; i
< argc
; i
++) {
1601 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1602 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1604 r
= bus_message_new_method_call(bus
, &m
, bus_machine_mgr
, "RemoveImage");
1606 return bus_log_create_error(r
);
1608 r
= sd_bus_message_append(m
, "s", argv
[i
]);
1610 return bus_log_create_error(r
);
1612 /* This is a slow operation, hence turn off any method call timeouts */
1613 r
= sd_bus_call(bus
, m
, USEC_INFINITY
, &error
, NULL
);
1615 return log_error_errno(r
, "Could not remove image: %s", bus_error_message(&error
, r
));
1621 static int rename_image(int argc
, char *argv
[], void *userdata
) {
1622 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1623 sd_bus
*bus
= ASSERT_PTR(userdata
);
1626 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1628 r
= bus_call_method(
1634 "ss", argv
[1], argv
[2]);
1636 return log_error_errno(r
, "Could not rename image: %s", bus_error_message(&error
, r
));
1641 static int clone_image(int argc
, char *argv
[], void *userdata
) {
1642 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1643 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
1644 sd_bus
*bus
= ASSERT_PTR(userdata
);
1647 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1649 r
= bus_message_new_method_call(bus
, &m
, bus_machine_mgr
, "CloneImage");
1651 return bus_log_create_error(r
);
1653 r
= sd_bus_message_append(m
, "ssb", argv
[1], argv
[2], arg_read_only
);
1655 return bus_log_create_error(r
);
1657 /* This is a slow operation, hence turn off any method call timeouts */
1658 r
= sd_bus_call(bus
, m
, USEC_INFINITY
, &error
, NULL
);
1660 return log_error_errno(r
, "Could not clone image: %s", bus_error_message(&error
, r
));
1665 static int read_only_image(int argc
, char *argv
[], void *userdata
) {
1666 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1667 sd_bus
*bus
= ASSERT_PTR(userdata
);
1671 b
= parse_boolean(argv
[2]);
1673 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1674 "Failed to parse boolean argument: %s",
1678 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1680 r
= bus_call_method(bus
, bus_machine_mgr
, "MarkImageReadOnly", &error
, NULL
, "sb", argv
[1], b
);
1682 return log_error_errno(r
, "Could not mark image read-only: %s", bus_error_message(&error
, r
));
1687 static int image_exists(sd_bus
*bus
, const char *name
) {
1688 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1694 r
= bus_call_method(bus
, bus_machine_mgr
, "GetImage", &error
, NULL
, "s", name
);
1696 if (sd_bus_error_has_name(&error
, BUS_ERROR_NO_SUCH_IMAGE
))
1699 return log_error_errno(r
, "Failed to check whether image %s exists: %s", name
, bus_error_message(&error
, r
));
1705 static int make_service_name(const char *name
, char **ret
) {
1710 assert(arg_runner
>= 0 && arg_runner
< (MachineRunner
) ELEMENTSOF(machine_runner_unit_prefix_table
));
1712 if (!hostname_is_valid(name
, 0))
1713 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1714 "Invalid machine name %s.", name
);
1716 r
= unit_name_build(machine_runner_unit_prefix_table
[arg_runner
], name
, ".service", ret
);
1718 return log_error_errno(r
, "Failed to build unit name: %m");
1723 static int start_machine(int argc
, char *argv
[], void *userdata
) {
1724 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1725 _cleanup_(bus_wait_for_jobs_freep
) BusWaitForJobs
*w
= NULL
;
1726 sd_bus
*bus
= ASSERT_PTR(userdata
);
1729 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1730 ask_password_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1732 r
= bus_wait_for_jobs_new(bus
, &w
);
1734 return log_error_errno(r
, "Could not watch jobs: %m");
1736 for (int i
= 1; i
< argc
; i
++) {
1737 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1738 _cleanup_free_
char *unit
= NULL
;
1741 r
= make_service_name(argv
[i
], &unit
);
1745 r
= image_exists(bus
, argv
[i
]);
1749 return log_error_errno(SYNTHETIC_ERRNO(ENXIO
),
1750 "Machine image '%s' does not exist.",
1753 r
= bus_call_method(
1759 "ss", unit
, "fail");
1761 return log_error_errno(r
, "Failed to start unit: %s", bus_error_message(&error
, r
));
1763 r
= sd_bus_message_read(reply
, "o", &object
);
1765 return bus_log_parse_error(r
);
1767 r
= bus_wait_for_jobs_add(w
, object
);
1772 r
= bus_wait_for_jobs(w
, arg_quiet
, NULL
);
1779 static int enable_machine(int argc
, char *argv
[], void *userdata
) {
1780 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
, *reply
= NULL
;
1781 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1783 sd_bus
*bus
= ASSERT_PTR(userdata
);
1787 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1789 enable
= streq(argv
[0], "enable");
1790 method
= enable
? "EnableUnitFiles" : "DisableUnitFiles";
1792 r
= bus_message_new_method_call(bus
, &m
, bus_systemd_mgr
, method
);
1794 return bus_log_create_error(r
);
1796 r
= sd_bus_message_open_container(m
, 'a', "s");
1798 return bus_log_create_error(r
);
1801 r
= sd_bus_message_append(m
, "s", "machines.target");
1803 return bus_log_create_error(r
);
1806 for (int i
= 1; i
< argc
; i
++) {
1807 _cleanup_free_
char *unit
= NULL
;
1809 r
= make_service_name(argv
[i
], &unit
);
1813 r
= image_exists(bus
, argv
[i
]);
1817 return log_error_errno(SYNTHETIC_ERRNO(ENXIO
),
1818 "Machine image '%s' does not exist.",
1821 r
= sd_bus_message_append(m
, "s", unit
);
1823 return bus_log_create_error(r
);
1826 r
= sd_bus_message_close_container(m
);
1828 return bus_log_create_error(r
);
1831 r
= sd_bus_message_append(m
, "bb", false, false);
1833 r
= sd_bus_message_append(m
, "b", false);
1835 return bus_log_create_error(r
);
1837 r
= sd_bus_call(bus
, m
, 0, &error
, &reply
);
1839 return log_error_errno(r
, "Failed to enable or disable unit: %s", bus_error_message(&error
, r
));
1842 r
= sd_bus_message_read(reply
, "b", NULL
);
1844 return bus_log_parse_error(r
);
1847 r
= bus_deserialize_and_dump_unit_file_changes(reply
, arg_quiet
);
1851 r
= bus_service_manager_reload(bus
);
1856 _cleanup_strv_free_
char **new_args
= NULL
;
1858 new_args
= strv_new(enable
? "start" : "poweroff");
1862 r
= strv_extend_strv(&new_args
, argv
+ 1, /* filter_duplicates = */ false);
1867 return start_machine(strv_length(new_args
), new_args
, userdata
);
1869 return poweroff_machine(strv_length(new_args
), new_args
, userdata
);
1875 static int set_limit(int argc
, char *argv
[], void *userdata
) {
1876 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1877 sd_bus
*bus
= userdata
;
1881 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1883 if (STR_IN_SET(argv
[argc
-1], "-", "none", "infinity"))
1886 r
= parse_size(argv
[argc
-1], 1024, &limit
);
1888 return log_error_errno(r
, "Failed to parse size: %s", argv
[argc
-1]);
1892 /* With two arguments changes the quota limit of the
1893 * specified image */
1894 r
= bus_call_method(bus
, bus_machine_mgr
, "SetImageLimit", &error
, NULL
, "st", argv
[1], limit
);
1896 /* With one argument changes the pool quota limit */
1897 r
= bus_call_method(bus
, bus_machine_mgr
, "SetPoolLimit", &error
, NULL
, "t", limit
);
1900 return log_error_errno(r
, "Could not set limit: %s", bus_error_message(&error
, r
));
1905 static int clean_images(int argc
, char *argv
[], void *userdata
) {
1906 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
, *reply
= NULL
;
1907 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1908 uint64_t usage
, total
= 0;
1909 sd_bus
*bus
= userdata
;
1914 polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1916 r
= bus_message_new_method_call(bus
, &m
, bus_machine_mgr
, "CleanPool");
1918 return bus_log_create_error(r
);
1920 r
= sd_bus_message_append(m
, "s", arg_all
? "all" : "hidden");
1922 return bus_log_create_error(r
);
1924 /* This is a slow operation, hence permit a longer time for completion. */
1925 r
= sd_bus_call(bus
, m
, USEC_INFINITY
, &error
, &reply
);
1927 return log_error_errno(r
, "Could not clean pool: %s", bus_error_message(&error
, r
));
1929 r
= sd_bus_message_enter_container(reply
, 'a', "(st)");
1931 return bus_log_parse_error(r
);
1933 while ((r
= sd_bus_message_read(reply
, "(st)", &name
, &usage
)) > 0) {
1934 if (usage
== UINT64_MAX
) {
1935 log_info("Removed image '%s'", name
);
1938 log_info("Removed image '%s'. Freed exclusive disk space: %s",
1939 name
, FORMAT_BYTES(usage
));
1940 if (total
!= UINT64_MAX
)
1946 r
= sd_bus_message_exit_container(reply
);
1948 return bus_log_parse_error(r
);
1950 if (total
== UINT64_MAX
)
1951 log_info("Removed %u images in total.", c
);
1953 log_info("Removed %u images in total. Total freed exclusive disk space: %s.",
1954 c
, FORMAT_BYTES(total
));
1959 static int chainload_importctl(int argc
, char *argv
[]) {
1962 log_notice("The 'machinectl %1$s' command has been replaced by 'importctl -m %1$s'. Redirecting invocation.", argv
[optind
]);
1964 _cleanup_strv_free_
char **c
=
1965 strv_new("importctl", "--class=machine");
1969 if (FLAGS_SET(arg_pager_flags
, PAGER_DISABLE
))
1970 if (strv_extend(&c
, "--no-pager") < 0)
1973 if (strv_extend(&c
, "--no-legend") < 0)
1976 if (strv_extend(&c
, "--read-only") < 0)
1979 if (strv_extend(&c
, "--force") < 0)
1982 if (strv_extend(&c
, "--quiet") < 0)
1984 if (!arg_ask_password
)
1985 if (strv_extend(&c
, "--no-ask-password") < 0)
1987 if (strv_extend_many(&c
, "--verify", import_verify_to_string(arg_verify
)) < 0)
1990 if (strv_extend_many(&c
, "--format", arg_format
) < 0)
1993 if (strv_extend_strv(&c
, argv
+ optind
, /* filter_duplicates= */ false) < 0)
1996 if (DEBUG_LOGGING
) {
1997 _cleanup_free_
char *joined
= strv_join(c
, " ");
1998 log_debug("Chainloading: %s", joined
);
2001 r
= invoke_callout_binary(BINDIR
"/importctl", c
);
2002 return log_error_errno(r
, "Failed to invoke 'importctl': %m");
2005 static int help(int argc
, char *argv
[], void *userdata
) {
2006 _cleanup_free_
char *link
= NULL
;
2009 pager_open(arg_pager_flags
);
2011 r
= terminal_urlify_man("machinectl", "1", &link
);
2015 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
2016 "%5$sSend control commands to or query the virtual machine and container%6$s\n"
2017 "%5$sregistration manager.%6$s\n"
2018 "\n%3$sMachine Commands:%4$s\n"
2019 " list List running VMs and containers\n"
2020 " status NAME... Show VM/container details\n"
2021 " show [NAME...] Show properties of one or more VMs/containers\n"
2022 " start NAME... Start container as a service\n"
2023 " login [NAME] Get a login prompt in a container or on the\n"
2025 " shell [[USER@]NAME [COMMAND...]]\n"
2026 " Invoke a shell (or other command) in a container\n"
2027 " or on the local host\n"
2028 " enable NAME... Enable automatic container start at boot\n"
2029 " disable NAME... Disable automatic container start at boot\n"
2030 " poweroff NAME... Power off one or more containers\n"
2031 " reboot NAME... Reboot one or more containers\n"
2032 " terminate NAME... Terminate one or more VMs/containers\n"
2033 " kill NAME... Send signal to processes of a VM/container\n"
2034 " copy-to NAME PATH [PATH] Copy files from the host to a container\n"
2035 " copy-from NAME PATH [PATH] Copy files from a container to the host\n"
2036 " bind NAME PATH [PATH] Bind mount a path from the host into a container\n"
2037 "\n%3$sImage Commands:%4$s\n"
2038 " list-images Show available container and VM images\n"
2039 " image-status [NAME...] Show image details\n"
2040 " show-image [NAME...] Show properties of image\n"
2041 " edit NAME|FILE... Edit settings of one or more VMs/containers\n"
2042 " cat NAME|FILE... Show settings of one or more VMs/containers\n"
2043 " clone NAME NAME Clone an image\n"
2044 " rename NAME NAME Rename an image\n"
2045 " read-only NAME [BOOL] Mark or unmark image read-only\n"
2046 " remove NAME... Remove an image\n"
2047 " set-limit [NAME] BYTES Set image or pool size limit (disk quota)\n"
2048 " clean Remove hidden (or all) images\n"
2049 "\n%3$sOptions:%4$s\n"
2050 " -h --help Show this help\n"
2051 " --version Show package version\n"
2052 " --no-pager Do not pipe output into a pager\n"
2053 " --no-legend Do not show the headers and footers\n"
2054 " --no-ask-password Do not ask for system passwords\n"
2055 " -H --host=[USER@]HOST Operate on remote host\n"
2056 " -M --machine=CONTAINER Operate on local container\n"
2057 " -p --property=NAME Show only properties by this name\n"
2058 " --value When showing properties, only print the value\n"
2059 " -P NAME Equivalent to --value --property=NAME\n"
2060 " -q --quiet Suppress output\n"
2061 " -a --all Show all properties, including empty ones\n"
2062 " -l --full Do not ellipsize output\n"
2063 " --kill-whom=WHOM Whom to send signal to\n"
2064 " -s --signal=SIGNAL Which signal to send\n"
2065 " --uid=USER Specify user ID to invoke shell as\n"
2066 " -E --setenv=VAR[=VALUE] Add an environment variable for shell\n"
2067 " --read-only Create read-only bind mount or clone\n"
2068 " --mkdir Create directory before bind mounting, if missing\n"
2069 " -n --lines=INTEGER Number of journal entries to show\n"
2070 " --max-addresses=INTEGER Number of internet addresses to show at most\n"
2071 " -o --output=STRING Change journal output mode (short, short-precise,\n"
2072 " short-iso, short-iso-precise, short-full,\n"
2073 " short-monotonic, short-unix, short-delta,\n"
2074 " json, json-pretty, json-sse, json-seq, cat,\n"
2075 " verbose, export, with-unit)\n"
2076 " --force Replace target file when copying, if necessary\n"
2077 " --now Start or power off container after enabling or\n"
2079 " --runner=RUNNER Select between nspawn and vmspawn as the runner\n"
2080 " -V Short for --runner=vmspawn\n"
2081 "\nSee the %2$s for details.\n",
2082 program_invocation_short_name
,
2092 static int parse_argv(int argc
, char *argv
[]) {
2095 ARG_VERSION
= 0x100,
2102 ARG_NO_ASK_PASSWORD
,
2112 static const struct option options
[] = {
2113 { "help", no_argument
, NULL
, 'h' },
2114 { "version", no_argument
, NULL
, ARG_VERSION
},
2115 { "property", required_argument
, NULL
, 'p' },
2116 { "value", no_argument
, NULL
, ARG_VALUE
},
2117 { "all", no_argument
, NULL
, 'a' },
2118 { "full", no_argument
, NULL
, 'l' },
2119 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
2120 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
},
2121 { "kill-whom", required_argument
, NULL
, ARG_KILL_WHOM
},
2122 { "signal", required_argument
, NULL
, 's' },
2123 { "host", required_argument
, NULL
, 'H' },
2124 { "machine", required_argument
, NULL
, 'M' },
2125 { "read-only", no_argument
, NULL
, ARG_READ_ONLY
},
2126 { "mkdir", no_argument
, NULL
, ARG_MKDIR
},
2127 { "quiet", no_argument
, NULL
, 'q' },
2128 { "lines", required_argument
, NULL
, 'n' },
2129 { "output", required_argument
, NULL
, 'o' },
2130 { "no-ask-password", no_argument
, NULL
, ARG_NO_ASK_PASSWORD
},
2131 { "verify", required_argument
, NULL
, ARG_VERIFY
},
2132 { "runner", required_argument
, NULL
, ARG_RUNNER
},
2133 { "now", no_argument
, NULL
, ARG_NOW
},
2134 { "force", no_argument
, NULL
, ARG_FORCE
},
2135 { "format", required_argument
, NULL
, ARG_FORMAT
},
2136 { "uid", required_argument
, NULL
, ARG_UID
},
2137 { "setenv", required_argument
, NULL
, 'E' },
2138 { "max-addresses", required_argument
, NULL
, ARG_MAX_ADDRESSES
},
2142 bool reorder
= false;
2143 int c
, r
, shell
= -1;
2148 /* Resetting to 0 forces the invocation of an internal initialization routine of getopt_long()
2149 * that checks for GNU extensions in optstring ('-' or '+' at the beginning). */
2153 static const char option_string
[] = "-hp:P:als:H:M:qn:o:E:V";
2155 c
= getopt_long(argc
, argv
, option_string
+ reorder
, options
, NULL
);
2161 case 1: /* getopt_long() returns 1 if "-" was the first character of the option string, and a
2162 * non-option argument was discovered. */
2166 /* We generally are fine with the fact that getopt_long() reorders the command line, and looks
2167 * for switches after the main verb. However, for "shell" we really don't want that, since we
2168 * want that switches specified after the machine name are passed to the program to execute,
2169 * and not processed by us. To make this possible, we'll first invoke getopt_long() with
2170 * reordering disabled (i.e. with the "-" prefix in the option string), looking for the first
2171 * non-option parameter. If it's the verb "shell" we remember its position and continue
2172 * processing options. In this case, as soon as we hit the next non-option argument we found
2173 * the machine name, and stop further processing. If the first non-option argument is any other
2174 * verb than "shell" we switch to normal reordering mode and continue processing arguments
2178 /* If we already found the "shell" verb on the command line, and now found the next
2179 * non-option argument, then this is the machine name and we should stop processing
2180 * further arguments. */
2181 optind
--; /* don't process this argument, go one step back */
2184 if (streq(optarg
, "shell"))
2185 /* Remember the position of the "shell" verb, and continue processing normally. */
2190 /* OK, this is some other verb. In this case, turn on reordering again, and continue
2191 * processing normally. */
2194 /* We changed the option string. getopt_long() only looks at it again if we invoke it
2195 * at least once with a reset option index. Hence, let's reset the option index here,
2196 * then invoke getopt_long() again (ignoring what it has to say, after all we most
2197 * likely already processed it), and the bump the option index so that we read the
2198 * intended argument again. */
2199 saved_optind
= optind
;
2201 (void) getopt_long(argc
, argv
, option_string
+ reorder
, options
, NULL
);
2202 optind
= saved_optind
- 1; /* go one step back, process this argument again */
2208 return help(0, NULL
, NULL
);
2215 r
= strv_extend(&arg_property
, optarg
);
2219 /* If the user asked for a particular property, show it to them, even if empty. */
2220 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
, true);
2227 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_ONLY_VALUE
, true);
2231 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
, true);
2240 if (safe_atou(optarg
, &arg_lines
) < 0)
2241 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
2242 "Failed to parse lines '%s'", optarg
);
2246 if (streq(optarg
, "help")) {
2247 DUMP_STRING_TABLE(output_mode
, OutputMode
, _OUTPUT_MODE_MAX
);
2251 r
= output_mode_from_string(optarg
);
2253 return log_error_errno(r
, "Unknown output '%s'.", optarg
);
2256 if (OUTPUT_MODE_IS_JSON(arg_output
))
2261 arg_pager_flags
|= PAGER_DISABLE
;
2269 arg_kill_whom
= optarg
;
2273 r
= parse_signal_argument(optarg
, &arg_signal
);
2278 case ARG_NO_ASK_PASSWORD
:
2279 arg_ask_password
= false;
2283 arg_transport
= BUS_TRANSPORT_REMOTE
;
2288 arg_transport
= BUS_TRANSPORT_MACHINE
;
2293 arg_read_only
= true;
2305 if (streq(optarg
, "help")) {
2306 DUMP_STRING_TABLE(import_verify
, ImportVerify
, _IMPORT_VERIFY_MAX
);
2310 r
= import_verify_from_string(optarg
);
2312 return log_error_errno(r
, "Failed to parse --verify= setting: %s", optarg
);
2317 arg_runner
= RUNNER_VMSPAWN
;
2321 r
= machine_runner_from_string(optarg
);
2323 return log_error_errno(r
, "Failed to parse --runner= setting: %s", optarg
);
2337 if (!STR_IN_SET(optarg
, "uncompressed", "xz", "gzip", "bzip2"))
2338 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
2339 "Unknown format: %s", optarg
);
2341 arg_format
= optarg
;
2349 r
= strv_env_replace_strdup_passthrough(&arg_setenv
, optarg
);
2351 return log_error_errno(r
, "Cannot assign environment variable %s: %m", optarg
);
2354 case ARG_MAX_ADDRESSES
:
2355 if (streq(optarg
, "all"))
2356 arg_max_addresses
= UINT_MAX
;
2357 else if (safe_atou(optarg
, &arg_max_addresses
) < 0)
2358 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
2359 "Invalid number of addresses: %s", optarg
);
2366 assert_not_reached();
2374 /* We found the "shell" verb while processing the argument list. Since we turned off reordering of the
2375 * argument list initially let's readjust it now, and move the "shell" verb to the back. */
2377 optind
-= 1; /* place the option index where the "shell" verb will be placed */
2380 for (int i
= shell
; i
< optind
; i
++)
2381 argv
[i
] = argv
[i
+1];
2388 static int machinectl_main(int argc
, char *argv
[], sd_bus
*bus
) {
2390 static const Verb verbs
[] = {
2391 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
2392 { "list", VERB_ANY
, 1, VERB_DEFAULT
, list_machines
},
2393 { "list-images", VERB_ANY
, 1, 0, list_images
},
2394 { "status", 2, VERB_ANY
, 0, show_machine
},
2395 { "image-status", VERB_ANY
, VERB_ANY
, 0, show_image
},
2396 { "show", VERB_ANY
, VERB_ANY
, 0, show_machine
},
2397 { "show-image", VERB_ANY
, VERB_ANY
, 0, show_image
},
2398 { "terminate", 2, VERB_ANY
, 0, terminate_machine
},
2399 { "reboot", 2, VERB_ANY
, 0, reboot_machine
},
2400 { "restart", 2, VERB_ANY
, 0, reboot_machine
}, /* Convenience alias */
2401 { "poweroff", 2, VERB_ANY
, 0, poweroff_machine
},
2402 { "stop", 2, VERB_ANY
, 0, poweroff_machine
}, /* Convenience alias */
2403 { "kill", 2, VERB_ANY
, 0, kill_machine
},
2404 { "login", VERB_ANY
, 2, 0, login_machine
},
2405 { "shell", VERB_ANY
, VERB_ANY
, 0, shell_machine
},
2406 { "bind", 3, 4, 0, bind_mount
},
2407 { "edit", 2, VERB_ANY
, 0, edit_settings
},
2408 { "cat", 2, VERB_ANY
, 0, cat_settings
},
2409 { "copy-to", 3, 4, 0, copy_files
},
2410 { "copy-from", 3, 4, 0, copy_files
},
2411 { "remove", 2, VERB_ANY
, 0, remove_image
},
2412 { "rename", 3, 3, 0, rename_image
},
2413 { "clone", 3, 3, 0, clone_image
},
2414 { "read-only", 2, 3, 0, read_only_image
},
2415 { "start", 2, VERB_ANY
, 0, start_machine
},
2416 { "enable", 2, VERB_ANY
, 0, enable_machine
},
2417 { "disable", 2, VERB_ANY
, 0, enable_machine
},
2418 { "set-limit", 2, 3, 0, set_limit
},
2419 { "clean", VERB_ANY
, 1, 0, clean_images
},
2423 return dispatch_verb(argc
, argv
, verbs
, bus
);
2426 static int run(int argc
, char *argv
[]) {
2427 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
2430 setlocale(LC_ALL
, "");
2433 /* The journal merging logic potentially needs a lot of fds. */
2434 (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE
);
2437 r
= parse_argv(argc
, argv
);
2441 if (STRPTR_IN_SET(argv
[optind
],
2442 "import-tar", "import-raw", "import-fs",
2443 "export-tar", "export-raw",
2444 "pull-tar", "pull-raw",
2445 "list-transfers", "cancel-transfer"))
2446 return chainload_importctl(argc
, argv
);
2448 r
= bus_connect_transport(arg_transport
, arg_host
, RUNTIME_SCOPE_SYSTEM
, &bus
);
2450 return bus_log_connect_error(r
, arg_transport
);
2452 (void) sd_bus_set_allow_interactive_authorization(bus
, arg_ask_password
);
2454 return machinectl_main(argc
, argv
, bus
);
2457 DEFINE_MAIN_FUNCTION(run
);