/src/systemd/src/shared/ask-password-agent.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | |
3 | | #include <signal.h> |
4 | | |
5 | | #include "ask-password-agent.h" |
6 | | #include "bus-util.h" |
7 | | #include "exec-util.h" |
8 | | #include "log.h" |
9 | | #include "process-util.h" |
10 | | |
11 | | static pid_t agent_pid = 0; |
12 | | |
13 | 0 | int ask_password_agent_open(void) { |
14 | 0 | int r; |
15 | |
|
16 | 0 | if (agent_pid > 0) |
17 | 0 | return 0; |
18 | | |
19 | 0 | r = shall_fork_agent(); |
20 | 0 | if (r <= 0) |
21 | 0 | return r; |
22 | | |
23 | 0 | r = fork_agent("(sd-askpwagent)", |
24 | 0 | NULL, 0, |
25 | 0 | &agent_pid, |
26 | 0 | SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH, |
27 | 0 | "--watch"); |
28 | 0 | if (r < 0) |
29 | 0 | return log_error_errno(r, "Failed to fork TTY ask password agent: %m"); |
30 | | |
31 | 0 | return 1; |
32 | 0 | } |
33 | | |
34 | 0 | void ask_password_agent_close(void) { |
35 | |
|
36 | 0 | if (agent_pid <= 0) |
37 | 0 | return; |
38 | | |
39 | | /* Inform agent that we are done */ |
40 | 0 | sigterm_wait(TAKE_PID(agent_pid)); |
41 | 0 | } |
42 | | |
43 | 0 | int ask_password_agent_open_if_enabled(BusTransport transport, bool ask_password) { |
44 | | |
45 | | /* Open the ask password agent as a child process if necessary */ |
46 | |
|
47 | 0 | if (transport != BUS_TRANSPORT_LOCAL) |
48 | 0 | return 0; |
49 | | |
50 | 0 | if (!ask_password) |
51 | 0 | return 0; |
52 | | |
53 | 0 | return ask_password_agent_open(); |
54 | 0 | } |