diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2014-04-17 23:48:19 +0100 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2014-04-17 23:48:19 +0100 |
commit | 024846b4d82ad57e68b64cac2ac12b932a9042d2 (patch) | |
tree | 01871a87bd0c06dcee691d5280784bc21622c1fc | |
parent | 4abc8f717a5a786a4dd9e4f24d64ec76b0829993 (diff) | |
download | rtmux-024846b4d82ad57e68b64cac2ac12b932a9042d2.tar.gz rtmux-024846b4d82ad57e68b64cac2ac12b932a9042d2.tar.bz2 rtmux-024846b4d82ad57e68b64cac2ac12b932a9042d2.zip |
If pgrp fails in osdep_get_cwd, try sid. Fixes eg cat foo|less. From Balazs
Kezes.
-rw-r--r-- | osdep-linux.c | 9 |
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); |