From 385d581b7429f9d1d6d2826eac82e581468656f9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Nov 2019 11:11:10 +0100 Subject: [PATCH 1/3] polkit-agent: don't use an inline function This is long enough to just be a regular function, and is never called in inner loops, let's hence just make this a plain function. --- src/shared/spawn-polkit-agent.c | 13 +++++++++++++ src/shared/spawn-polkit-agent.h | 17 +++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/shared/spawn-polkit-agent.c b/src/shared/spawn-polkit-agent.c index 180cb7964c..4d6c0cae6c 100644 --- a/src/shared/spawn-polkit-agent.c +++ b/src/shared/spawn-polkit-agent.c @@ -83,3 +83,16 @@ void polkit_agent_close(void) { } #endif + +int polkit_agent_open_if_enabled(BusTransport transport, bool ask_password) { + + /* Open the polkit agent as a child process if necessary */ + + if (transport != BUS_TRANSPORT_LOCAL) + return 0; + + if (!ask_password) + return 0; + + return polkit_agent_open(); +} diff --git a/src/shared/spawn-polkit-agent.h b/src/shared/spawn-polkit-agent.h index 190b970b6f..56b0175944 100644 --- a/src/shared/spawn-polkit-agent.h +++ b/src/shared/spawn-polkit-agent.h @@ -1,22 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once +#include + #include "bus-util.h" int polkit_agent_open(void); void polkit_agent_close(void); -static inline int polkit_agent_open_if_enabled( - BusTransport transport, - bool ask_password) { - - /* Open the polkit agent as a child process if necessary */ - - if (transport != BUS_TRANSPORT_LOCAL) - return 0; - - if (!ask_password) - return 0; - - return polkit_agent_open(); -} +int polkit_agent_open_if_enabled(BusTransport transport, bool ask_password); From c59e2ec6961e6ce1acb97bb2cdb7499dc23bc23d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Nov 2019 11:11:52 +0100 Subject: [PATCH 2/3] ask-password-agent: introduce ask_password_agent_open_if_enabled() This makes the ask-password agent handling more alike the polkit agent handling again, and introduces ask_password_agent_open_if_enabled() that works just like the already existing polkit_agent_open_if_enabled(). --- src/shared/spawn-ask-password-agent.c | 13 +++++++++++++ src/shared/spawn-ask-password-agent.h | 6 ++++++ src/systemctl/systemctl.c | 12 +++--------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/shared/spawn-ask-password-agent.c b/src/shared/spawn-ask-password-agent.c index 309071c89d..ddaebf0f61 100644 --- a/src/shared/spawn-ask-password-agent.c +++ b/src/shared/spawn-ask-password-agent.c @@ -46,3 +46,16 @@ void ask_password_agent_close(void) { (void) wait_for_terminate(agent_pid, NULL); agent_pid = 0; } + +int ask_password_agent_open_if_enabled(BusTransport transport, bool ask_password) { + + /* Open the ask password agent as a child process if necessary */ + + if (transport != BUS_TRANSPORT_LOCAL) + return 0; + + if (!ask_password) + return 0; + + return ask_password_agent_open(); +} diff --git a/src/shared/spawn-ask-password-agent.h b/src/shared/spawn-ask-password-agent.h index 97e73bda44..97b12fe268 100644 --- a/src/shared/spawn-ask-password-agent.h +++ b/src/shared/spawn-ask-password-agent.h @@ -1,5 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once +#include + +#include "bus-util.h" + int ask_password_agent_open(void); void ask_password_agent_close(void); + +int ask_password_agent_open_if_enabled(BusTransport transport, bool ask_password); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 4be695d5b6..012867fbb0 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -236,22 +236,16 @@ static void release_busses(void) { buses[w] = sd_bus_flush_close_unref(buses[w]); } -static void ask_password_agent_open_if_enabled(void) { +static void ask_password_agent_open_maybe(void) { /* Open the password agent as a child process if necessary */ if (arg_dry_run) return; - if (!arg_ask_password) - return; - if (arg_scope != UNIT_FILE_SYSTEM) return; - if (arg_transport != BUS_TRANSPORT_LOCAL) - return; - - ask_password_agent_open(); + ask_password_agent_open_if_enabled(arg_transport, arg_ask_password); } static void polkit_agent_open_maybe(void) { @@ -3071,7 +3065,7 @@ static int start_unit(int argc, char *argv[], void *userdata) { if (r < 0) return r; - ask_password_agent_open_if_enabled(); + ask_password_agent_open_maybe(); polkit_agent_open_maybe(); if (arg_action == ACTION_SYSTEMCTL) { From e41e9ba8bfd97eae8d0009f41a99d9eda4297e2f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Nov 2019 11:12:34 +0100 Subject: [PATCH 3/3] machinectl: spawn ask password agent on "start" We start units in the background, hence it is wise to also have the ask pasword agent around. Fixes: #13587 --- src/machine/machinectl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 6dbdba12fd..afb89853be 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -46,6 +46,7 @@ #include "sigbus.h" #include "signal-util.h" #include "sort-util.h" +#include "spawn-ask-password-agent.h" #include "spawn-polkit-agent.h" #include "stdio-util.h" #include "string-table.h" @@ -1722,6 +1723,7 @@ static int start_machine(int argc, char *argv[], void *userdata) { assert(bus); polkit_agent_open_if_enabled(arg_transport, arg_ask_password); + ask_password_agent_open_if_enabled(arg_transport, arg_ask_password); r = bus_wait_for_jobs_new(bus, &w); if (r < 0)