1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

New facility, platform_start_subprocess.

We already have the ability to start a subprocess and hook it up to a
Socket, for running local proxy commands. Now the same facility is
available as an auxiliary feature, so that a backend can start another
subcommand for a different purpose, and make a separate Socket to
communicate with it.

Just like the local proxy system, this facility captures the
subprocess's stderr, and passes it back to the caller via plug_log. To
make that not look silly, I had to add a system where the "proxy:"
prefix on the usual plug_log messages is reconfigurable, and when you
call platform_start_subprocess(), you get to pass the prefix you want
to use in this case.
This commit is contained in:
Simon Tatham
2022-08-22 18:46:32 +01:00
parent a92aeca111
commit eec350c38b
11 changed files with 96 additions and 2 deletions

View File

@ -388,6 +388,13 @@ Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
return &hs->sock;
}
void handle_socket_set_psb_prefix(Socket *s, const char *prefix)
{
HandleSocket *hs = container_of(s, HandleSocket, sock);
assert(hs->sock.vt == &HandleSocket_sockvt);
psb_set_prefix(&hs->psb, prefix);
}
static void sk_handle_deferred_close(Socket *s)
{
HandleSocket *hs = container_of(s, HandleSocket, sock);

View File

@ -98,3 +98,21 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
local_proxy_opener_set_socket(opener, socket);
return socket;
}
Socket *platform_start_subprocess(const char *cmd, Plug *plug,
const char *prefix)
{
Socket *socket = make_deferred_handle_socket(
null_deferred_socket_opener(),
sk_nonamelookup("<local command>"), 0, plug);
char *err = platform_setup_local_proxy(socket, cmd);
handle_socket_set_psb_prefix(socket, prefix);
if (err) {
sk_close(socket);
socket = new_error_socket_fmt(plug, "%s", err);
sfree(err);
}
return socket;
}

View File

@ -354,6 +354,7 @@ Socket *make_deferred_handle_socket(DeferredSocketOpener *opener,
SockAddr *addr, int port, Plug *plug);
void setup_handle_socket(Socket *s, HANDLE send_H, HANDLE recv_H,
HANDLE stderr_H, bool overlapped);
void handle_socket_set_psb_prefix(Socket *s, const char *prefix);
Socket *new_named_pipe_client(const char *pipename, Plug *plug); /* winnpc */
Socket *new_named_pipe_listener(const char *pipename, Plug *plug); /* winnps */