This source file includes following definitions.
- ask_password_agent_open
- ask_password_agent_close
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/prctl.h>
#include <signal.h>
#include <fcntl.h>
#include "log.h"
#include "util.h"
#include "spawn-ask-password-agent.h"
static pid_t agent_pid = 0;
int ask_password_agent_open(void) {
int r;
if (agent_pid > 0)
return 0;
if (!isatty(STDIN_FILENO))
return 0;
r = fork_agent(&agent_pid,
NULL, 0,
SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH,
SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH, "--watch", NULL);
if (r < 0)
log_error("Failed to fork TTY ask password agent: %s", strerror(-r));
return r;
}
void ask_password_agent_close(void) {
if (agent_pid <= 0)
return;
kill(agent_pid, SIGTERM);
kill(agent_pid, SIGCONT);
wait_for_terminate(agent_pid, NULL);
agent_pid = 0;
}