diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2012-09-24 14:05:38 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2012-09-24 14:05:38 +0100 |
commit | 5d60bc7f7c43c20fcf65531b5a5fb1fc7dcbb338 (patch) | |
tree | fd7cdea8dd53657a1545db7df6f2baa1e1c2f574 /osdep-linux.c | |
parent | 5b85efeb93d44e504e36ae06a91c2e1b8b82c50e (diff) |
Use pgrp of pty fd not pid of immediate child when recovering current working
directory (like current process). From Marcel Partap.
Diffstat (limited to 'osdep-linux.c')
-rw-r--r-- | osdep-linux.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/osdep-linux.c b/osdep-linux.c index 8adf202b..b65acffc 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) { |