summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2013-10-10 12:28:08 +0000
committernicm <nicm>2013-10-10 12:28:08 +0000
commit7936ce38749a4751120c856a112ee85122df612c (patch)
tree4d7fcda69120a584a3723b91df1de09ffa30a79f
parentb8b85fbb0c6cf4e9a3fa650ec7dc5036a1b0b01a (diff)
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.
-rw-r--r--client.c21
-rw-r--r--cmd-attach-session.c10
-rw-r--r--cmd-detach-client.c22
3 files changed, 40 insertions, 13 deletions
diff --git a/client.c b/client.c
index e1bd47c2..0d57b793 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");
@@ -582,6 +595,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:
@@ -613,11 +627,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 8dcc5997..c71e6f1f 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 fc80499c..82001bee 100644
--- a/cmd-detach-client.c
+++ b/cmd-detach-client.c
@@ -18,6 +18,8 @@
#include <sys/types.h>
+#include <string.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 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);