abduco

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

commit 4b4c08457f83815cbb58e29c63155b41b56c7620
parent 9e29a968d8edf4ed5005bf962020ec1b9e3dcb8f
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 24 Jun 2014 10:55:44 +0200

Make client termination more robust by explicitly sending exit messages

Diffstat:
client.c | 3+++
server.c | 37+++++++++++++++++++------------------
2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/client.c b/client.c @@ -77,6 +77,8 @@ static int client_mainloop() { client.need_resize = true; break; case MSG_EXIT: + client_send_packet(&pkt); + close(server.socket); return pkt.u.i; } } @@ -96,6 +98,7 @@ static int client_mainloop() { pkt.type = MSG_DETACH; pkt.len = 0; client_send_packet(&pkt); + close(server.socket); return -1; } else if (!client.readonly) { client_send_packet(&pkt); diff --git a/server.c b/server.c @@ -186,23 +186,6 @@ static void server_mainloop() { pty_data = server_read_pty(&server_packet); for (Client **prev_next = &server.clients, *c = server.clients; c;) { - if (c->state == STATE_DISCONNECTED) { - bool first = (c == server.clients); - Client *t = c->next; - client_free(c); - *prev_next = c = t; - if (first && server.clients) { - Packet pkt = { - .type = MSG_RESIZE, - .len = 0, - }; - server_send_packet(server.clients, &pkt); - } else if (!server.clients) { - server_mark_socket_exec(false, true); - } - continue; - } - if (FD_ISSET(c->socket, &readfds) && server_recv_packet(c, &client_packet)) { switch (client_packet.type) { case MSG_CONTENT: @@ -221,13 +204,31 @@ static void server_mainloop() { kill(-server.pid, SIGWINCH); break; case MSG_DETACH: - c->state = STATE_DETACHED; + case MSG_EXIT: + c->state = STATE_DISCONNECTED; break; default: /* ignore package */ break; } } + if (c->state == STATE_DISCONNECTED) { + bool first = (c == server.clients); + Client *t = c->next; + client_free(c); + *prev_next = c = t; + if (first && server.clients) { + Packet pkt = { + .type = MSG_RESIZE, + .len = 0, + }; + server_send_packet(server.clients, &pkt); + } else if (!server.clients) { + server_mark_socket_exec(false, true); + } + continue; + } + FD_SET_MAX(c->socket, &new_readfds, new_fdmax); if (pty_data)