forked from github/abduco
Send exit status back to client
This commit is contained in:
parent
12287e473d
commit
006c93a9d1
14
abduco.c
14
abduco.c
|
|
@ -64,6 +64,7 @@ enum PacketType {
|
||||||
MSG_DETACH = 2,
|
MSG_DETACH = 2,
|
||||||
MSG_RESIZE = 3,
|
MSG_RESIZE = 3,
|
||||||
MSG_REDRAW = 4,
|
MSG_REDRAW = 4,
|
||||||
|
MSG_EXIT = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -327,13 +328,14 @@ static bool attach_session(const char *name) {
|
||||||
tcsetattr(0, TCSADRAIN, &cur_term);
|
tcsetattr(0, TCSADRAIN, &cur_term);
|
||||||
|
|
||||||
client_clear_screen();
|
client_clear_screen();
|
||||||
switch (client_mainloop()) {
|
int status = client_mainloop();
|
||||||
case -1:
|
if (status == -1) {
|
||||||
info("detached");
|
info("detached");
|
||||||
break;
|
} else if (status == -EIO) {
|
||||||
case EIO:
|
info("exited due to I/O errors");
|
||||||
info("exited due to I/O errors: %s", strerror(errno));
|
} else {
|
||||||
break;
|
info("session terminated with exit status %d", status);
|
||||||
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
5
client.c
5
client.c
|
|
@ -116,6 +116,8 @@ static int client_mainloop() {
|
||||||
case MSG_CONTENT:
|
case MSG_CONTENT:
|
||||||
write_all(STDOUT_FILENO, pkt.u.msg, pkt.len);
|
write_all(STDOUT_FILENO, pkt.u.msg, pkt.len);
|
||||||
break;
|
break;
|
||||||
|
case MSG_EXIT:
|
||||||
|
return pkt.u.i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,6 +128,7 @@ static int client_mainloop() {
|
||||||
if (len == -1 && errno != EAGAIN && errno != EINTR)
|
if (len == -1 && errno != EAGAIN && errno != EINTR)
|
||||||
die("client-stdin");
|
die("client-stdin");
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
|
debug("client-stdin: %c", pkt.u.msg[0]);
|
||||||
pkt.len = len;
|
pkt.len = len;
|
||||||
if (pkt.u.msg[0] == KEY_REDRAW) {
|
if (pkt.u.msg[0] == KEY_REDRAW) {
|
||||||
client.need_resize = true;
|
client.need_resize = true;
|
||||||
|
|
@ -141,5 +144,5 @@ static int client_mainloop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
debug.c
3
debug.c
|
|
@ -30,6 +30,9 @@ static void print_packet(const char *prefix, Packet *pkt) {
|
||||||
case MSG_REDRAW:
|
case MSG_REDRAW:
|
||||||
s = "REDRAW";
|
s = "REDRAW";
|
||||||
break;
|
break;
|
||||||
|
case MSG_EXIT:
|
||||||
|
s = "EXIT";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkt->type == MSG_CONTENT) {
|
if (pkt->type == MSG_CONTENT) {
|
||||||
|
|
|
||||||
14
server.c
14
server.c
|
|
@ -284,10 +284,20 @@ static void server_mainloop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clients_ready && server.clients) {
|
if (clients_ready && server.clients) {
|
||||||
if (server.running)
|
if (server.running) {
|
||||||
FD_SET_MAX(server.pty, &new_readfds, new_fdmax);
|
FD_SET_MAX(server.pty, &new_readfds, new_fdmax);
|
||||||
else
|
} else if (server.exit_status == INT_MAX) {
|
||||||
break;
|
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)) {
|
if (FD_ISSET(server.pty, &writefds)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue