Package: tmux / 1.9-6

upstream-0d14f81d76.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
From 0d14f81d76d1836e7de7d6f6d152cc64309e5ae8 Mon Sep 17 00:00:00 2001
From: Nicholas Marriott <nicholas.marriott@gmail.com>
Date: Thu, 17 Apr 2014 23:48:19 +0100
Subject: [PATCH 4/6] If pgrp fails in osdep_get_cwd, try sid. Fixes eg cat
 foo|less. From Balazs Kezes.

---
 osdep-linux.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/osdep-linux.c b/osdep-linux.c
index ccac267..46aea68 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);
-- 
1.9.2