If pgrp fails in osdep_get_cwd, try sid. Fixes eg cat foo|less. From Balazs

Kezes.
pull/1/head
Nicholas Marriott 2014-04-17 23:48:19 +01:00
parent 4abc8f717a
commit 024846b4d8
1 changed files with 8 additions and 1 deletions

View File

@ -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,13 @@ osdep_get_cwd(int fd)
xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
n = readlink(path, target, MAXPATHLEN);
free(path);
if (n == -1 && ioctl(fd, TIOCGSID, &sid) != -1) {
xasprintf(&path, "/proc/%lld/cwd", (long long) sid);
n = readlink(path, target, MAXPATHLEN);
free(path);
}
if (n > 0) {
target[n] = '\0';
return (target);