Introduce read only sessions (-r option)

Based on a patch from Lars Kellogg-Stedman.
This commit is contained in:
Marc André Tanner 2014-03-22 17:27:59 +01:00
parent 1fbc4690e5
commit eccf9fd16e
4 changed files with 19 additions and 6 deletions

View File

@ -12,6 +12,7 @@ abduco
.RI [ args \ ... "" ] .RI [ args \ ... "" ]
.br .br
.B abduco .B abduco
.RB [ \-r ]
.RB [ \-e .RB [ \-e
.IR detachkey ] .IR detachkey ]
.RB \-n .RB \-n
@ -28,6 +29,7 @@ abduco
.RI [ args \ ... "" ] .RI [ args \ ... "" ]
.br .br
.B abduco .B abduco
.RB [ \-r ]
.RB [ \-e .RB [ \-e
.IR detachkey ] .IR detachkey ]
.RB \-a .RB \-a
@ -74,6 +76,9 @@ indicate that at least one client is connected.
.B \-v .B \-v
Print version information to standard output and exit. Print version information to standard output and exit.
.TP .TP
.B \-r
Readonly session, i.e. no user input is ignored.
.TP
.BI \-e \ detachkey .BI \-e \ detachkey
Set the key to detach which by default is set to CTRL+\\ i.e. ^\\ to detachkey. Set the key to detach which by default is set to CTRL+\\ i.e. ^\\ to detachkey.
.TP .TP

View File

@ -74,6 +74,7 @@ typedef struct {
char msg[BUFSIZ]; char msg[BUFSIZ];
struct winsize ws; struct winsize ws;
int i; int i;
bool b;
} u; } u;
} Packet; } Packet;
@ -87,6 +88,7 @@ struct Client {
STATE_DISCONNECTED, STATE_DISCONNECTED,
} state; } state;
bool need_resize; bool need_resize;
bool readonly;
Client *next; Client *next;
}; };
@ -104,6 +106,7 @@ typedef struct {
} Server; } Server;
static Server server = { .running = true, .exit_status = -1 }; static Server server = { .running = true, .exit_status = -1 };
static Client client;
static struct termios orig_term, cur_term; static struct termios orig_term, cur_term;
bool has_term; bool has_term;
@ -202,7 +205,7 @@ static void die(const char *s) {
} }
static void usage() { 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); exit(EXIT_FAILURE);
} }
@ -432,6 +435,9 @@ int main(int argc, char *argv[]) {
*esc = CTRL(esc[1]); *esc = CTRL(esc[1]);
KEY_DETACH = *esc; KEY_DETACH = *esc;
break; break;
case 'r':
client.readonly = true;
break;
case 'v': case 'v':
puts("abduco-"VERSION" © 2013-2014 Marc André Tanner"); puts("abduco-"VERSION" © 2013-2014 Marc André Tanner");
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
@ -446,7 +452,7 @@ int main(int argc, char *argv[]) {
cmd[0] = "dvtm"; cmd[0] = "dvtm";
} }
if (!action || !server.session_name) if (!action || !server.session_name || ((action == 'c' || action == 'A') && client.readonly))
usage(); usage();
if (tcgetattr(STDIN_FILENO, &orig_term) != -1) { if (tcgetattr(STDIN_FILENO, &orig_term) != -1) {

View File

@ -1,5 +1,3 @@
static Client client;
static void client_sigwinch_handler(int sig) { static void client_sigwinch_handler(int sig) {
client.need_resize = true; client.need_resize = true;
} }
@ -36,6 +34,8 @@ static void client_restore_terminal() {
static int client_mainloop() { static int client_mainloop() {
client.need_resize = true; 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) { while (server.running) {
fd_set fds; fd_set fds;
FD_ZERO(&fds); FD_ZERO(&fds);
@ -92,7 +92,7 @@ static int client_mainloop() {
pkt.len = 0; pkt.len = 0;
client_send_packet(&pkt); client_send_packet(&pkt);
return -1; return -1;
} else { } else if (!client.readonly) {
client_send_packet(&pkt); client_send_packet(&pkt);
} }
} }

View File

@ -206,10 +206,12 @@ static void server_mainloop() {
server_write_pty(&client_packet); server_write_pty(&client_packet);
break; break;
case MSG_ATTACH: case MSG_ATTACH:
c->readonly = client_packet.u.b;
break;
case MSG_RESIZE: case MSG_RESIZE:
c->state = STATE_ATTACHED; c->state = STATE_ATTACHED;
case MSG_REDRAW: 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"); debug("server-ioct: TIOCSWINSZ\n");
ioctl(server.pty, TIOCSWINSZ, &client_packet.u.ws); ioctl(server.pty, TIOCSWINSZ, &client_packet.u.ws);
} }