Debian Codegraph @

src/shared/ask-password-agent.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "ask-password-agent.h"
4 #include "bus-util.h"
5 #include "exec-util.h"
6 #include "log.h"
7 #include "pidref.h"
8
9 static PidRef agent_pidref = PIDREF_NULL;
10
11 int ask_password_agent_open(void) {
12 int r;
13
14 if (pidref_is_set(&agent_pidref))
15 return 0;
16
17 r = shall_fork_agent();
18 if (r <= 0)
19 return r;
20
21 r = fork_agent("(sd-askpwagent)",
22 NULL, 0,
23 &agent_pidref,
24 SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH,
25 "--watch");
26 if (r < 0)
27 return log_error_errno(r, "Failed to fork TTY ask password agent: %m");
28
29 return 1;
30 }
31
32 void ask_password_agent_close(void) {
33 /* Inform agent that we are done */
34 pidref_done_sigterm_wait(&agent_pidref);
35 }
36
37 int ask_password_agent_open_if_enabled(BusTransport transport, bool ask_password) {
38
39 /* Open the ask password agent as a child process if necessary */
40
41 if (transport != BUS_TRANSPORT_LOCAL)
42 return 0;
43
44 if (!ask_password)
45 return 0;
46
47 return ask_password_agent_open();
48 }