]>
git.proxmox.com Git - systemd.git/blob - src/shared/spawn-polkit-agent.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 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"
37 static pid_t agent_pid
= 0;
39 int polkit_agent_open(void) {
42 char notify_fd
[DECIMAL_STR_MAX(int) + 1];
47 /* We check STDIN here, not STDOUT, since this is about input,
49 if (!isatty(STDIN_FILENO
))
52 if (pipe2(pipe_fd
, 0) < 0)
55 xsprintf(notify_fd
, "%i", pipe_fd
[1]);
57 r
= fork_agent(&agent_pid
,
59 POLKIT_AGENT_BINARY_PATH
,
60 POLKIT_AGENT_BINARY_PATH
, "--notify-fd", notify_fd
, "--fallback", NULL
);
62 /* Close the writing side, because that's the one for the agent */
63 safe_close(pipe_fd
[1]);
66 log_error_errno(r
, "Failed to fork TTY ask password agent: %m");
68 /* Wait until the agent closes the fd */
69 fd_wait_for_event(pipe_fd
[0], POLLHUP
, USEC_INFINITY
);
71 safe_close(pipe_fd
[0]);
76 void polkit_agent_close(void) {
81 /* Inform agent that we are done */
82 (void) kill(agent_pid
, SIGTERM
);
83 (void) kill(agent_pid
, SIGCONT
);
85 (void) wait_for_terminate(agent_pid
, NULL
);
91 int polkit_agent_open(void) {
95 void polkit_agent_close(void) {