summaryrefslogtreecommitdiffstats
path: root/osdep-linux.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2014-04-17 23:48:19 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2014-04-17 23:48:19 +0100
commit024846b4d82ad57e68b64cac2ac12b932a9042d2 (patch)
tree01871a87bd0c06dcee691d5280784bc21622c1fc /osdep-linux.c
parent4abc8f717a5a786a4dd9e4f24d64ec76b0829993 (diff)
If pgrp fails in osdep_get_cwd, try sid. Fixes eg cat foo|less. From Balazs
Kezes.
Diffstat (limited to 'osdep-linux.c')
-rw-r--r--osdep-linux.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/osdep-linux.c b/osdep-linux.c
index ccac2670..46aea68e 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,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);