mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-04 21:12:47 -05:00
In GUI PuTTY, log standard error from local proxy commands.
On both Unix and Windows, we now redirect the local proxy command's standard error into a third pipe; data received from that pipe is broken up at newlines and logged in the Event Log. So if the proxy command emits any error messages in the course of failing to connect to something, you now have a fighting chance of finding out what went wrong. This feature is disabled in command-line tools like PSFTP and Plink, on the basis that in that situation it seems more likely that the user would expect standard-error output to go to the ordinary standard error in the ordinary way. Only GUI PuTTY catches it and logs it like this, because it either doesn't have a standard error at all (on Windows) or is likely to be pointing it at some completely unhelpful session log file (under X).
This commit is contained in:
@ -22,7 +22,9 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
|
||||
Plug plug, Conf *conf)
|
||||
{
|
||||
char *cmd;
|
||||
HANDLE us_to_cmd, us_from_cmd, cmd_to_us, cmd_from_us;
|
||||
HANDLE us_to_cmd, cmd_from_us;
|
||||
HANDLE us_from_cmd, cmd_to_us;
|
||||
HANDLE us_from_cmd_err, cmd_err_to_us;
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
@ -64,8 +66,25 @@ 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);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
SetHandleInformation(us_to_cmd, HANDLE_FLAG_INHERIT, 0);
|
||||
SetHandleInformation(us_from_cmd, HANDLE_FLAG_INHERIT, 0);
|
||||
if (us_from_cmd_err != NULL)
|
||||
SetHandleInformation(us_from_cmd_err, HANDLE_FLAG_INHERIT, 0);
|
||||
|
||||
si.cb = sizeof(si);
|
||||
si.lpReserved = NULL;
|
||||
@ -76,7 +95,7 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
|
||||
si.lpReserved2 = NULL;
|
||||
si.hStdInput = cmd_from_us;
|
||||
si.hStdOutput = cmd_to_us;
|
||||
si.hStdError = NULL;
|
||||
si.hStdError = cmd_err_to_us;
|
||||
CreateProcess(NULL, cmd, NULL, NULL, TRUE,
|
||||
CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,
|
||||
NULL, NULL, &si, &pi);
|
||||
@ -88,5 +107,9 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
|
||||
CloseHandle(cmd_from_us);
|
||||
CloseHandle(cmd_to_us);
|
||||
|
||||
return make_handle_socket(us_to_cmd, us_from_cmd, plug, FALSE);
|
||||
if (cmd_err_to_us != NULL)
|
||||
CloseHandle(cmd_err_to_us);
|
||||
|
||||
return make_handle_socket(us_to_cmd, us_from_cmd, us_from_cmd_err,
|
||||
plug, FALSE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user