1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Support running UNIX Pageant in foreground mode, without debugging output

This new mode makes it easy to run Pageant as a "supervised" instance,
e.g. as part of a test harness for other programs interacting with an
SSH agent, which is the original use case. Because Pageant is then
running as a child process of the supervisor, the operating system
notifies the supervisor of the child's aliveness without resorting to
PIDs or socket addresses, both of which may principally run stale and/or
get recycled.
This commit is contained in:
Marco Ricci 2024-09-18 20:04:31 +02:00 committed by Simon Tatham
parent fca6ce10db
commit 2b93417398
2 changed files with 19 additions and 3 deletions

View File

@ -8,8 +8,8 @@
\S{pageant-manpage-synopsis} SYNOPSIS \S{pageant-manpage-synopsis} SYNOPSIS
\c pageant ( -X | -T | --permanent | --debug ) [ [ --encrypted ] key-file... ] \c pageant ( -X | -T | --permanent | --debug | --foreground ) [ [ --encrypted ] key-file... ]
\e bbbbbbb bb bb bbbbbbbbbbb bbbbbbb bbbbbbbbbbb iiiiiiii \e bbbbbbb bb bb bbbbbbbbbbb bbbbbbb bbbbbbbbbbbb bbbbbbbbbbb iiiiiiii
\c pageant [ [ --encrypted ] key-file... ] --exec command [ args... ] \c pageant [ [ --encrypted ] key-file... ] --exec command [ args... ]
\e bbbbbbb bbbbbbbbb iiiiiiii bbbbbb iiiiiii iiii \e bbbbbbb bbbbbbbbb iiiiiiii bbbbbb iiiiiii iiii
\c pageant -a [ --encrypted ] key-file... \c pageant -a [ --encrypted ] key-file...
@ -183,6 +183,16 @@ prompts will need to be answered on standard input. This is useful
for debugging what Pageant itself is doing, or what another process is for debugging what Pageant itself is doing, or what another process is
doing to it. doing to it.
\dt \cw{--foreground}
\dd Like \cw{--debug}, Pageant will run in the foreground, without
forking. It will print its environment variable setup commands on
standard output. Unlike \cw{--debug}, Pageant will not automatically log
agent activity to standard output, nor will it force passphrase prompts
to standard input. This is useful if Pageant is spawned by a parent
process that controls or otherwise programmatically interfaces with
Pageant.
\S{pageant-manpage-client} CLIENT OPTIONS \S{pageant-manpage-client} CLIENT OPTIONS
The following options tell Pageant to operate in client mode, The following options tell Pageant to operate in client mode,

View File

@ -198,6 +198,7 @@ static void usage(void)
printf(" -T run with the lifetime of the controlling tty\n"); printf(" -T run with the lifetime of the controlling tty\n");
printf(" --permanent run permanently\n"); printf(" --permanent run permanently\n");
printf(" --debug run in debugging mode, without forking\n"); printf(" --debug run in debugging mode, without forking\n");
printf(" --foreground run permanently, without forking\n");
printf(" --exec <command> run with the lifetime of that command\n"); printf(" --exec <command> run with the lifetime of that command\n");
printf("Client options, for talking to an existing agent:\n"); printf("Client options, for talking to an existing agent:\n");
printf(" -a add key(s) to the existing agent\n"); printf(" -a add key(s) to the existing agent\n");
@ -425,7 +426,7 @@ bool have_controlling_tty(void)
static char **exec_args = NULL; static char **exec_args = NULL;
static enum { static 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, LIFE_FOREGROUND
} life = LIFE_UNSPEC; } life = LIFE_UNSPEC;
static const char *display = NULL; static const char *display = NULL;
static enum { static enum {
@ -1222,6 +1223,9 @@ void run_agent(FILE *logfp, const char *symlink_path)
pageant_fork_and_print_env(true); pageant_fork_and_print_env(true);
} else if (life == LIFE_PERM) { } else if (life == LIFE_PERM) {
pageant_fork_and_print_env(false); pageant_fork_and_print_env(false);
} else if (life == LIFE_FOREGROUND) {
setvbuf(stdout, NULL, _IOLBF, 0);
pageant_print_env(getpid());
} else if (life == LIFE_DEBUG) { } else if (life == LIFE_DEBUG) {
/* Force stdout to be line-buffered in preference to unbuffered, so /* Force stdout to be line-buffered in preference to unbuffered, so
* that if diagnostic output is being piped somewhere, it will arrive * that if diagnostic output is being piped somewhere, it will arrive
@ -1366,6 +1370,8 @@ int main(int argc, char **argv)
} }
} else if (!strcmp(p, "--debug")) { } else if (!strcmp(p, "--debug")) {
life = LIFE_DEBUG; life = LIFE_DEBUG;
} else if (!strcmp(p, "--foreground")) {
life = LIFE_FOREGROUND;
} else if (!strcmp(p, "--test-sign")) { } else if (!strcmp(p, "--test-sign")) {
curr_keyact = KEYACT_CLIENT_SIGN; curr_keyact = KEYACT_CLIENT_SIGN;
sign_flags = 0; sign_flags = 0;