1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 #include "process-util.h"
10 #include "spawn-ask-password-agent.h"
12 static pid_t agent_pid
= 0;
14 int ask_password_agent_open(void) {
20 /* We check STDIN here, not STDOUT, since this is about input,
22 if (!isatty(STDIN_FILENO
))
25 if (!is_main_thread())
28 r
= fork_agent("(sd-askpwagent)",
31 SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH
,
32 SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH
, "--watch", NULL
);
34 return log_error_errno(r
, "Failed to fork TTY ask password agent: %m");
39 void ask_password_agent_close(void) {
44 /* Inform agent that we are done */
45 sigterm_wait(TAKE_PID(agent_pid
));
48 int ask_password_agent_open_if_enabled(BusTransport transport
, bool ask_password
) {
50 /* Open the ask password agent as a child process if necessary */
52 if (transport
!= BUS_TRANSPORT_LOCAL
)
58 return ask_password_agent_open();