aboutsummaryrefslogtreecommitdiff
path: root/server-client.c
diff options
context:
space:
mode:
authornicm <nicm>2017-04-05 10:49:46 +0000
committernicm <nicm>2017-04-05 10:49:46 +0000
commit9b28200578670183a0dc70f1d16d5642101a6982 (patch)
tree745e1455c441ab36e2b39ec9398bfb40c14c9a56 /server-client.c
parentab4a4b2ad0ce2c8fdb485bc0fe871571181eace8 (diff)
downloadrtmux-9b28200578670183a0dc70f1d16d5642101a6982.tar.gz
rtmux-9b28200578670183a0dc70f1d16d5642101a6982.tar.bz2
rtmux-9b28200578670183a0dc70f1d16d5642101a6982.zip
Give each client a name. This defaults to the tty name as before but
falls back to an alternative if the tty name is not available. This is clearer than overloading the client ttyname member and allows us to remove the path stored in the tty struct, it should always be the same as the client.
Diffstat (limited to 'server-client.c')
-rw-r--r--server-client.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/server-client.c b/server-client.c
index a2dc79c7..6be467af 100644
--- a/server-client.c
+++ b/server-client.c
@@ -99,15 +99,12 @@ server_client_check_nested(struct client *c)
struct environ_entry *envent;
struct window_pane *wp;
- if (c->tty.path == NULL)
- return (0);
-
envent = environ_find(c->environ, "TMUX");
if (envent == NULL || *envent->value == '\0')
return (0);
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
- if (strcmp(wp->tty, c->tty.path) == 0)
+ if (strcmp(wp->tty, c->ttyname) == 0)
return (1);
}
return (0);
@@ -322,8 +319,10 @@ server_client_free(__unused int fd, __unused short events, void *arg)
if (!TAILQ_EMPTY(&c->queue))
fatalx("queue not empty");
- if (c->references == 0)
+ if (c->references == 0) {
+ free((void *)c->name);
free(c);
+ }
}
/* Detach a client. */
@@ -1470,6 +1469,7 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg)
const char *data, *home;
size_t datalen;
int flags;
+ char *name;
if (c->flags & CLIENT_IDENTIFIED)
fatalx("out-of-order identify message");
@@ -1535,6 +1535,13 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg)
return;
c->flags |= CLIENT_IDENTIFIED;
+ if (*c->ttyname != '\0')
+ name = xstrdup(c->ttyname);
+ else
+ xasprintf(&name, "client-%ld", (long)c->pid);
+ c->name = name;
+ log_debug("client %p name is %s", c, c->name);
+
if (c->flags & CLIENT_CONTROL) {
c->stdin_callback = control_callback;
@@ -1685,7 +1692,7 @@ server_client_add_message(struct client *c, const char *fmt, ...)
xvasprintf(&s, fmt, ap);
va_end(ap);
- log_debug("%s: message %s", c->tty.path, s);
+ log_debug("message %s (client %p)", s, c);
msg = xcalloc(1, sizeof *msg);
msg->msg_time = time(NULL);