mirror of
https://github.com/tmux/tmux.git
synced 2025-04-14 15:28:50 +00:00
Don't try to change the window name unless the pid of the process chosen has
changed. Reduces CPU use. osdep-* stuff is a bit horrible now but there we go :-/.
This commit is contained in:
parent
9d90d9ad70
commit
c9cfc9a9f3
11
names.c
11
names.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: names.c,v 1.2 2009-01-26 22:57:19 nicm Exp $ */
|
/* $Id: names.c,v 1.3 2009-02-09 18:08:01 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -53,14 +53,19 @@ set_window_names(void)
|
|||||||
|
|
||||||
if (w->active->screen != &w->active->base)
|
if (w->active->screen != &w->active->base)
|
||||||
name = NULL;
|
name = NULL;
|
||||||
else
|
else {
|
||||||
name = get_argv0(w->active->fd, w->active->tty);
|
if (osdep_get_name(w->active->fd,
|
||||||
|
w->active->tty, &w->name_pid, &name) == 1)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
wname = default_window_name(w);
|
wname = default_window_name(w);
|
||||||
else {
|
else {
|
||||||
wname = parse_window_name(name);
|
wname = parse_window_name(name);
|
||||||
xfree(name);
|
xfree(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(wname, w->name) == 0)
|
if (strcmp(wname, w->name) == 0)
|
||||||
xfree(wname);
|
xfree(wname);
|
||||||
else {
|
else {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: osdep-darwin.c,v 1.4 2009-02-07 19:41:35 nicm Exp $ */
|
/* $Id: osdep-darwin.c,v 1.5 2009-02-09 18:08:01 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
||||||
@ -25,7 +25,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
char *get_argv0(int, char *);
|
int osdep_get_name(int, char *, pid_t *, char **);
|
||||||
|
|
||||||
|
#define unused __attribute__ ((unused))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX This actually returns the executable path, not the process's argv[0].
|
* XXX This actually returns the executable path, not the process's argv[0].
|
||||||
@ -33,8 +35,8 @@ char *get_argv0(int, char *);
|
|||||||
* Apple's 'ps' source and start digging.
|
* Apple's 'ps' source and start digging.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *
|
int
|
||||||
get_argv0(int fd, __attribute__ ((unused)) char *tty)
|
osdep_get_name(int fd, unused char *tty, unused pid_t *last_pid, char **name)
|
||||||
{
|
{
|
||||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 };
|
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 };
|
||||||
size_t size;
|
size_t size;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: osdep-freebsd.c,v 1.11 2009-02-08 13:03:43 nicm Exp $ */
|
/* $Id: osdep-freebsd.c,v 1.12 2009-02-09 18:08:01 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -31,8 +31,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
char *get_argv0(int, char *);
|
int osdep_get_name(int, char *, pid_t *, char **);
|
||||||
char *get_proc_argv0(pid_t);
|
char *osdep_get_argv0(pid_t);
|
||||||
|
|
||||||
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
|
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
|
||||||
|
|
||||||
@ -41,16 +41,17 @@ char *get_proc_argv0(pid_t);
|
|||||||
#define is_stopped(p) \
|
#define is_stopped(p) \
|
||||||
((p)->ki_stat == SSTOP || (p)->ki_stat == SZOMB)
|
((p)->ki_stat == SSTOP || (p)->ki_stat == SZOMB)
|
||||||
|
|
||||||
char *
|
int
|
||||||
get_argv0(int fd, char *tty)
|
osdep_get_name(int fd, char *tty, pid_t *last_pid, char **name)
|
||||||
{
|
{
|
||||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 };
|
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 };
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
size_t len;
|
size_t len;
|
||||||
struct kinfo_proc *buf, *newbuf, *p, *bestp;
|
struct kinfo_proc *buf, *newbuf, *p, *bestp;
|
||||||
char *procname;
|
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
|
*name = NULL;
|
||||||
|
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
|
|
||||||
if (stat(tty, &sb) == -1)
|
if (stat(tty, &sb) == -1)
|
||||||
@ -114,22 +115,29 @@ retry:
|
|||||||
if (p->ki_pid > bestp->ki_pid)
|
if (p->ki_pid > bestp->ki_pid)
|
||||||
bestp = p;
|
bestp = p;
|
||||||
}
|
}
|
||||||
if (bestp != NULL) {
|
|
||||||
procname = get_proc_argv0(bestp->ki_pid);
|
|
||||||
if (procname == NULL || *procname == '\0') {
|
|
||||||
free(procname);
|
|
||||||
procname = strdup(bestp->ki_comm);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
procname = NULL;
|
|
||||||
|
|
||||||
|
if (bestp == NULL) {
|
||||||
|
free(buf);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bestp->ki_pid == *last_pid) {
|
||||||
|
free(buf);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
*last_pid = bestp->ki_pid;
|
||||||
|
|
||||||
|
*name = osdep_get_argv0(bestp->ki_pid);
|
||||||
|
if (*name == NULL || **name == '\0') {
|
||||||
|
free(*name);
|
||||||
|
*name = strdup(bestp->ki_comm);
|
||||||
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
return (procname);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
get_proc_argv0(pid_t pid)
|
osdep_get_argv0(pid_t pid)
|
||||||
{
|
{
|
||||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0 };
|
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0 };
|
||||||
size_t size, size2;
|
size_t size, size2;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: osdep-linux.c,v 1.3 2009-02-02 15:46:36 nicm Exp $ */
|
/* $Id: osdep-linux.c,v 1.4 2009-02-09 18:08:01 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
char *
|
int
|
||||||
get_argv0(int fd, unused char *tty)
|
osdep_get_name(int fd, unused char *tty, unused pid_t *last_pid, char **name)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char *path, *buf;
|
char *path, *buf;
|
||||||
@ -35,13 +35,15 @@ get_argv0(int fd, unused char *tty)
|
|||||||
int ch;
|
int ch;
|
||||||
pid_t pgrp;
|
pid_t pgrp;
|
||||||
|
|
||||||
|
*name = NULL;
|
||||||
|
|
||||||
if ((pgrp = tcgetpgrp(fd)) == -1)
|
if ((pgrp = tcgetpgrp(fd)) == -1)
|
||||||
return (NULL);
|
return (-1);
|
||||||
|
|
||||||
xasprintf(&path, "/proc/%lld/cmdline", (long long) pgrp);
|
xasprintf(&path, "/proc/%lld/cmdline", (long long) pgrp);
|
||||||
if ((f = fopen(path, "r")) == NULL) {
|
if ((f = fopen(path, "r")) == NULL) {
|
||||||
xfree(path);
|
xfree(path);
|
||||||
return (NULL);
|
return (-1);
|
||||||
}
|
}
|
||||||
xfree(path);
|
xfree(path);
|
||||||
|
|
||||||
@ -55,9 +57,10 @@ get_argv0(int fd, unused char *tty)
|
|||||||
}
|
}
|
||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
|
*name = buf;
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return (buf);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: osdep-openbsd.c,v 1.11 2009-02-08 12:31:02 nicm Exp $ */
|
/* $Id: osdep-openbsd.c,v 1.12 2009-02-09 18:08:01 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -35,35 +35,36 @@
|
|||||||
#define is_stopped(p) \
|
#define is_stopped(p) \
|
||||||
((p)->p_stat == SSTOP || (p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
|
((p)->p_stat == SSTOP || (p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
|
||||||
|
|
||||||
char *get_argv0(int, char *);
|
int osdep_get_name(int, char *, pid_t *, char **);
|
||||||
char *get_proc_argv0(pid_t);
|
char *osdep_get_argv0(pid_t);
|
||||||
|
|
||||||
char *
|
int
|
||||||
get_argv0(int fd, char *tty)
|
osdep_get_name(int fd, char *tty, pid_t *last_pid, char **name)
|
||||||
{
|
{
|
||||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 };
|
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 };
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
size_t len;
|
size_t len;
|
||||||
struct kinfo_proc *buf, *newbuf;
|
struct kinfo_proc *buf, *newbuf;
|
||||||
struct proc *p, *bestp;
|
struct proc *p, *bestp;
|
||||||
char *procname;
|
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
|
*name = NULL;
|
||||||
|
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
|
|
||||||
if (stat(tty, &sb) == -1)
|
if (stat(tty, &sb) == -1)
|
||||||
return (NULL);
|
return (-1);
|
||||||
if ((mib[3] = tcgetpgrp(fd)) == -1)
|
if ((mib[3] = tcgetpgrp(fd)) == -1)
|
||||||
return (NULL);
|
return (-1);
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) == -1)
|
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) == -1)
|
||||||
return (NULL);
|
return (-1);
|
||||||
len = (len * 5) / 4;
|
len = (len * 5) / 4;
|
||||||
|
|
||||||
if ((newbuf = realloc(buf, len)) == NULL) {
|
if ((newbuf = realloc(buf, len)) == NULL) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return (NULL);
|
return (-1);
|
||||||
}
|
}
|
||||||
buf = newbuf;
|
buf = newbuf;
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ retry:
|
|||||||
if (errno == ENOMEM)
|
if (errno == ENOMEM)
|
||||||
goto retry;
|
goto retry;
|
||||||
free(buf);
|
free(buf);
|
||||||
return (NULL);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bestp = NULL;
|
bestp = NULL;
|
||||||
@ -123,22 +124,30 @@ retry:
|
|||||||
|
|
||||||
if (p->p_pid > bestp->p_pid)
|
if (p->p_pid > bestp->p_pid)
|
||||||
bestp = p;
|
bestp = p;
|
||||||
}
|
}
|
||||||
if (bestp != NULL) {
|
|
||||||
procname = get_proc_argv0(bestp->p_pid);
|
|
||||||
if (procname == NULL || *procname == '\0') {
|
|
||||||
free(procname);
|
|
||||||
procname = strdup(bestp->p_comm);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
procname = NULL;
|
|
||||||
|
|
||||||
|
if (bestp == NULL) {
|
||||||
|
free(buf);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bestp->p_pid == *last_pid) {
|
||||||
|
free(buf);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
*last_pid = bestp->p_pid;
|
||||||
|
|
||||||
|
*name = osdep_get_argv0(bestp->p_pid);
|
||||||
|
if (*name == NULL || **name == '\0') {
|
||||||
|
free(*name);
|
||||||
|
*name = strdup(bestp->p_comm);
|
||||||
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
return (procname);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
get_proc_argv0(pid_t pid)
|
osdep_get_argv0(pid_t pid)
|
||||||
{
|
{
|
||||||
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, 0, KERN_PROC_ARGV };
|
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, 0, KERN_PROC_ARGV };
|
||||||
size_t size;
|
size_t size;
|
||||||
|
5
tmux.h
5
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.261 2009-02-09 16:11:26 nicm Exp $ */
|
/* $Id: tmux.h,v 1.262 2009-02-09 18:08:01 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -612,6 +612,7 @@ TAILQ_HEAD(window_panes, window_pane);
|
|||||||
struct window {
|
struct window {
|
||||||
char *name;
|
char *name;
|
||||||
struct timeval name_timer;
|
struct timeval name_timer;
|
||||||
|
pid_t name_pid;
|
||||||
|
|
||||||
struct window_pane *active;
|
struct window_pane *active;
|
||||||
struct window_panes panes;
|
struct window_panes panes;
|
||||||
@ -1519,7 +1520,7 @@ int utf8_width(u_int);
|
|||||||
char *section_string(char *, size_t, size_t, size_t);
|
char *section_string(char *, size_t, size_t, size_t);
|
||||||
|
|
||||||
/* osdep-*.c */
|
/* osdep-*.c */
|
||||||
char *get_argv0(int, char *);
|
int osdep_get_name(int, char *, pid_t *, char **);
|
||||||
|
|
||||||
/* buffer.c */
|
/* buffer.c */
|
||||||
struct buffer *buffer_create(size_t);
|
struct buffer *buffer_create(size_t);
|
||||||
|
3
window.c
3
window.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: window.c,v 1.65 2009-02-08 16:11:26 nicm Exp $ */
|
/* $Id: window.c,v 1.66 2009-02-09 18:08:01 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -235,6 +235,7 @@ window_create(const char *name, const char *cmd, const char *cwd,
|
|||||||
}
|
}
|
||||||
w->active = TAILQ_FIRST(&w->panes);
|
w->active = TAILQ_FIRST(&w->panes);
|
||||||
|
|
||||||
|
w->name_pid = -1;
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
w->name = xstrdup(name);
|
w->name = xstrdup(name);
|
||||||
options_set_number(&w->options, "automatic-rename", 0);
|
options_set_number(&w->options, "automatic-rename", 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user