diff --git a/client.c b/client.c index 7d997a7e..9c493dfa 100644 --- a/client.c +++ b/client.c @@ -352,9 +352,10 @@ client_main(int argc, char **argv, int flags) void client_send_identify(int flags) { - const char *s; + const char *s; char **ss; - int fd; + int fd; + pid_t pid; client_write_one(MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags); @@ -374,6 +375,9 @@ client_send_identify(int flags) fatal("dup failed"); client_write_one(MSG_IDENTIFY_STDIN, fd, NULL, 0); + pid = getpid(); + client_write_one(MSG_IDENTIFY_CLIENTPID, -1, &pid, sizeof pid); + for (ss = environ; *ss != NULL; ss++) client_write_one(MSG_IDENTIFY_ENVIRON, -1, *ss, strlen(*ss) + 1); diff --git a/format.c b/format.c index d323d32f..f562f23e 100644 --- a/format.c +++ b/format.c @@ -272,6 +272,7 @@ format_create_status(int status) *ptr = '\0'; format_add(ft, "host_short", "%s", host); } + format_add(ft, "pid", "%ld", (long) getpid()); return (ft); } @@ -704,6 +705,7 @@ format_defaults_client(struct format_tree *ft, struct client *c) if (ft->s == NULL) ft->s = c->session; + format_add(ft, "client_pid", "%ld", (long) c->pid); format_add(ft, "client_height", "%u", c->tty.sy); format_add(ft, "client_width", "%u", c->tty.sx); if (c->tty.path != NULL) diff --git a/server-client.c b/server-client.c index 27efc57d..c9c0c3ef 100644 --- a/server-client.c +++ b/server-client.c @@ -1053,6 +1053,7 @@ server_client_msg_dispatch(struct client *c) case MSG_IDENTIFY_CWD: case MSG_IDENTIFY_STDIN: case MSG_IDENTIFY_ENVIRON: + case MSG_IDENTIFY_CLIENTPID: case MSG_IDENTIFY_DONE: server_client_msg_identify(c, &imsg); break; @@ -1227,6 +1228,11 @@ server_client_msg_identify(struct client *c, struct imsg *imsg) if (strchr(data, '=') != NULL) environ_put(&c->environ, data); break; + case MSG_IDENTIFY_CLIENTPID: + if (datalen != sizeof c->pid) + fatalx("bad MSG_IDENTIFY_CLIENTPID size"); + memcpy(&c->pid, data, sizeof c->pid); + break; default: break; } diff --git a/tmux.1 b/tmux.1 index f3eeabcc..8fed79e7 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3357,6 +3357,7 @@ The following variables are available, where appropriate: .It Li "client_created_string" Ta "" Ta "String time client created" .It Li "client_height" Ta "" Ta "Height of client" .It Li "client_last_session" Ta "" Ta "Name of the client's last session" +.It Li "client_pid" Ta "" Ta "PID of client process" .It Li "client_prefix" Ta "" Ta "1 if prefix key has been pressed" .It Li "client_readonly" Ta "" Ta "1 if client is readonly" .It Li "client_session" Ta "" Ta "Name of the client's session" @@ -3401,6 +3402,7 @@ The following variables are available, where appropriate: .It Li "pane_top" Ta "" Ta "Top of pane" .It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane" .It Li "pane_width" Ta "" Ta "Width of pane" +.It Li "pid" Ta "" Ta "Server PID" .It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane" .It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane" .It Li "session_alerts" Ta "" Ta "List of window indexes with alerts" diff --git a/tmux.h b/tmux.h index 210826ad..7ba1b0b2 100644 --- a/tmux.h +++ b/tmux.h @@ -429,6 +429,7 @@ enum msgtype { MSG_IDENTIFY_STDIN, MSG_IDENTIFY_ENVIRON, MSG_IDENTIFY_DONE, + MSG_IDENTIFY_CLIENTPID, MSG_COMMAND = 200, MSG_DETACH, @@ -1210,6 +1211,7 @@ RB_HEAD(status_out_tree, status_out); struct client { struct imsgbuf ibuf; + pid_t pid; int fd; struct event event; int retval;