Pass terminal data on socket on Cygwin platforms

On Cygwin and MSYS2 use a controlling pty for the server client handler
instead of passing a file descriptor over the socket which is not
possible on Cygwin platforms.

Attach an event to STDIN on the client, passing data from it to the
server and attach an event to the pty out_fd on the server client
handler and pass data from it to the client.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover
2024-07-25 21:55:40 +00:00
parent 8d6eb4be40
commit 80e6621298
6 changed files with 78 additions and 2 deletions

View File

@@ -244,6 +244,9 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
char *line = NULL, **caps = NULL, *cause;
u_int ncaps = 0;
struct args_value *values;
#ifdef TTY_OVER_SOCKET
struct tty* tty = xmalloc(sizeof *tty);
#endif
/* Set up the initial command. */
if (shell_command != NULL) {
@@ -397,6 +400,10 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
} else if (msg == MSG_SHELL)
proc_send(client_peer, msg, -1, NULL, 0);
#ifdef TTY_OVER_SOCKET
tty_attach_stdin_to_socket(tty, client_peer);
#endif
/* Start main loop. */
proc_loop(client_proc, NULL);
@@ -474,12 +481,14 @@ client_send_identify(const char *ttynam, const char *termname, char **caps,
caps[i], strlen(caps[i]) + 1);
}
#ifndef TTY_OVER_SOCKET
if ((fd = dup(STDIN_FILENO)) == -1)
fatal("dup failed");
proc_send(client_peer, MSG_IDENTIFY_STDIN, fd, NULL, 0);
if ((fd = dup(STDOUT_FILENO)) == -1)
fatal("dup failed");
proc_send(client_peer, MSG_IDENTIFY_STDOUT, fd, NULL, 0);
#endif
pid = getpid();
proc_send(client_peer, MSG_IDENTIFY_CLIENTPID, -1, &pid, sizeof pid);
@@ -805,5 +814,10 @@ client_dispatch_attached(struct imsg *imsg)
system(data);
proc_send(client_peer, MSG_UNLOCK, -1, NULL, 0);
break;
#ifdef TTY_OVER_SOCKET
case MSG_TTY_READ:
write(STDOUT_FILENO, data, datalen);
break;
#endif
}
}