Skip to content

Instantly share code, notes, and snippets.

@nezza
Created April 3, 2014 12:03
Show Gist options
  • Save nezza/9953124 to your computer and use it in GitHub Desktop.
Save nezza/9953124 to your computer and use it in GitHub Desktop.
Caller code:
char *password = NULL;
if (arg_console)
if ((tty_fd = acquire_terminal("/dev/console", false, false, false, (usec_t) -1)) < 0) {
r = tty_fd;
goto finish;
}
r = ask_password_tty(message, not_after, filename, &password);
Code for ask_password_tty:
int ask_password_tty(
const char *message,
usec_t until,
const char *flag_file,
char **_passphrase) {
struct termios old_termios, new_termios;
char passphrase[LINE_MAX], *x;
size_t p = 0;
int r;
_cleanup_close_ int ttyfd = -1, notify = -1;
struct pollfd pollfd[2];
bool reset_tty = false;
bool silent_mode = false;
bool dirty = false;
enum {
POLL_TTY,
POLL_INOTIFY
};
assert(message);
assert(_passphrase);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment