Show session name in detached message. Requested by somebody a few

months ago who didn't bother testing it. But it works for me anyway.
pull/1/head
nicm 2013-10-10 12:28:08 +00:00
parent b8b85fbb0c
commit 7936ce3874
3 changed files with 40 additions and 13 deletions

View File

@ -48,6 +48,7 @@ enum {
} client_exitreason = CLIENT_EXIT_NONE; } client_exitreason = CLIENT_EXIT_NONE;
int client_exitval; int client_exitval;
enum msgtype client_exittype; enum msgtype client_exittype;
const char *client_exitsession;
int client_attached; int client_attached;
int client_get_lock(char *); int client_get_lock(char *);
@ -138,12 +139,24 @@ failed:
const char * const char *
client_exit_message(void) client_exit_message(void)
{ {
static char msg[256];
switch (client_exitreason) { switch (client_exitreason) {
case CLIENT_EXIT_NONE: case CLIENT_EXIT_NONE:
break; break;
case CLIENT_EXIT_DETACHED: case CLIENT_EXIT_DETACHED:
if (client_exitsession != NULL) {
xsnprintf(msg, sizeof msg, "detached "
"(from session %s)", client_exitsession);
return (msg);
}
return ("detached"); return ("detached");
case CLIENT_EXIT_DETACHED_HUP: 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"); return ("detached and SIGHUP");
case CLIENT_EXIT_LOST_TTY: case CLIENT_EXIT_LOST_TTY:
return ("lost tty"); return ("lost tty");
@ -582,6 +595,7 @@ client_dispatch_wait(void *data0)
shell_exec(data, data0); shell_exec(data, data0);
/* NOTREACHED */ /* NOTREACHED */
case MSG_DETACH: case MSG_DETACH:
case MSG_DETACHKILL:
client_write_server(MSG_EXITING, NULL, 0); client_write_server(MSG_EXITING, NULL, 0);
break; break;
case MSG_EXITED: case MSG_EXITED:
@ -613,11 +627,12 @@ client_dispatch_attached(void)
log_debug("got %d from server", imsg.hdr.type); log_debug("got %d from server", imsg.hdr.type);
switch (imsg.hdr.type) { switch (imsg.hdr.type) {
case MSG_DETACHKILL:
case MSG_DETACH: case MSG_DETACH:
if (datalen != 0) case MSG_DETACHKILL:
fatalx("bad MSG_DETACH size"); if (datalen == 0 || data[datalen - 1] != '\0')
fatalx("bad MSG_DETACH string");
client_exitsession = xstrdup(data);
client_exittype = imsg.hdr.type; client_exittype = imsg.hdr.type;
if (imsg.hdr.type == MSG_DETACHKILL) if (imsg.hdr.type == MSG_DETACHKILL)
client_exitreason = CLIENT_EXIT_DETACHED_HUP; client_exitreason = CLIENT_EXIT_DETACHED_HUP;

View File

@ -77,7 +77,9 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
continue; continue;
if (c == cmdq->client) if (c == cmdq->client)
continue; 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) if (rflag)
cmdq->client->flags |= CLIENT_READONLY; cmdq->client->flags |= CLIENT_READONLY;
if (dflag) if (dflag) {
server_write_session(s, MSG_DETACH, NULL, 0); server_write_session(s, MSG_DETACH, s->name,
strlen(s->name) + 1);
}
update = options_get_string(&s->options, "update-environment"); update = options_get_string(&s->options, "update-environment");
environ_update(update, &cmdq->client->environ, &s->environ); environ_update(update, &cmdq->client->environ, &s->environ);

View File

@ -18,6 +18,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <string.h>
#include "tmux.h" #include "tmux.h"
/* /*
@ -40,8 +42,8 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
{ {
struct args *args = self->args; struct args *args = self->args;
struct client *c, *c2; struct client *c, *c2;
struct session *s; struct session *s;
enum msgtype msgtype; enum msgtype msgtype;
u_int i; u_int i;
if (args_has(args, 'P')) 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++) { for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i); c = ARRAY_ITEM(&clients, i);
if (c != NULL && c->session == s) if (c == NULL || c->session != s)
server_write_client(c, msgtype, NULL, 0); continue;
server_write_client(c, msgtype, c->session->name,
strlen(c->session->name) + 1);
} }
} else { } else {
c = cmd_find_client(cmdq, args_get(args, 't'), 0); 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); c2 = ARRAY_ITEM(&clients, i);
if (c2 == NULL || c == c2) if (c2 == NULL || c == c2)
continue; continue;
server_write_client(c2, msgtype, NULL, 0); server_write_client(c2, msgtype,
c2->session->name,
strlen(c2->session->name) + 1);
} }
} else } else {
server_write_client(c, msgtype, NULL, 0); server_write_client(c, msgtype, c->session->name,
strlen(c->session->name) + 1);
}
} }
return (CMD_RETURN_STOP); return (CMD_RETURN_STOP);