abduco

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

commit 006c93a9d1a4398c7949bf6d0e92e3d3ad63f2d3
parent 12287e473dd8640396e585a22593d93bf16f936f
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 27 Feb 2014 17:17:48 +0100

Send exit status back to client

Diffstat:
abduco.c | 14++++++++------
client.c | 5++++-
debug.c | 3+++
server.c | 14++++++++++++--
4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/abduco.c b/abduco.c @@ -64,6 +64,7 @@ enum PacketType { MSG_DETACH = 2, MSG_RESIZE = 3, MSG_REDRAW = 4, + MSG_EXIT = 5, }; typedef struct { @@ -327,13 +328,14 @@ static bool attach_session(const char *name) { tcsetattr(0, TCSADRAIN, &cur_term); client_clear_screen(); - switch (client_mainloop()) { - case -1: + int status = client_mainloop(); + if (status == -1) { info("detached"); - break; - case EIO: - info("exited due to I/O errors: %s", strerror(errno)); - break; + } else if (status == -EIO) { + info("exited due to I/O errors"); + } else { + info("session terminated with exit status %d", status); + exit(status); } return true; diff --git a/client.c b/client.c @@ -116,6 +116,8 @@ static int client_mainloop() { case MSG_CONTENT: write_all(STDOUT_FILENO, pkt.u.msg, pkt.len); break; + case MSG_EXIT: + return pkt.u.i; } } } @@ -126,6 +128,7 @@ static int client_mainloop() { if (len == -1 && errno != EAGAIN && errno != EINTR) die("client-stdin"); if (len > 0) { + debug("client-stdin: %c", pkt.u.msg[0]); pkt.len = len; if (pkt.u.msg[0] == KEY_REDRAW) { client.need_resize = true; @@ -141,5 +144,5 @@ static int client_mainloop() { } } - return 0; + return -EIO; } diff --git a/debug.c b/debug.c @@ -30,6 +30,9 @@ static void print_packet(const char *prefix, Packet *pkt) { case MSG_REDRAW: s = "REDRAW"; break; + case MSG_EXIT: + s = "EXIT"; + break; } if (pkt->type == MSG_CONTENT) { diff --git a/server.c b/server.c @@ -284,10 +284,20 @@ static void server_mainloop() { } if (clients_ready && server.clients) { - if (server.running) + if (server.running) { FD_SET_MAX(server.pty, &new_readfds, new_fdmax); - else + } else if (server.exit_status == INT_MAX) { break; + } else if (server.exit_status != -1) { + Packet pkt = { .type = MSG_EXIT, .len = sizeof(int), .u.i = server.exit_status }; + server.pty_output = pkt; + for (Client *c = server.clients; c; c = c->next) { + server_place_packet(c, &server.pty_output); + c->last_activity = now; + FD_SET_MAX(c->socket, &new_writefds, new_fdmax); + } + server.exit_status = INT_MAX; + } } if (FD_ISSET(server.pty, &writefds)) {