} arg_action = ACTION_QUERY;
static bool arg_plymouth = false;
+static bool arg_console = false;
static int ask_password_plymouth(const char *message, usec_t until, const char *flag_file, char **_passphrase) {
int fd = -1, notify = -1;
if (arg_plymouth)
r = ask_password_plymouth(message, not_after, filename, &password);
- else
+ else {
+ int tty_fd = -1;
+
+ if (arg_console)
+ if ((tty_fd = acquire_terminal("/dev/console", false, false, false)) < 0) {
+ r = tty_fd;
+ goto finish;
+ }
+
r = ask_password_tty(message, not_after, filename, &password);
+ if (arg_console) {
+ close_nointr_nofail(tty_fd);
+ release_terminal();
+ }
+ }
+
if (r < 0) {
log_error("Failed to query password: %s", strerror(-r));
goto finish;
return r;
}
-static int tty_block(void) {
+static int wall_tty_block(void) {
char *p;
const char *t;
int fd;
return fd;
}
-static bool tty_match(const char *path) {
+static bool wall_tty_match(const char *path) {
int fd;
char *p;
free(p);
if (wall) {
- utmp_wall(wall, tty_match);
+ utmp_wall(wall, wall_tty_match);
free(wall);
}
}
sigset_t mask;
int r;
- tty_block_fd = tty_block();
+ tty_block_fd = wall_tty_block();
mkdir_p("/dev/.systemd/ask-password", 0755);
for (;;) {
if ((r = show_passwords()) < 0)
- goto finish;
+ log_error("Failed to show password: %s", strerror(-r));
if (poll(pollfd, _FD_MAX, -1) < 0) {
" --query Process pending password requests\n"
" --watch Continously process password requests\n"
" --wall Continously forward password requests to wall\n"
- " --plymouth Ask question with Plymouth instead of on TTY\n",
+ " --plymouth Ask question with Plymouth instead of on TTY\n"
+ " --console Ask question on /dev/console instead of current TTY\n",
program_invocation_short_name);
return 0;
ARG_QUERY,
ARG_WATCH,
ARG_WALL,
- ARG_PLYMOUTH
+ ARG_PLYMOUTH,
+ ARG_CONSOLE
};
static const struct option options[] = {
{ "watch", no_argument, NULL, ARG_WATCH },
{ "wall", no_argument, NULL, ARG_WALL },
{ "plymouth", no_argument, NULL, ARG_PLYMOUTH },
+ { "console", no_argument, NULL, ARG_CONSOLE },
{ NULL, 0, NULL, 0 }
};
arg_plymouth = true;
break;
+ case ARG_CONSOLE:
+ arg_console = true;
+ break;
+
case '?':
return -EINVAL;
if ((r = parse_argv(argc, argv)) <= 0)
goto finish;
+ if (arg_console) {
+ setsid();
+ release_terminal();
+ }
+
if (arg_action == ACTION_WATCH ||
arg_action == ACTION_WALL)
r = watch_passwords();