Why not getsid()?
On Sun, Mar 02, 2014 at 03:18:10PM +0000, Balazs Kezes wrote:
> On 2014-02-27 22:09, Matteo Cavalleri wrote:
> > $ cat /etc/hosts | less # the pipe is important here
> > [...]
> > so when I create a new window with e.g. something piped to less the
> > new window opens on the root directory, always.
>
> It seems that tmux tries to determine the pane's current directory by
> checking the foreground process group's leader's current working
> directory. In the above pipe that leader is the "cat /etc/hosts" which
> has already finished when you do the split so it can't observe its cwd
> at that point.
>
> I think a reasonable fallback for this scenario would be to check the
> session leader's cwd which is the shell where you start the above
> pipeline. I've appended a patch which implements this in Linux.
>
> ---
> diff --git a/osdep-linux.c b/osdep-linux.c
> index ccac267..8942c94 100644
> --- a/osdep-linux.c
> +++ b/osdep-linux.c
> @@ -65,7 +65,7 @@ osdep_get_cwd(int fd)
> {
> static char target[MAXPATHLEN + 1];
> char *path;
> - pid_t pgrp;
> + pid_t pgrp, sid;
> ssize_t n;
>
> if ((pgrp = tcgetpgrp(fd)) == -1)
> @@ -74,6 +74,16 @@ osdep_get_cwd(int fd)
> xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
> n = readlink(path, target, MAXPATHLEN);
> free(path);
> +
> + if (n == -1) {
> + // Try the session leader as well.
> + if (ioctl(fd, TIOCGSID, &sid) == -1)
> + return (NULL);
> + xasprintf(&path, "/proc/%lld/cwd", (long long) sid);
> + n = readlink(path, target, MAXPATHLEN);
> + free(path);
> + }
> +
> if (n > 0) {
> target[n] = '\0';
> return (target);
> --
> Balazs
>
> ------------------------------------------------------------------------------
> Flow-based real-time traffic analytics software. Cisco certified tool.
> Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
> Customize your own dashboards, set traffic alerts and generate reports.
> Network behavioral analysis & security monitoring. All-in-one tool.
> http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
> _______________________________________________
> tmux-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/tmux-users
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works.
Faster operations. Version large binaries. Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-users