From 5d60bc7f7c43c20fcf65531b5a5fb1fc7dcbb338 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 24 Sep 2012 14:05:38 +0100 Subject: Use pgrp of pty fd not pid of immediate child when recovering current working directory (like current process). From Marcel Partap. --- osdep-sunos.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'osdep-sunos.c') diff --git a/osdep-sunos.c b/osdep-sunos.c index bb67412c..fd644f5d 100644 --- a/osdep-sunos.c +++ b/osdep-sunos.c @@ -65,13 +65,17 @@ osdep_get_name(int fd, char *tty) } char * -osdep_get_cwd(pid_t pid) +osdep_get_cwd(int fd) { static char target[MAXPATHLEN + 1]; char *path; ssize_t n; + pid_t pgrp; + + if ((pgrp = tcgetpgrp(fd)) == -1) + return (NULL); - xasprintf(&path, "/proc/%u/path/cwd", (u_int) pid); + xasprintf(&path, "/proc/%u/path/cwd", (u_int) pgrp); n = readlink(path, target, MAXPATHLEN); free(path); if (n > 0) { -- cgit