abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit eccf9fd16e39fe676af58cdf16b8b5c5720c6f97
parent 1fbc4690e5955848dddb98f8f86203c545ad60a7
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat, 22 Mar 2014 17:27:59 +0100

Introduce read only sessions (-r option)

Based on a patch from Lars Kellogg-Stedman.

Diffstat:
abduco.1 | 5+++++
abduco.c | 10++++++++--
client.c | 6+++---
server.c | 4+++-
4 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/abduco.1 b/abduco.1 @@ -12,6 +12,7 @@ abduco .RI [ args \ ... "" ] .br .B abduco +.RB [ \-r ] .RB [ \-e .IR detachkey ] .RB \-n @@ -28,6 +29,7 @@ abduco .RI [ args \ ... "" ] .br .B abduco +.RB [ \-r ] .RB [ \-e .IR detachkey ] .RB \-a @@ -74,6 +76,9 @@ indicate that at least one client is connected. .B \-v Print version information to standard output and exit. .TP +.B \-r +Readonly session, i.e. no user input is ignored. +.TP .BI \-e \ detachkey Set the key to detach which by default is set to CTRL+\\ i.e. ^\\ to detachkey. .TP diff --git a/abduco.c b/abduco.c @@ -74,6 +74,7 @@ typedef struct { char msg[BUFSIZ]; struct winsize ws; int i; + bool b; } u; } Packet; @@ -87,6 +88,7 @@ struct Client { STATE_DISCONNECTED, } state; bool need_resize; + bool readonly; Client *next; }; @@ -104,6 +106,7 @@ typedef struct { } Server; static Server server = { .running = true, .exit_status = -1 }; +static Client client; static struct termios orig_term, cur_term; bool has_term; @@ -202,7 +205,7 @@ static void die(const char *s) { } static void usage() { - fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-e detachkey] name command\n"); + fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-r] [-e detachkey] name command\n"); exit(EXIT_FAILURE); } @@ -432,6 +435,9 @@ int main(int argc, char *argv[]) { *esc = CTRL(esc[1]); KEY_DETACH = *esc; break; + case 'r': + client.readonly = true; + break; case 'v': puts("abduco-"VERSION" © 2013-2014 Marc André Tanner"); exit(EXIT_SUCCESS); @@ -446,7 +452,7 @@ int main(int argc, char *argv[]) { cmd[0] = "dvtm"; } - if (!action || !server.session_name) + if (!action || !server.session_name || ((action == 'c' || action == 'A') && client.readonly)) usage(); if (tcgetattr(STDIN_FILENO, &orig_term) != -1) { diff --git a/client.c b/client.c @@ -1,5 +1,3 @@ -static Client client; - static void client_sigwinch_handler(int sig) { client.need_resize = true; } @@ -36,6 +34,8 @@ static void client_restore_terminal() { static int client_mainloop() { client.need_resize = true; + Packet pkt = { .type = MSG_ATTACH, .u = { .b = client.readonly }, .len = sizeof(pkt.u.b) }; + client_send_packet(&pkt); while (server.running) { fd_set fds; FD_ZERO(&fds); @@ -92,7 +92,7 @@ static int client_mainloop() { pkt.len = 0; client_send_packet(&pkt); return -1; - } else { + } else if (!client.readonly) { client_send_packet(&pkt); } } diff --git a/server.c b/server.c @@ -206,10 +206,12 @@ static void server_mainloop() { server_write_pty(&client_packet); break; case MSG_ATTACH: + c->readonly = client_packet.u.b; + break; case MSG_RESIZE: c->state = STATE_ATTACHED; case MSG_REDRAW: - if (client_packet.type == MSG_REDRAW || c == server.clients) { + if (!c->readonly && (client_packet.type == MSG_REDRAW || c == server.clients)) { debug("server-ioct: TIOCSWINSZ\n"); ioctl(server.pty, TIOCSWINSZ, &client_packet.u.ws); }