1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2011 Lennart Poettering
13 #include "process-util.h"
14 #include "spawn-ask-password-agent.h"
17 static pid_t agent_pid
= 0;
19 int ask_password_agent_open(void) {
25 /* We check STDIN here, not STDOUT, since this is about input,
27 if (!isatty(STDIN_FILENO
))
30 if (!is_main_thread())
33 r
= fork_agent("(sd-askpwagent)",
36 SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH
,
37 SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH
, "--watch", NULL
);
39 return log_error_errno(r
, "Failed to fork TTY ask password agent: %m");
44 void ask_password_agent_close(void) {
49 /* Inform agent that we are done */
50 (void) kill_and_sigcont(agent_pid
, SIGTERM
);
51 (void) wait_for_terminate(agent_pid
, NULL
);