Applied, thanks.

On Sat, Sep 15, 2012 at 03:22:37PM +0200, Marcel Partap wrote:
> by picking up the process group leader from the terminal fd
> via tcgetpgrp() instead of using the direct pane child process.
> 
> (works on linux, other platforms untested)
> ---
>  trunk/cmd.c             |    2 +-
>  trunk/format.c          |    2 +-
>  trunk/osdep-aix.c       |    2 +-
>  trunk/osdep-darwin.c    |   10 +++++++---
>  trunk/osdep-dragonfly.c |    4 ++--
>  trunk/osdep-freebsd.c   |   10 +++++++---
>  trunk/osdep-hpux.c      |    2 +-
>  trunk/osdep-linux.c     |    8 ++++++--
>  trunk/osdep-netbsd.c    |    4 ++--
>  trunk/osdep-openbsd.c   |    8 +++++---
>  trunk/osdep-sunos.c     |    8 ++++++--
>  trunk/osdep-unknown.c   |    2 +-
>  trunk/tmux.h            |    2 +-
>  13 files changed, 41 insertions(+), 23 deletions(-)
> 
> diff --git a/trunk/cmd.c b/trunk/cmd.c
> index 2413642..17d182c 100644
> --- a/trunk/cmd.c
> +++ b/trunk/cmd.c
> @@ -1296,7 +1296,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/trunk/format.c b/trunk/format.c
> index 55d51df..19f322a 100644
> --- a/trunk/format.c
> +++ b/trunk/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/trunk/osdep-aix.c b/trunk/osdep-aix.c
> index 2a29165..8d59081 100644
> --- a/trunk/osdep-aix.c
> +++ b/trunk/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/trunk/osdep-darwin.c b/trunk/osdep-darwin.c
> index 9cac131..b112fa7 100644
> --- a/trunk/osdep-darwin.c
> +++ b/trunk/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/trunk/osdep-dragonfly.c b/trunk/osdep-dragonfly.c
> index 22045c3..ad417d9 100644
> --- a/trunk/osdep-dragonfly.c
> +++ b/trunk/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/trunk/osdep-freebsd.c b/trunk/osdep-freebsd.c
> index 1027a64..d596eab 100644
> --- a/trunk/osdep-freebsd.c
> +++ b/trunk/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/trunk/osdep-hpux.c b/trunk/osdep-hpux.c
> index c962a1f..352e375 100644
> --- a/trunk/osdep-hpux.c
> +++ b/trunk/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/trunk/osdep-linux.c b/trunk/osdep-linux.c
> index 8adf202..b65acff 100644
> --- a/trunk/osdep-linux.c
> +++ b/trunk/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/trunk/osdep-netbsd.c b/trunk/osdep-netbsd.c
> index bb2676c..f16d0dc 100644
> --- a/trunk/osdep-netbsd.c
> +++ b/trunk/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/trunk/osdep-openbsd.c b/trunk/osdep-openbsd.c
> index 4fb75bf..9eee984 100644
> --- a/trunk/osdep-openbsd.c
> +++ b/trunk/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/trunk/osdep-sunos.c b/trunk/osdep-sunos.c
> index bb67412..fd644f5 100644
> --- a/trunk/osdep-sunos.c
> +++ b/trunk/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/trunk/osdep-unknown.c b/trunk/osdep-unknown.c
> index c962a1f..41f435b 100644
> --- a/trunk/osdep-unknown.c
> +++ b/trunk/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/trunk/tmux.h b/trunk/tmux.h
> index a3d64de..ce44011 100644
> --- a/trunk/tmux.h
> +++ b/trunk/tmux.h
> @@ -2257,7 +2257,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 */
> -- 
> 1.7.10.4
> 
> 
> ------------------------------------------------------------------------------
> How fast is your code?
> 3 out of 4 devs don\\\'t know how their code performs in production.
> Find out how slow your code is with AppDynamics Lite.
> http://ad.doubleclick.net/clk;262219672;13503038;z?
> http://info.appdynamics.com/FreeJavaPerformanceDownload.html
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users

------------------------------------------------------------------------------
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-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to