mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
pageant --foreground: close stdout after printing env setup.
This is a small refinement of my own to Marco Ricci's new mode introduced by the previous commit. If Pageant is being run by a parent process intending to make requests to it, then it's probably put a pipe on Pageant's stdout, and will be reading from that pipe to retrieve the environment setup commands. So it needs to know when it's read enough. Closing stdout immediately makes this as easy as possible, freeing the parent process of the need to count lines of output (and also know how many lines to expect): it can simply read until there's no more data. This also means there's no need to make stdout line-buffered, of course – the fclose will flush it anyway.
This commit is contained in:
parent
2b93417398
commit
10b5c1163c
@ -193,6 +193,15 @@ to standard input. This is useful if Pageant is spawned by a parent
|
||||
process that controls or otherwise programmatically interfaces with
|
||||
Pageant.
|
||||
|
||||
\lcont{
|
||||
|
||||
After Pageant prints its environment setup commands, it closes its
|
||||
standard output, so that the parent process can simply read until it
|
||||
receives EOF, instead of having to know how many lines of output to
|
||||
expect.
|
||||
|
||||
}
|
||||
|
||||
\S{pageant-manpage-client} CLIENT OPTIONS
|
||||
|
||||
The following options tell Pageant to operate in client mode,
|
||||
|
@ -1224,8 +1224,10 @@ void run_agent(FILE *logfp, const char *symlink_path)
|
||||
} else if (life == LIFE_PERM) {
|
||||
pageant_fork_and_print_env(false);
|
||||
} else if (life == LIFE_FOREGROUND) {
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
pageant_print_env(getpid());
|
||||
/* Close stdout, so that a parent process at the other end of a pipe
|
||||
* can do the simple thing of reading up to EOF */
|
||||
fclose(stdout);
|
||||
} else if (life == LIFE_DEBUG) {
|
||||
/* Force stdout to be line-buffered in preference to unbuffered, so
|
||||
* that if diagnostic output is being piped somewhere, it will arrive
|
||||
|
Loading…
Reference in New Issue
Block a user