diff --git a/client.c b/client.c index 90bd40cb..8884f637 100644 --- a/client.c +++ b/client.c @@ -48,6 +48,7 @@ enum { } client_exitreason = CLIENT_EXIT_NONE; int client_exitval; enum msgtype client_exittype; +const char *client_exitsession; int client_attached; int client_get_lock(char *); @@ -138,12 +139,24 @@ failed: const char * client_exit_message(void) { + static char msg[256]; + switch (client_exitreason) { case CLIENT_EXIT_NONE: break; case CLIENT_EXIT_DETACHED: + if (client_exitsession != NULL) { + xsnprintf(msg, sizeof msg, "detached " + "(from session %s)", client_exitsession); + return (msg); + } return ("detached"); case CLIENT_EXIT_DETACHED_HUP: + if (client_exitsession != NULL) { + xsnprintf(msg, sizeof msg, "detached and SIGHUP " + "(from session %s)", client_exitsession); + return (msg); + } return ("detached and SIGHUP"); case CLIENT_EXIT_LOST_TTY: return ("lost tty"); @@ -587,6 +600,7 @@ client_dispatch_wait(void *data0) shell_exec(data, data0); /* NOTREACHED */ case MSG_DETACH: + case MSG_DETACHKILL: client_write_server(MSG_EXITING, NULL, 0); break; case MSG_EXITED: @@ -618,11 +632,12 @@ client_dispatch_attached(void) log_debug("got %d from server", imsg.hdr.type); switch (imsg.hdr.type) { - case MSG_DETACHKILL: case MSG_DETACH: - if (datalen != 0) - fatalx("bad MSG_DETACH size"); + case MSG_DETACHKILL: + if (datalen == 0 || data[datalen - 1] != '\0') + fatalx("bad MSG_DETACH string"); + client_exitsession = xstrdup(data); client_exittype = imsg.hdr.type; if (imsg.hdr.type == MSG_DETACHKILL) client_exitreason = CLIENT_EXIT_DETACHED_HUP; diff --git a/cmd-attach-session.c b/cmd-attach-session.c index f78a89fd..e4c0b232 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -77,7 +77,9 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, continue; if (c == cmdq->client) continue; - server_write_client(c, MSG_DETACH, NULL, 0); + server_write_client(c, MSG_DETACH, + c->session->name, + strlen(c->session->name) + 1); } } @@ -138,8 +140,10 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, if (rflag) cmdq->client->flags |= CLIENT_READONLY; - if (dflag) - server_write_session(s, MSG_DETACH, NULL, 0); + if (dflag) { + server_write_session(s, MSG_DETACH, s->name, + strlen(s->name) + 1); + } update = options_get_string(&s->options, "update-environment"); environ_update(update, &cmdq->client->environ, &s->environ); diff --git a/cmd-detach-client.c b/cmd-detach-client.c index ea9e3816..f0867364 100644 --- a/cmd-detach-client.c +++ b/cmd-detach-client.c @@ -18,6 +18,8 @@ #include +#include + #include "tmux.h" /* @@ -40,8 +42,8 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct client *c, *c2; - struct session *s; - enum msgtype msgtype; + struct session *s; + enum msgtype msgtype; u_int i; if (args_has(args, 'P')) @@ -56,8 +58,10 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); - if (c != NULL && c->session == s) - server_write_client(c, msgtype, NULL, 0); + if (c == NULL || c->session != s) + continue; + server_write_client(c, msgtype, c->session->name, + strlen(c->session->name) + 1); } } else { c = cmd_find_client(cmdq, args_get(args, 't'), 0); @@ -69,10 +73,14 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq) c2 = ARRAY_ITEM(&clients, i); if (c2 == NULL || c == c2) continue; - server_write_client(c2, msgtype, NULL, 0); + server_write_client(c2, msgtype, + c2->session->name, + strlen(c2->session->name) + 1); } - } else - server_write_client(c, msgtype, NULL, 0); + } else { + server_write_client(c, msgtype, c->session->name, + strlen(c->session->name) + 1); + } } return (CMD_RETURN_STOP);