1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-02-04 06:02:24 +00:00

Unix Pageant: factor out have_controlling_tty().

I'm going to want to reuse it when deciding on a passphrase-prompting
strategy.
This commit is contained in:
Simon Tatham 2015-05-13 13:54:15 +01:00
parent a181639521
commit 460c45dd23

View File

@ -269,6 +269,21 @@ void add_keyact(keyact action, const char *filename)
keyact_tail = a; keyact_tail = a;
} }
int have_controlling_tty(void)
{
int fd = open("/dev/tty", O_RDONLY);
if (fd < 0) {
if (errno != ENXIO) {
perror("/dev/tty: open");
exit(1);
}
return FALSE;
} else {
close(fd);
return TRUE;
}
}
char **exec_args = NULL; char **exec_args = NULL;
enum { enum {
LIFE_UNSPEC, LIFE_X11, LIFE_TTY, LIFE_DEBUG, LIFE_PERM, LIFE_EXEC LIFE_UNSPEC, LIFE_X11, LIFE_TTY, LIFE_DEBUG, LIFE_PERM, LIFE_EXEC
@ -840,16 +855,9 @@ void run_agent(void)
* our containing tty session has ended, so it's time to * our containing tty session has ended, so it's time to
* clean up and leave. * clean up and leave.
*/ */
int fd = open("/dev/tty", O_RDONLY); if (!have_controlling_tty()) {
if (fd < 0) {
if (errno != ENXIO) {
perror("/dev/tty: open");
exit(1);
}
time_to_die = TRUE; time_to_die = TRUE;
break; break;
} else {
close(fd);
} }
} }