]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/spawn-polkit-agent.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2011 Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
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
10 (at your option) any later version.
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
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
31 #include "process-util.h"
32 #include "spawn-polkit-agent.h"
33 #include "stdio-util.h"
34 #include "time-util.h"
38 static pid_t agent_pid
= 0;
40 int polkit_agent_open(void) {
43 char notify_fd
[DECIMAL_STR_MAX(int) + 1];
48 /* Clients that run as root don't need to activate/query polkit */
52 /* We check STDIN here, not STDOUT, since this is about input,
54 if (!isatty(STDIN_FILENO
))
57 if (pipe2(pipe_fd
, 0) < 0)
60 xsprintf(notify_fd
, "%i", pipe_fd
[1]);
62 r
= fork_agent(&agent_pid
,
64 POLKIT_AGENT_BINARY_PATH
,
65 POLKIT_AGENT_BINARY_PATH
, "--notify-fd", notify_fd
, "--fallback", NULL
);
67 /* Close the writing side, because that's the one for the agent */
68 safe_close(pipe_fd
[1]);
71 log_error_errno(r
, "Failed to fork TTY ask password agent: %m");
73 /* Wait until the agent closes the fd */
74 fd_wait_for_event(pipe_fd
[0], POLLHUP
, USEC_INFINITY
);
76 safe_close(pipe_fd
[0]);
81 void polkit_agent_close(void) {
86 /* Inform agent that we are done */
87 (void) kill(agent_pid
, SIGTERM
);
88 (void) kill(agent_pid
, SIGCONT
);
90 (void) wait_for_terminate(agent_pid
, NULL
);
96 int polkit_agent_open(void) {
100 void polkit_agent_close(void) {