1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05:00

Remove FLAG_STDERR completely.

Originally, it controlled whether ssh.c should send terminal messages
(such as login and password prompts) to terminal.c or to stderr. But
we've had the from_backend() abstraction for ages now, which even has
an existing flag to indicate that the data is stderr rather than
stdout data; applications which set FLAG_STDERR are precisely those
that link against uxcons or wincons, so from_backend will do the
expected thing anyway with data sent to it with that flag set. So
there's no reason ssh.c can't just unconditionally pass everything
through that, and remove the special case.

FLAG_STDERR was also used by winproxy and uxproxy to decide whether to
capture standard error from a local proxy command, or whether to let
the proxy command send its diagnostics directly to the usual standard
error. On reflection, I think it's better to unconditionally capture
the proxy's stderr, for three reasons. Firstly, it means proxy
diagnostics are prefixed with 'proxy:' so that you can tell them apart
from any other stderr spew (which used to be particularly confusing if
both the main application and the proxy command were instances of
Plink); secondly, proxy diagnostics are now reliably copied to packet
log files along with all the other Event Log entries, even by
command-line tools; and thirdly, this means the option to suppress
proxy command diagnostics after the main session starts will actually
_work_ in the command-line tools, which it previously couldn't.

A more minor structure change is that copying of Event Log messages to
stderr in verbose mode is now done by wincons/uxcons, instead of
centrally in logging.c (since logging.c can now no longer check
FLAG_STDERR to decide whether to do it). The total amount of code to
do this is considerably smaller than the defensive-sounding comment in
logevent.c explaining why I did it the other way instead :-)
This commit is contained in:
Simon Tatham
2018-09-21 16:15:49 +01:00
parent 361efee621
commit e230751853
11 changed files with 31 additions and 77 deletions

View File

@ -413,12 +413,14 @@ void console_provide_logctx(LogContext *logctx)
void logevent(Frontend *frontend, const char *string)
{
struct termios cf;
if ((flags & FLAG_STDERR) && (flags & FLAG_VERBOSE))
if (flags & FLAG_VERBOSE) {
premsg(&cf);
fprintf(stderr, "%s\n", string);
fflush(stderr);
postmsg(&cf);
}
if (console_logctx)
log_eventlog(console_logctx, string);
if ((flags & FLAG_STDERR) && (flags & FLAG_VERBOSE))
postmsg(&cf);
}
/*

View File

@ -610,7 +610,7 @@ int main(int argc, char **argv)
bufchain_init(&stderr_data);
outgoingeof = EOF_NO;
flags = FLAG_STDERR | FLAG_STDERR_TTY;
flags = FLAG_STDERR_TTY;
cmdline_tooltype |=
(TOOLTYPE_HOST_ARG |
TOOLTYPE_HOST_ARG_CAN_BE_SESSION |

View File

@ -299,18 +299,6 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
if (proxytype == PROXY_CMD) {
cmd = format_telnet_command(addr, port, conf);
if (flags & FLAG_STDERR) {
/* If we have a sensible stderr, the proxy command can
* send its own standard error there, so we won't
* interfere. */
cmd_err_pipe[0] = cmd_err_pipe[1] = -1;
} else {
/* If we don't have a sensible stderr, we should catch the
* proxy command's standard error to put in our event
* log. */
cmd_err_pipe[0] = cmd_err_pipe[1] = 0;
}
{
char *logmsg = dupprintf("Starting local proxy command: %s", cmd);
plug_log(plug, 2, NULL, 0, logmsg, 0);
@ -323,15 +311,14 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
*/
if (pipe(to_cmd_pipe) < 0 ||
pipe(from_cmd_pipe) < 0 ||
(cmd_err_pipe[0] == 0 && pipe(cmd_err_pipe) < 0)) {
pipe(cmd_err_pipe) < 0) {
ret->error = dupprintf("pipe: %s", strerror(errno));
sfree(cmd);
return &ret->sockvt;
}
cloexec(to_cmd_pipe[1]);
cloexec(from_cmd_pipe[0]);
if (cmd_err_pipe[0] >= 0)
cloexec(cmd_err_pipe[0]);
cloexec(cmd_err_pipe[0]);
pid = fork();
@ -346,10 +333,7 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
dup2(from_cmd_pipe[1], 1);
close(to_cmd_pipe[0]);
close(from_cmd_pipe[1]);
if (cmd_err_pipe[0] >= 0) {
dup2(cmd_err_pipe[1], 2);
close(cmd_err_pipe[1]);
}
dup2(cmd_err_pipe[1], 2);
noncloexec(0);
noncloexec(1);
execl("/bin/sh", "sh", "-c", cmd, (void *)NULL);
@ -360,8 +344,7 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
close(to_cmd_pipe[0]);
close(from_cmd_pipe[1]);
if (cmd_err_pipe[0] >= 0)
close(cmd_err_pipe[1]);
close(cmd_err_pipe[1]);
ret->to_cmd = to_cmd_pipe[1];
ret->from_cmd = from_cmd_pipe[0];