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

Kezes.
This commit is contained in:
Nicholas Marriott 2014-04-17 23:48:19 +01:00
parent 4abc8f717a
commit 024846b4d8

View File

@ -65,7 +65,7 @@ osdep_get_cwd(int fd)
{ {
static char target[MAXPATHLEN + 1]; static char target[MAXPATHLEN + 1];
char *path; char *path;
pid_t pgrp; pid_t pgrp, sid;
ssize_t n; ssize_t n;
if ((pgrp = tcgetpgrp(fd)) == -1) if ((pgrp = tcgetpgrp(fd)) == -1)
@ -74,6 +74,13 @@ osdep_get_cwd(int fd)
xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp); xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
n = readlink(path, target, MAXPATHLEN); n = readlink(path, target, MAXPATHLEN);
free(path); 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) { if (n > 0) {
target[n] = '\0'; target[n] = '\0';
return (target); return (target);