]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
6bb92a16 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2011 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
8 | under the terms of the GNU Lesser General Public License as published by |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
6bb92a16 LP |
10 | (at your option) any later version. |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 15 | Lesser General Public License for more details. |
6bb92a16 | 16 | |
5430f7f2 | 17 | You should have received a copy of the GNU Lesser General Public License |
6bb92a16 LP |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
19 | ***/ | |
20 | ||
00843602 | 21 | #include <signal.h> |
6bb92a16 LP |
22 | #include <stdlib.h> |
23 | #include <unistd.h> | |
6bb92a16 LP |
24 | |
25 | #include "log.h" | |
0b452006 | 26 | #include "process-util.h" |
6bb92a16 | 27 | #include "spawn-ask-password-agent.h" |
cf0fbc49 | 28 | #include "util.h" |
6bb92a16 LP |
29 | |
30 | static pid_t agent_pid = 0; | |
31 | ||
32 | int ask_password_agent_open(void) { | |
33 | int r; | |
34 | ||
35 | if (agent_pid > 0) | |
36 | return 0; | |
37 | ||
38 | /* We check STDIN here, not STDOUT, since this is about input, | |
39 | * not output */ | |
40 | if (!isatty(STDIN_FILENO)) | |
41 | return 0; | |
42 | ||
9bdc770c LP |
43 | r = fork_agent(&agent_pid, |
44 | NULL, 0, | |
45 | SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH, | |
46 | SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH, "--watch", NULL); | |
6bb92a16 | 47 | if (r < 0) |
00843602 | 48 | return log_error_errno(r, "Failed to fork TTY ask password agent: %m"); |
6bb92a16 | 49 | |
00843602 | 50 | return 1; |
6bb92a16 LP |
51 | } |
52 | ||
53 | void ask_password_agent_close(void) { | |
54 | ||
55 | if (agent_pid <= 0) | |
56 | return; | |
57 | ||
58 | /* Inform agent that we are done */ | |
00843602 LP |
59 | (void) kill(agent_pid, SIGTERM); |
60 | (void) kill(agent_pid, SIGCONT); | |
c73d180d | 61 | (void) wait_for_terminate(agent_pid, NULL); |
6bb92a16 LP |
62 | agent_pid = 0; |
63 | } |