From c901f2bbb8ac7eb8d3daf15be948bc1c0da80ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 17 Mar 2018 11:28:07 +0100 Subject: [PATCH] If stdin is not a terminal pass-through its data to the session This allows to send commands to a running session: echo cowsay hi | abduco -a session See #8 for initial discussion of the feature. --- abduco.1 | 3 +++ abduco.c | 11 +++++++++-- client.c | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/abduco.1 b/abduco.1 index ffacb09..90ed721 100644 --- a/abduco.1 +++ b/abduco.1 @@ -76,6 +76,9 @@ If for some reason the domain socket representing a session is deleted, sending .BR SIGUSR1 to the server process will recreate it. + +If standard input does not refer to a terminal, its content is passed +through to the underlying session. .SH OPTIONS If no command line arguments are given all currently active sessions are printed sorted by their respective creation date. Lines starting with an diff --git a/abduco.c b/abduco.c index 3e01ca8..4756342 100644 --- a/abduco.c +++ b/abduco.c @@ -120,7 +120,7 @@ typedef struct { static Server server = { .running = true, .exit_status = -1, .host = "@localhost" }; static Client client; static struct termios orig_term, cur_term; -static bool has_term, alternate_buffer, quiet; +static bool has_term, alternate_buffer, quiet, passthrough; static struct sockaddr_un sockaddr = { .sun_family = AF_UNIX, @@ -588,6 +588,8 @@ int main(int argc, char *argv[]) { server.name = basename(argv[0]); gethostname(server.host+1, sizeof(server.host) - 1); + passthrough = !isatty(STDIN_FILENO); + while ((opt = getopt(argc, argv, "aAclne:fqrv")) != -1) { switch (opt) { case 'a': @@ -623,6 +625,11 @@ int main(int argc, char *argv[]) { } } + if (passthrough) { + quiet = true; + client.flags |= CLIENT_LOWPRIORITY; + } + /* collect the session name if trailing args */ if (optind < argc) server.session_name = argv[optind]; @@ -638,7 +645,7 @@ int main(int argc, char *argv[]) { if (!action || !server.session_name) usage(); - if (tcgetattr(STDIN_FILENO, &orig_term) != -1) { + if (!passthrough && tcgetattr(STDIN_FILENO, &orig_term) != -1) { server.term = orig_term; has_term = true; } diff --git a/client.c b/client.c index 0e6f7a1..3d6d82b 100644 --- a/client.c +++ b/client.c @@ -100,7 +100,8 @@ static int client_mainloop(void) { if (client_recv_packet(&pkt)) { switch (pkt.type) { case MSG_CONTENT: - write_all(STDOUT_FILENO, pkt.u.msg, pkt.len); + if (!passthrough) + write_all(STDOUT_FILENO, pkt.u.msg, pkt.len); break; case MSG_RESIZE: client.need_resize = true;