summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2015-06-14 10:07:44 +0000
committernicm <nicm>2015-06-14 10:07:44 +0000
commit29c29e771767b037f2929b889bb0de2b0b6ee138 (patch)
tree28d2497e9fd6f69da442ed01f1e431bb51f9561c
parentbbc0898060a02515461cbd90d7af35bf91d9cb3d (diff)
Add a format for client PID (client_pid) and server PID (pid). Diff for
client_pid from Thomas Adam.
-rw-r--r--client.c8
-rw-r--r--format.c2
-rw-r--r--server-client.c6
-rw-r--r--tmux.12
-rw-r--r--tmux.h2
5 files changed, 18 insertions, 2 deletions
diff --git a/client.c b/client.c
index 48109613..4b7bbb1f 100644
--- a/client.c
+++ b/client.c
@@ -348,9 +348,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);
@@ -370,6 +371,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 eaa979da..49cf7506 100644
--- a/format.c
+++ b/format.c
@@ -271,6 +271,7 @@ format_create_status(int status)
*ptr = '\0';
format_add(ft, "host_short", "%s", host);
}
+ format_add(ft, "pid", "%ld", (long) getpid());
return (ft);
}
@@ -703,6 +704,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 8739b5ab..9beef4bc 100644
--- a/server-client.c
+++ b/server-client.c
@@ -1044,6 +1044,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;
@@ -1218,6 +1219,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 16e979ad..70b43a7a 100644
--- a/tmux.1
+++ b/tmux.1
@@ -3353,6 +3353,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"
@@ -3396,6 +3397,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 265fdc40..dfd6bf49 100644
--- a/tmux.h
+++ b/tmux.h
@@ -425,6 +425,7 @@ enum msgtype {
MSG_IDENTIFY_STDIN,
MSG_IDENTIFY_ENVIRON,
MSG_IDENTIFY_DONE,
+ MSG_IDENTIFY_CLIENTPID,
MSG_COMMAND = 200,
MSG_DETACH,
@@ -1206,6 +1207,7 @@ RB_HEAD(status_out_tree, status_out);
struct client {
struct imsgbuf ibuf;
+ pid_t pid;
int fd;
struct event event;
int retval;