summaryrefslogtreecommitdiff
path: root/src/machine
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-02-18 11:42:03 +0100
committerLennart Poettering <lennart@poettering.net>2015-02-18 11:43:18 +0100
commit2723b3b51d409340558e46e37e90525d4f880fe1 (patch)
treeefcc21c8b4cc77f36bc8f8549545d864897969eb /src/machine
parent70244d1d25eb80b57e160ea004d0e6bf793d4caf (diff)
machinectl: issue all bus commands while allowing interactive auth
Diffstat (limited to 'src/machine')
-rw-r--r--src/machine/machinectl.c87
1 files changed, 28 insertions, 59 deletions
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index ea6db4d18b..053c8fbbe7 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -969,15 +969,13 @@ static int poweroff_machine(int argc, char *argv[], void *userdata) {
static int terminate_machine(int argc, char *argv[], void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus *bus = userdata;
- int i;
+ int r, i;
assert(bus);
polkit_agent_open_if_enabled();
for (i = 1; i < argc; i++) {
- int r;
-
r = sd_bus_call_method(
bus,
"org.freedesktop.machine1",
@@ -1004,6 +1002,8 @@ static int copy_files(int argc, char *argv[], void *userdata) {
assert(bus);
+ polkit_agent_open_if_enabled();
+
copy_from = streq(argv[0], "copy-from");
r = sd_bus_call_method(
@@ -1033,6 +1033,8 @@ static int bind_mount(int argc, char *argv[], void *userdata) {
assert(bus);
+ polkit_agent_open_if_enabled();
+
r = sd_bus_call_method(
bus,
"org.freedesktop.machine1",
@@ -1082,7 +1084,7 @@ static int on_machine_removed(sd_bus *bus, sd_bus_message *m, void *userdata, sd
static int login_machine(int argc, char *argv[], void *userdata) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_slot_unref_ sd_bus_slot *slot = NULL;
_cleanup_(pty_forward_freep) PTYForward *forward = NULL;
_cleanup_event_unref_ sd_event *event = NULL;
@@ -1123,24 +1125,15 @@ static int login_machine(int argc, char *argv[], void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to add machine removal match: %m");
- r = sd_bus_message_new_method_call(bus,
- &m,
- "org.freedesktop.machine1",
- "/org/freedesktop/machine1",
- "org.freedesktop.machine1.Manager",
- "OpenMachineLogin");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_append(m, "s", argv[1]);
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_call(bus, m, 0, &error, &reply);
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.machine1",
+ "/org/freedesktop/machine1",
+ "org.freedesktop.machine1.Manager",
+ "OpenMachineLogin",
+ &error,
+ &reply,
+ "s", argv[1]);
if (r < 0) {
log_error("Failed to get machine PTY: %s", bus_error_message(&error, -r));
return r;
@@ -1305,7 +1298,7 @@ static int start_machine(int argc, char *argv[], void *userdata) {
return log_oom();
for (i = 1; i < argc; i++) {
- _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_free_ char *e = NULL, *unit = NULL;
const char *object;
@@ -1322,25 +1315,15 @@ static int start_machine(int argc, char *argv[], void *userdata) {
if (!unit)
return log_oom();
- r = sd_bus_message_new_method_call(
+ r = sd_bus_call_method(
bus,
- &m,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
- "StartUnit");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_append(m, "ss", unit, "fail");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_call(bus, m, 0, &error, &reply);
+ "StartUnit",
+ &error,
+ &reply,
+ "ss", unit, "fail");
if (r < 0) {
log_error("Failed to start unit: %s", bus_error_message(&error, -r));
return r;
@@ -1386,10 +1369,6 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_create_error(r);
- r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
- if (r < 0)
- return bus_log_create_error(r);
-
r = sd_bus_message_open_container(m, 'a', "s");
if (r < 0)
return bus_log_create_error(r);
@@ -1442,23 +1421,15 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
if (r < 0)
return r;
- m = sd_bus_message_unref(m);
-
- r = sd_bus_message_new_method_call(
+ r = sd_bus_call_method(
bus,
- &m,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
- "Reload");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_call(bus, m, 0, &error, NULL);
+ "Reload",
+ &error,
+ NULL,
+ NULL);
if (r < 0) {
log_error("Failed to reload daemon: %s", bus_error_message(&error, -r));
return r;
@@ -1547,10 +1518,6 @@ static int pull_image_common(sd_bus *bus, sd_bus_message *m) {
if (r < 0)
return log_error_errno(r, "Failed to attach bus to event loop: %m");
- r = sd_bus_message_set_allow_interactive_authorization(m, arg_ask_password);
- if (r < 0)
- return bus_log_create_error(r);
-
r = sd_bus_add_match(
bus,
&slot_job_removed,
@@ -2223,6 +2190,8 @@ int main(int argc, char*argv[]) {
goto finish;
}
+ sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
+
r = machinectl_main(argc, argv, bus);
finish: