mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00: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:
parent
361efee621
commit
e230751853
13
logging.c
13
logging.c
@ -219,20 +219,11 @@ void logtraffic(LogContext *ctx, unsigned char c, int logmode)
|
||||
}
|
||||
|
||||
/*
|
||||
* Log an Event Log entry. Used in SSH packet logging mode; this is
|
||||
* also as convenient a place as any to put the output of Event Log
|
||||
* entries to stderr when a command-line tool is in verbose mode.
|
||||
* (In particular, this is a better place to put it than in the
|
||||
* front ends, because it only has to be done once for all
|
||||
* platforms. Platforms which don't have a meaningful stderr can
|
||||
* just avoid defining FLAG_STDERR.
|
||||
* Log an Event Log entry. Used in SSH packet logging mode, to copy
|
||||
* the Event Log entries into the same log file as the packet data.
|
||||
*/
|
||||
void log_eventlog(LogContext *ctx, const char *event)
|
||||
{
|
||||
if ((flags & FLAG_STDERR) && (flags & FLAG_VERBOSE)) {
|
||||
fprintf(stderr, "%s\n", event);
|
||||
fflush(stderr);
|
||||
}
|
||||
/* If we don't have a context yet (eg winnet.c init) then skip entirely */
|
||||
if (!ctx)
|
||||
return;
|
||||
|
2
pscp.c
2
pscp.c
@ -2283,7 +2283,7 @@ int psftp_main(int argc, char *argv[])
|
||||
|
||||
default_protocol = PROT_TELNET;
|
||||
|
||||
flags = FLAG_STDERR
|
||||
flags = 0
|
||||
#ifdef FLAG_SYNCAGENT
|
||||
| FLAG_SYNCAGENT
|
||||
#endif
|
||||
|
2
psftp.c
2
psftp.c
@ -2872,7 +2872,7 @@ int psftp_main(int argc, char *argv[])
|
||||
int modeflags = 0;
|
||||
char *batchfile = NULL;
|
||||
|
||||
flags = FLAG_STDERR | FLAG_INTERACTIVE
|
||||
flags = FLAG_INTERACTIVE
|
||||
#ifdef FLAG_SYNCAGENT
|
||||
| FLAG_SYNCAGENT
|
||||
#endif
|
||||
|
7
putty.h
7
putty.h
@ -520,10 +520,6 @@ extern const char *const appname;
|
||||
*
|
||||
* FLAG_VERBOSE is set when the user requests verbose details.
|
||||
*
|
||||
* FLAG_STDERR is set in command-line applications (which have a
|
||||
* functioning stderr that it makes sense to write to) and not in
|
||||
* GUI applications (which don't).
|
||||
*
|
||||
* FLAG_INTERACTIVE is set when a full interactive shell session is
|
||||
* being run, _either_ because no remote command has been provided
|
||||
* _or_ because the application is GUI and can't run non-
|
||||
@ -538,8 +534,7 @@ extern const char *const appname;
|
||||
* avoid collision.
|
||||
*/
|
||||
#define FLAG_VERBOSE 0x0001
|
||||
#define FLAG_STDERR 0x0002
|
||||
#define FLAG_INTERACTIVE 0x0004
|
||||
#define FLAG_INTERACTIVE 0x0002
|
||||
GLOBAL int flags;
|
||||
|
||||
/*
|
||||
|
17
ssh.c
17
ssh.c
@ -704,21 +704,9 @@ static int ssh_rportcmp_ssh2(void *av, void *bv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void c_write_stderr(int trusted, const void *vbuf, int len)
|
||||
{
|
||||
const char *buf = (const char *)vbuf;
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
if (buf[i] != '\r' && (trusted || buf[i] == '\n' || (buf[i] & 0x60)))
|
||||
fputc(buf[i], stderr);
|
||||
}
|
||||
|
||||
static void c_write(Ssh ssh, const void *buf, int len)
|
||||
{
|
||||
if (flags & FLAG_STDERR)
|
||||
c_write_stderr(1, buf, len);
|
||||
else
|
||||
from_backend(ssh->frontend, 1, buf, len);
|
||||
from_backend(ssh->frontend, 1, buf, len);
|
||||
}
|
||||
|
||||
static void c_write_str(Ssh ssh, const char *buf)
|
||||
@ -1866,8 +1854,7 @@ static void do_ssh1_login(void *vctx)
|
||||
{
|
||||
char *userlog = dupprintf("Sent username \"%s\"", ssh->username);
|
||||
logevent(userlog);
|
||||
if (flags & FLAG_INTERACTIVE &&
|
||||
(!((flags & FLAG_STDERR) && (flags & FLAG_VERBOSE)))) {
|
||||
if ((flags & FLAG_VERBOSE) || (flags & FLAG_INTERACTIVE)) {
|
||||
c_write_str(ssh, userlog);
|
||||
c_write_str(ssh, "\r\n");
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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 |
|
||||
|
@ -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];
|
||||
|
@ -342,6 +342,10 @@ void console_provide_logctx(LogContext *logctx)
|
||||
|
||||
void logevent(Frontend *frontend, const char *string)
|
||||
{
|
||||
if (flags & FLAG_VERBOSE) {
|
||||
fprintf(stderr, "%s\n", string);
|
||||
fflush(stderr);
|
||||
}
|
||||
log_eventlog(console_logctx, string);
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ int main(int argc, char **argv)
|
||||
default_protocol = PROT_SSH;
|
||||
default_port = 22;
|
||||
|
||||
flags = FLAG_STDERR;
|
||||
flags = 0;
|
||||
cmdline_tooltype |=
|
||||
(TOOLTYPE_HOST_ARG |
|
||||
TOOLTYPE_HOST_ARG_CAN_BE_SESSION |
|
||||
|
@ -66,23 +66,15 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
|
||||
return ret;
|
||||
}
|
||||
|
||||
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. */
|
||||
us_from_cmd_err = cmd_err_to_us = NULL;
|
||||
} else {
|
||||
/* If we don't have a sensible stderr, we should catch the
|
||||
* proxy command's standard error to put in our event log. */
|
||||
if (!CreatePipe(&us_from_cmd_err, &cmd_err_to_us, &sa, 0)) {
|
||||
Socket ret = new_error_socket
|
||||
("Unable to create pipes for proxy command", plug);
|
||||
sfree(cmd);
|
||||
CloseHandle(us_from_cmd);
|
||||
CloseHandle(cmd_to_us);
|
||||
CloseHandle(us_to_cmd);
|
||||
CloseHandle(cmd_from_us);
|
||||
return ret;
|
||||
}
|
||||
if (!CreatePipe(&us_from_cmd_err, &cmd_err_to_us, &sa, 0)) {
|
||||
Socket ret = new_error_socket
|
||||
("Unable to create pipes for proxy command", plug);
|
||||
sfree(cmd);
|
||||
CloseHandle(us_from_cmd);
|
||||
CloseHandle(cmd_to_us);
|
||||
CloseHandle(us_to_cmd);
|
||||
CloseHandle(cmd_from_us);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SetHandleInformation(us_to_cmd, HANDLE_FLAG_INHERIT, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user