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 \ ... "" ]
.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

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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);
}