The branch, master has been updated via 5d60bc7f7c43c20fcf65531b5a5fb1fc7dcbb338 (commit) from 5b85efeb93d44e504e36ae06a91c2e1b8b82c50e (commit)
- Log ----------------------------------------------------------------- commit 5d60bc7f7c43c20fcf65531b5a5fb1fc7dcbb338 Author: Nicholas Marriott <nicholas.marri...@gmail.com> Commit: Nicholas Marriott <nicholas.marri...@gmail.com> Use pgrp of pty fd not pid of immediate child when recovering current working directory (like current process). From Marcel Partap. --- cmd.c | 2 +- format.c | 2 +- osdep-aix.c | 2 +- osdep-darwin.c | 10 +++++++--- osdep-dragonfly.c | 4 ++-- osdep-freebsd.c | 10 +++++++--- osdep-hpux.c | 2 +- osdep-linux.c | 8 ++++++-- osdep-netbsd.c | 4 ++-- osdep-openbsd.c | 8 +++++--- osdep-sunos.c | 8 ++++++-- osdep-unknown.c | 2 +- tmux.h | 2 +- 13 files changed, 41 insertions(+), 23 deletions(-) diff --git a/cmd.c b/cmd.c index d4b7e97..4a17ddc 100644 --- a/cmd.c +++ b/cmd.c @@ -1297,7 +1297,7 @@ cmd_get_default_path(struct cmd_ctx *ctx, const char *cwd) if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL) root = ctx->cmdclient->cwd; else if (ctx->curclient != NULL && s->curw != NULL) - root = osdep_get_cwd(s->curw->window->active->pid); + root = osdep_get_cwd(s->curw->window->active->fd); else return (s->cwd); skip = 0; diff --git a/format.c b/format.c index 55d51df..19f322a 100644 --- a/format.c +++ b/format.c @@ -391,7 +391,7 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_start_command", "%s", wp->cmd); if (wp->cwd != NULL) format_add(ft, "pane_start_path", "%s", wp->cwd); - format_add(ft, "pane_current_path", "%s", osdep_get_cwd(wp->pid)); + format_add(ft, "pane_current_path", "%s", osdep_get_cwd(wp->fd)); format_add(ft, "pane_pid", "%ld", (long) wp->pid); format_add(ft, "pane_tty", "%s", wp->tty); } diff --git a/osdep-aix.c b/osdep-aix.c index 2a29165..8d59081 100644 --- a/osdep-aix.c +++ b/osdep-aix.c @@ -29,7 +29,7 @@ osdep_get_name(unused int fd, unused char *tty) } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(unused int fd) { return (NULL); } diff --git a/osdep-darwin.c b/osdep-darwin.c index 9cac131..b112fa7 100644 --- a/osdep-darwin.c +++ b/osdep-darwin.c @@ -26,7 +26,7 @@ #include <unistd.h> char *osdep_get_name(int, char *); -char *osdep_get_cwd(pid_t); +char *osdep_get_cwd(int); struct event_base *osdep_event_init(void); #define unused __attribute__ ((unused)) @@ -51,14 +51,18 @@ osdep_get_name(int fd, unused char *tty) } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { static char wd[PATH_MAX]; struct proc_vnodepathinfo pathinfo; + pid_t pgrp; int ret; + if ((pgrp = tcgetpgrp(fd)) == -1) + return (NULL); + ret = proc_pidinfo( - pid, PROC_PIDVNODEPATHINFO, 0, &pathinfo, sizeof pathinfo); + pgrp, PROC_PIDVNODEPATHINFO, 0, &pathinfo, sizeof pathinfo); if (ret == sizeof pathinfo) { strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd); return (wd); diff --git a/osdep-dragonfly.c b/osdep-dragonfly.c index 22045c3..ad417d9 100644 --- a/osdep-dragonfly.c +++ b/osdep-dragonfly.c @@ -31,7 +31,7 @@ struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); char *osdep_get_name(int, char *); -char *osdep_get_cwd(pid_t); +char *osdep_get_cwd(int); struct event_base *osdep_event_init(void); #ifndef nitems @@ -121,7 +121,7 @@ error: } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { return (NULL); } diff --git a/osdep-freebsd.c b/osdep-freebsd.c index 1027a64..d596eab 100644 --- a/osdep-freebsd.c +++ b/osdep-freebsd.c @@ -33,7 +33,7 @@ struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); char *osdep_get_name(int, char *); -char *osdep_get_cwd(pid_t); +char *osdep_get_cwd(int); struct event_base *osdep_event_init(void); #ifndef nitems @@ -133,13 +133,17 @@ error: } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { static char wd[PATH_MAX]; struct kinfo_file *info = NULL; + pid_t pgrp; int nrecords, i; - if ((info = kinfo_getfile(pid, &nrecords)) == NULL) + if ((pgrp = tcgetpgrp(fd)) == -1) + return (NULL); + + if ((info = kinfo_getfile(pgrp, &nrecords)) == NULL) return (NULL); for (i = 0; i < nrecords; i++) { diff --git a/osdep-hpux.c b/osdep-hpux.c index c962a1f..352e375 100644 --- a/osdep-hpux.c +++ b/osdep-hpux.c @@ -29,7 +29,7 @@ osdep_get_name(unused int fd, unused char *tty) } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(unused int fd) { return (NULL); } diff --git a/osdep-linux.c b/osdep-linux.c index 8adf202..b65acff 100644 --- a/osdep-linux.c +++ b/osdep-linux.c @@ -61,13 +61,17 @@ osdep_get_name(int fd, unused char *tty) } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { static char target[MAXPATHLEN + 1]; char *path; + pid_t pgrp; ssize_t n; - xasprintf(&path, "/proc/%d/cwd", pid); + if ((pgrp = tcgetpgrp(fd)) == -1) + return (NULL); + + xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp); n = readlink(path, target, MAXPATHLEN); free(path); if (n > 0) { diff --git a/osdep-netbsd.c b/osdep-netbsd.c index bb2676c..f16d0dc 100644 --- a/osdep-netbsd.c +++ b/osdep-netbsd.c @@ -34,7 +34,7 @@ struct kinfo_proc2 *cmp_procs(struct kinfo_proc2 *, struct kinfo_proc2 *); char *osdep_get_name(int, char *); -char *osdep_get_cwd(pid_t); +char *osdep_get_cwd(int); struct event_base *osdep_event_init(void); struct kinfo_proc2 * @@ -125,7 +125,7 @@ error: } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { return (NULL); } diff --git a/osdep-openbsd.c b/osdep-openbsd.c index 4fb75bf..9eee984 100644 --- a/osdep-openbsd.c +++ b/osdep-openbsd.c @@ -37,7 +37,7 @@ struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); char *osdep_get_name(int, char *); -char *osdep_get_cwd(pid_t); +char *osdep_get_cwd(int); struct event_base *osdep_event_init(void); struct kinfo_proc * @@ -135,12 +135,14 @@ error: } char* -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { - int name[] = { CTL_KERN, KERN_PROC_CWD, (int)pid }; + int name[] = { CTL_KERN, KERN_PROC_CWD, 0 }; static char path[MAXPATHLEN]; size_t pathlen = sizeof path; + if ((name[2] = tcgetpgrp(fd)) == -1) + return (NULL); if (sysctl(name, 3, path, &pathlen, NULL, 0) != 0) return (NULL); return (path); diff --git a/osdep-sunos.c b/osdep-sunos.c index bb67412..fd644f5 100644 --- a/osdep-sunos.c +++ b/osdep-sunos.c @@ -65,13 +65,17 @@ osdep_get_name(int fd, char *tty) } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { static char target[MAXPATHLEN + 1]; char *path; ssize_t n; + pid_t pgrp; + + if ((pgrp = tcgetpgrp(fd)) == -1) + return (NULL); - xasprintf(&path, "/proc/%u/path/cwd", (u_int) pid); + xasprintf(&path, "/proc/%u/path/cwd", (u_int) pgrp); n = readlink(path, target, MAXPATHLEN); free(path); if (n > 0) { diff --git a/osdep-unknown.c b/osdep-unknown.c index c962a1f..41f435b 100644 --- a/osdep-unknown.c +++ b/osdep-unknown.c @@ -29,7 +29,7 @@ osdep_get_name(unused int fd, unused char *tty) } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { return (NULL); } diff --git a/tmux.h b/tmux.h index 9374012..249dd5d 100644 --- a/tmux.h +++ b/tmux.h @@ -2273,7 +2273,7 @@ u_int utf8_split2(u_int, u_char *); /* osdep-*.c */ char *osdep_get_name(int, char *); -char *osdep_get_cwd(pid_t); +char *osdep_get_cwd(int); struct event_base *osdep_event_init(void); /* log.c */ ----------------------------------------------------------------------- Summary of changes: cmd.c | 2 +- format.c | 2 +- osdep-aix.c | 2 +- osdep-darwin.c | 10 +++++++--- osdep-dragonfly.c | 4 ++-- osdep-freebsd.c | 10 +++++++--- osdep-hpux.c | 2 +- osdep-linux.c | 8 ++++++-- osdep-netbsd.c | 4 ++-- osdep-openbsd.c | 8 +++++--- osdep-sunos.c | 8 ++++++-- osdep-unknown.c | 2 +- tmux.h | 2 +- 13 files changed, 41 insertions(+), 23 deletions(-) hooks/post-receive -- tmux ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ tmux-cvs mailing list tmux-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-cvs