summaryrefslogtreecommitdiffstats
path: root/src/machine/machinectl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/machine/machinectl.c')
-rw-r--r--src/machine/machinectl.c96
1 files changed, 24 insertions, 72 deletions
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index 921af58c94..d05b4101cc 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -264,11 +264,9 @@ static int list_machines(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(table_unrefp) Table *table = NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_machine_mgr, "ListMachines", &error, &reply, NULL);
@@ -343,11 +341,9 @@ static int list_images(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(table_unrefp) Table *table = NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
pager_open(arg_pager_flags);
r = bus_call_method(bus, bus_machine_mgr, "ListImages", &error, &reply, NULL);
@@ -694,11 +690,9 @@ static int show_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
bool properties, new_line = false;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r = 0;
- assert(bus);
-
properties = !strstr(argv[0], "status");
pager_open(arg_pager_flags);
@@ -993,11 +987,9 @@ static int show_image(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
bool properties, new_line = false;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r = 0;
- assert(bus);
-
properties = !strstr(argv[0], "status");
pager_open(arg_pager_flags);
@@ -1037,11 +1029,9 @@ static int show_image(int argc, char *argv[], void *userdata) {
static int kill_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
if (!arg_kill_whom)
@@ -1078,11 +1068,9 @@ static int poweroff_machine(int argc, char *argv[], void *userdata) {
static int terminate_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (int i = 1; i < argc; i++) {
@@ -1106,12 +1094,10 @@ static int copy_files(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *abs_host_path = NULL;
char *dest, *host_path, *container_path;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
bool copy_from;
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
copy_from = streq(argv[0], "copy-from");
@@ -1160,11 +1146,9 @@ static int copy_files(int argc, char *argv[], void *userdata) {
static int bind_mount(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = bus_call_method(
@@ -1303,11 +1287,9 @@ static int login_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_slot_unrefp) sd_bus_slot *slot = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
int master = -1, r;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
const char *match, *machine;
- assert(bus);
-
if (!strv_isempty(arg_setenv) || arg_uid)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--setenv= and --uid= are not supported for 'login'. Use 'shell' instead.");
@@ -1357,12 +1339,10 @@ static int shell_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_slot_unrefp) sd_bus_slot *slot = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
int master = -1, r;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
const char *match, *machine, *path;
_cleanup_free_ char *uid = NULL;
- assert(bus);
-
if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Shell only supported on local machines.");
@@ -1433,11 +1413,9 @@ static int shell_machine(int argc, char *argv[], void *userdata) {
}
static int remove_image(int argc, char *argv[], void *userdata) {
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (int i = 1; i < argc; i++) {
@@ -1463,11 +1441,9 @@ static int remove_image(int argc, char *argv[], void *userdata) {
static int rename_image(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = bus_call_method(
@@ -1486,11 +1462,9 @@ static int rename_image(int argc, char *argv[], void *userdata) {
static int clone_image(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = bus_message_new_method_call(bus, &m, bus_machine_mgr, "CloneImage");
@@ -1511,11 +1485,9 @@ static int clone_image(int argc, char *argv[], void *userdata) {
static int read_only_image(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int b = true, r;
- assert(bus);
-
if (argc > 2) {
b = parse_boolean(argv[2]);
if (b < 0)
@@ -1571,11 +1543,9 @@ static int make_service_name(const char *name, char **ret) {
static int start_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
ask_password_agent_open_if_enabled(arg_transport, arg_ask_password);
@@ -1632,11 +1602,9 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
UnitFileChange *changes = NULL;
size_t n_changes = 0;
const char *method = NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
method = streq(argv[0], "enable") ? "EnableUnitFiles" : "DisableUnitFiles";
@@ -1834,11 +1802,9 @@ static int import_tar(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *ll = NULL, *fn = NULL;
const char *local = NULL, *path = NULL;
_cleanup_close_ int fd = -1;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
if (argc >= 2)
path = empty_or_dash_to_null(argv[1]);
@@ -1897,11 +1863,9 @@ static int import_raw(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *ll = NULL, *fn = NULL;
const char *local = NULL, *path = NULL;
_cleanup_close_ int fd = -1;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
if (argc >= 2)
path = empty_or_dash_to_null(argv[1]);
@@ -1960,11 +1924,9 @@ static int import_fs(int argc, char *argv[], void *userdata) {
const char *local = NULL, *path = NULL;
_cleanup_free_ char *fn = NULL;
_cleanup_close_ int fd = -1;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
if (argc >= 2)
path = empty_or_dash_to_null(argv[1]);
@@ -2028,11 +1990,9 @@ static int export_tar(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_close_ int fd = -1;
const char *local = NULL, *path = NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
local = argv[1];
if (!hostname_is_valid(local, 0))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
@@ -2070,11 +2030,9 @@ static int export_raw(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_close_ int fd = -1;
const char *local = NULL, *path = NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
local = argv[1];
if (!hostname_is_valid(local, 0))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
@@ -2112,11 +2070,9 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *l = NULL, *ll = NULL;
const char *local, *remote;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
remote = argv[1];
if (!http_url_is_valid(remote) && !file_url_is_valid(remote))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
@@ -2168,11 +2124,9 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *l = NULL, *ll = NULL;
const char *local, *remote;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
remote = argv[1];
if (!http_url_is_valid(remote) && !file_url_is_valid(remote))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
@@ -2329,11 +2283,9 @@ static int list_transfers(int argc, char *argv[], void *userdata) {
static int cancel_transfer(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- sd_bus *bus = userdata;
+ sd_bus *bus = ASSERT_PTR(userdata);
int r;
- assert(bus);
-
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (int i = 1; i < argc; i++) {