Send exit status back to client

This commit is contained in:
Marc André Tanner 2014-02-27 17:17:48 +01:00
parent 12287e473d
commit 006c93a9d1
4 changed files with 27 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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