Looking up argv[0] is expensive, so just use p_comm for the window name which is good enough. Also increase name update time to 500 ms.

pull/1/head
Nicholas Marriott 2009-02-13 00:43:04 +00:00
parent b1e911aff0
commit cce03e138b
8 changed files with 55 additions and 162 deletions

View File

@ -1,3 +1,8 @@
13 February 2009
* Looking up argv[0] is expensive, so just use p_comm for the window name which
is good enough. Also increase name update time to 500 ms.
11 February 2009
* Only use ri when actually at the top of the screen; just move the cursor up
@ -1104,7 +1109,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.253 2009-02-12 00:03:58 nicm Exp $
$Id: CHANGES,v 1.254 2009-02-13 00:43:04 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms

10
names.c
View File

@ -1,4 +1,4 @@
/* $Id: names.c,v 1.3 2009-02-09 18:08:01 nicm Exp $ */
/* $Id: names.c,v 1.4 2009-02-13 00:43:04 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -53,12 +53,8 @@ set_window_names(void)
if (w->active->screen != &w->active->base)
name = NULL;
else {
if (osdep_get_name(w->active->fd,
w->active->tty, &w->name_pid, &name) == 1)
continue;
}
else
name = osdep_get_name(w->active->fd, w->active->tty);
if (name == NULL)
wname = default_window_name(w);
else {

View File

@ -1,4 +1,4 @@
/* $Id: osdep-darwin.c,v 1.8 2009-02-11 19:35:50 nicm Exp $ */
/* $Id: osdep-darwin.c,v 1.9 2009-02-13 00:43:04 nicm Exp $ */
/*
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
@ -25,36 +25,27 @@
#include <string.h>
#include <unistd.h>
int osdep_get_name(int, char *, pid_t *, char **);
char *osdep_get_name(int, char *);
#define unused __attribute__ ((unused))
/*
* XXX This actually returns the executable path, not the process's argv[0].
* Anyone who wishes to complain about this is welcome to grab a copy of
* Apple's 'ps' source and start digging.
*/
int
osdep_get_name(int fd, unused char *tty, unused pid_t *last_pid, char **name)
char *
osdep_get_name(int fd, unused char *tty)
{
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 };
size_t size;
struct kinfo_proc kp;
*name = NULL;
if ((mib[3] = tcgetpgrp(fd)) == -1)
return (-1);
return (NULL);
size = sizeof kp;
if (sysctl(mib, 4, &kp, &size, NULL, 0) == -1)
return (-1);
return (NULL);
if (*kp.kp_proc.p_comm == '\0')
return (-1);
return (NULL);
*name = strdup(kp.kp_proc.p_comm);
return (0);
return (strdup(kp.kp_proc.p_comm));
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: osdep-freebsd.c,v 1.13 2009-02-09 18:09:58 nicm Exp $ */
/* $Id: osdep-freebsd.c,v 1.14 2009-02-13 00:43:04 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -31,8 +31,7 @@
#include <string.h>
#include <unistd.h>
int osdep_get_name(int, char *, pid_t *, char **);
char *osdep_get_argv0(pid_t);
char *osdep_get_name(int, char *);
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
@ -41,32 +40,31 @@ char *osdep_get_argv0(pid_t);
#define is_stopped(p) \
((p)->ki_stat == SSTOP || (p)->ki_stat == SZOMB)
int
osdep_get_name(int fd, char *tty, pid_t *last_pid, char **name)
char *
osdep_get_name(int fd, char *tty)
{
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 };
struct stat sb;
size_t len;
struct kinfo_proc *buf, *newbuf, *p, *bestp;
u_int i;
*name = NULL;
char *name;
buf = NULL;
if (stat(tty, &sb) == -1)
return (-1);
return (NULL);
if ((mib[3] = tcgetpgrp(fd)) == -1)
return (-1);
return (NULL);
retry:
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) == -1)
return (-1);
return (NULL);
len = (len * 5) / 4;
if ((newbuf = realloc(buf, len)) == NULL) {
free(buf);
return (-1);
return (NULL);
}
buf = newbuf;
@ -74,7 +72,7 @@ retry:
if (errno == ENOMEM)
goto retry;
free(buf);
return (-1);
return (NULL);
}
bestp = NULL;
@ -116,56 +114,12 @@ retry:
bestp = p;
}
if (bestp == NULL) {
free(buf);
return (-1);
}
name = NULL;
if (bestp != NULL)
name = strdup(bestp->ki_comm);
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);
return (0);
}
char *
osdep_get_argv0(pid_t pid)
{
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0 };
size_t size, size2;
char *args, *args2, *procname;
mib[3] = pid;
procname = NULL;
args = NULL;
size = 128;
while (size < SIZE_MAX / 2) {
size *= 2;
if ((args2 = realloc(args, size)) == NULL)
break;
args = args2;
size2 = size;
if (sysctl(mib, 4, args, &size2, NULL, 0) == -1) {
if (errno == ENOMEM)
continue;
break;
}
if (size2 > 0 && *args != '\0')
procname = strdup(args);
break;
}
free(args);
return (procname);
return (name);
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: osdep-linux.c,v 1.4 2009-02-09 18:08:01 nicm Exp $ */
/* $Id: osdep-linux.c,v 1.5 2009-02-13 00:43:04 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -26,8 +26,8 @@
#include "tmux.h"
int
osdep_get_name(int fd, unused char *tty, unused pid_t *last_pid, char **name)
char *
osdep_get_name(int fd, unused char *tty)
{
FILE *f;
char *path, *buf;
@ -35,15 +35,13 @@ osdep_get_name(int fd, unused char *tty, unused pid_t *last_pid, char **name)
int ch;
pid_t pgrp;
*name = NULL;
if ((pgrp = tcgetpgrp(fd)) == -1)
return (-1);
return (NULL);
xasprintf(&path, "/proc/%lld/cmdline", (long long) pgrp);
if ((f = fopen(path, "r")) == NULL) {
xfree(path);
return (-1);
return (NULL);
}
xfree(path);
@ -57,10 +55,9 @@ osdep_get_name(int fd, unused char *tty, unused pid_t *last_pid, char **name)
}
if (buf != NULL)
buf[len] = '\0';
*name = buf;
fclose(f);
return (0);
return (buf);
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: osdep-openbsd.c,v 1.12 2009-02-09 18:08:01 nicm Exp $ */
/* $Id: osdep-openbsd.c,v 1.13 2009-02-13 00:43:04 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -35,11 +35,10 @@
#define is_stopped(p) \
((p)->p_stat == SSTOP || (p)->p_stat == SZOMB || (p)->p_stat == SDEAD)
int osdep_get_name(int, char *, pid_t *, char **);
char *osdep_get_argv0(pid_t);
char *osdep_get_name(int, char *);
int
osdep_get_name(int fd, char *tty, pid_t *last_pid, char **name)
char *
osdep_get_name(int fd, char *tty)
{
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PGRP, 0 };
struct stat sb;
@ -47,24 +46,23 @@ osdep_get_name(int fd, char *tty, pid_t *last_pid, char **name)
struct kinfo_proc *buf, *newbuf;
struct proc *p, *bestp;
u_int i;
*name = NULL;
char *name;
buf = NULL;
if (stat(tty, &sb) == -1)
return (-1);
return (NULL);
if ((mib[3] = tcgetpgrp(fd)) == -1)
return (-1);
return (NULL);
retry:
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) == -1)
return (-1);
return (NULL);
len = (len * 5) / 4;
if ((newbuf = realloc(buf, len)) == NULL) {
free(buf);
return (-1);
return (NULL);
}
buf = newbuf;
@ -72,7 +70,7 @@ retry:
if (errno == ENOMEM)
goto retry;
free(buf);
return (-1);
return (NULL);
}
bestp = NULL;
@ -126,56 +124,12 @@ retry:
bestp = p;
}
if (bestp == NULL) {
free(buf);
return (-1);
}
name = NULL;
if (bestp != NULL)
name = strdup(bestp->p_comm);
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);
return (0);
}
char *
osdep_get_argv0(pid_t pid)
{
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, 0, KERN_PROC_ARGV };
size_t size;
char **args, **args2, *procname;
procname = NULL;
mib[2] = pid;
args = NULL;
size = 128;
while (size < SIZE_MAX / 2) {
size *= 2;
if ((args2 = realloc(args, size)) == NULL)
break;
args = args2;
if (sysctl(mib, 4, args, &size, NULL, 0) == -1) {
if (errno == ENOMEM)
continue;
break;
}
if (*args != NULL)
procname = strdup(*args);
break;
}
free(args);
return (procname);
return (name);
}
#endif

7
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.270 2009-02-11 23:16:42 nicm Exp $ */
/* $Id: tmux.h,v 1.271 2009-02-13 00:43:04 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -124,7 +124,7 @@ extern const char *__progname;
#define PANE_MINIMUM 4 /* includes separator line */
/* Automatic name refresh interval, in milliseconds. */
#define NAME_INTERVAL 250
#define NAME_INTERVAL 500
/* Fatal errors. */
#define fatal(msg) log_fatal("%s: %s", __func__, msg);
@ -615,7 +615,6 @@ TAILQ_HEAD(window_panes, window_pane);
struct window {
char *name;
struct timeval name_timer;
pid_t name_pid;
struct window_pane *active;
struct window_panes panes;
@ -1527,7 +1526,7 @@ int utf8_width(u_int);
char *section_string(char *, size_t, size_t, size_t);
/* osdep-*.c */
int osdep_get_name(int, char *, pid_t *, char **);
char *osdep_get_name(int, char *);
/* buffer.c */
struct buffer *buffer_create(size_t);

View File

@ -1,4 +1,4 @@
/* $Id: window.c,v 1.67 2009-02-12 17:31:23 nicm Exp $ */
/* $Id: window.c,v 1.68 2009-02-13 00:43:04 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -235,7 +235,6 @@ window_create(const char *name, const char *cmd, const char *cwd,
}
w->active = TAILQ_FIRST(&w->panes);
w->name_pid = -1;
if (name != NULL) {
w->name = xstrdup(name);
options_set_number(&w->options, "automatic-rename", 0);
@ -627,7 +626,6 @@ window_pane_set_mode(struct window_pane *wp, const struct window_mode *mode)
if (wp->mode != NULL || wp->mode == mode)
return (1);
wp->window->name_pid = -1;
wp->mode = mode;
@ -642,7 +640,6 @@ window_pane_reset_mode(struct window_pane *wp)
{
if (wp->mode == NULL)
return;
wp->window->name_pid = -1;
wp->mode->free(wp);
wp->mode = NULL;